-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(advanced-search): Complete Advanced Search: backend changes & tying UI together #6068
Changes from 30 commits
8310925
617ecbd
021e7f3
9086469
f1a5ba4
f5381dc
aac65b2
8a2771e
450eeda
0118f8b
ee60ec1
2e70ad1
8223072
e6567cd
eb1e77f
5f97685
3c965d8
42c88cc
6dad0b0
7f0388a
733811c
82ca21c
ffb612d
d4c3523
8ba3012
ee21612
86b88ee
7694c76
e7d083e
3c4fa4e
ccd6240
6bfa481
05568e0
3b237e6
0e2f4a8
df815b8
c0f8a1c
4da8e38
8eef5f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
import com.datahub.authentication.Authentication; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.linkedin.data.template.StringArray; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.exception.ValidationException; | ||
import com.linkedin.datahub.graphql.generated.FacetFilterInput; | ||
|
||
import com.linkedin.metadata.query.filter.Condition; | ||
import com.linkedin.metadata.query.filter.Criterion; | ||
import com.linkedin.metadata.query.filter.CriterionArray; | ||
import com.linkedin.metadata.query.filter.Filter; | ||
|
@@ -81,20 +83,69 @@ public static Map<String, String> buildFacetFilters(@Nullable List<FacetFilterIn | |
if (!validFacetFields.contains(facetFilterInput.getField())) { | ||
throw new ValidationException(String.format("Unrecognized facet with name %s provided", facetFilterInput.getField())); | ||
} | ||
facetFilters.put(facetFilterInput.getField(), facetFilterInput.getValue()); | ||
facetFilters.put(facetFilterInput.getField(), facetFilterInput.getValues().get(0)); | ||
}); | ||
|
||
return facetFilters; | ||
} | ||
|
||
// In the case that user sends filters to be or-d together, we need to build a series of conjective criterion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: conjunctive criterion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed! |
||
// arrays, rather than just one for the AND case. | ||
public static ConjunctiveCriterionArray buildConjunctiveCriterionArrayWithOr( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: annotation this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just leaving this here -> The name of this function + the parameters it takes are not immediately making it clear to me what this function does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved! |
||
final List<Criterion> andCriterions, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need an annotation for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no longer relevant |
||
@Nonnull List<FacetFilterInput> orFilters | ||
) { | ||
return new ConjunctiveCriterionArray(orFilters.stream().map(orFilter -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we are combining the existing "and" filters with a set of OR filters? Why is this necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Will try to understand on my own just leaving my initial reactions) |
||
CriterionArray andCriterionsForOr = new CriterionArray(andCriterions); | ||
andCriterionsForOr.add(criterionFromFilter(orFilter)); | ||
|
||
return new ConjunctiveCriterion().setAnd( | ||
andCriterionsForOr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So here we are doing something like this... If you pass a list of and criterion:
and some set of ORs
then we will essentially build an OR of ANDs?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we convert into an OR of ANDs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I had to work through this in my head for some time. We should consider adding some comments or something to give an example ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resovled! |
||
); | ||
} | ||
).collect(Collectors.toList())); | ||
} | ||
|
||
@Nullable | ||
public static Filter buildFilter(@Nullable List<FacetFilterInput> facetFilterInputs) { | ||
if (facetFilterInputs == null || facetFilterInputs.isEmpty()) { | ||
public static Filter buildFilter(@Nullable List<FacetFilterInput> andFilters, @Nullable List<FacetFilterInput> orFilters) { | ||
if ((andFilters == null || andFilters.isEmpty()) && (orFilters == null || orFilters.isEmpty())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you separate these two conditions out into boolean variables? it's a little hard to read, and you can use the the same variables down below when building the andCriterions and orCriterions. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved |
||
return null; | ||
} | ||
return new Filter().setOr(new ConjunctiveCriterionArray(new ConjunctiveCriterion().setAnd(new CriterionArray(facetFilterInputs.stream() | ||
.map(filter -> new Criterion().setField(getFilterField(filter.getField())).setValue(filter.getValue())) | ||
.collect(Collectors.toList()))))); | ||
|
||
final List<Criterion> andCriterions = andFilters != null && !andFilters.isEmpty() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is a bit confusing now. I was imagining we'd just have a nested OR or ANDs coming in from the FacetFilterInput. It's kinda hard to understand that if you provide both AND and OR filters that we'll combine them (and how) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved in my update- clearer now! |
||
? andFilters.stream() | ||
.map(filter -> criterionFromFilter(filter)) | ||
.collect(Collectors.toList()) : Collections.emptyList(); | ||
|
||
// if we have OR filters, we need to build a series of CriterionArrays | ||
if (orFilters != null && !orFilters.isEmpty()) { | ||
return new Filter().setOr(buildConjunctiveCriterionArrayWithOr(andCriterions, orFilters)); | ||
} | ||
|
||
// if we do not have any OR filters, just set one ConjectiveCriterionArray | ||
return new Filter().setOr(new ConjunctiveCriterionArray(new ConjunctiveCriterion().setAnd(new CriterionArray(andCriterions)))); | ||
} | ||
|
||
// Translates a FacetFilterInput (graphql input class) into Criterion (our internal model) | ||
public static Criterion criterionFromFilter(final FacetFilterInput filter) { | ||
Criterion result = new Criterion(); | ||
result.setField(getFilterField(filter.getField())); | ||
result.setValue(filter.getValues().get(0)); | ||
if (filter.getValues() != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should you move line 133 inside of this not null check to prevent a null-pointer guy? and maybe a check that it's not an empty list? |
||
result.setValues(new StringArray(filter.getValues())); | ||
} | ||
|
||
if (filter.getCondition() != null) { | ||
result.setCondition(Condition.valueOf(filter.getCondition().toString())); | ||
} else { | ||
result.setCondition(Condition.EQUAL); | ||
} | ||
|
||
if (filter.getNegated() != null) { | ||
result.setNegated(filter.getNegated()); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private static String getFilterField(final String originalField) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,12 @@ | |
import com.linkedin.datahub.graphql.generated.AssertionRunStatus; | ||
import com.linkedin.datahub.graphql.generated.FacetFilterInput; | ||
import com.linkedin.datahub.graphql.generated.FilterInput; | ||
import com.linkedin.datahub.graphql.generated.SearchCondition; | ||
import com.linkedin.datahub.graphql.types.dataset.mappers.AssertionRunEventMapper; | ||
import com.linkedin.entity.client.EntityClient; | ||
import com.linkedin.metadata.Constants; | ||
import com.linkedin.metadata.aspect.EnvelopedAspect; | ||
import com.linkedin.metadata.query.filter.ConjunctiveCriterion; | ||
import com.linkedin.metadata.query.filter.ConjunctiveCriterionArray; | ||
import com.linkedin.metadata.query.filter.Criterion; | ||
import com.linkedin.metadata.query.filter.CriterionArray; | ||
import com.linkedin.metadata.query.filter.Filter; | ||
import com.linkedin.r2.RemoteInvocationException; | ||
|
@@ -102,13 +100,16 @@ private Filter buildFilter(@Nullable FilterInput filtersInput, @Nullable final S | |
} | ||
List<FacetFilterInput> facetFilters = new ArrayList<>(); | ||
if (status != null) { | ||
facetFilters.add(new FacetFilterInput("status", status, ImmutableList.of(status), false, SearchCondition.EQUAL)); | ||
FacetFilterInput filter = new FacetFilterInput(); | ||
filter.setField("status"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we make this a constant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like Gabe didn't originally make this but yeah I think it should be. Either in this PR or a followup There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can do this in a followup |
||
filter.setValues(ImmutableList.of(status)); | ||
facetFilters.add(filter); | ||
} | ||
if (filtersInput != null) { | ||
facetFilters.addAll(filtersInput.getAnd()); | ||
} | ||
return new Filter().setOr(new ConjunctiveCriterionArray(new ConjunctiveCriterion().setAnd(new CriterionArray(facetFilters.stream() | ||
.map(filter -> new Criterion().setField(filter.getField()).setValue(filter.getValue())) | ||
.map(filter -> criterionFromFilter(filter)) | ||
.collect(Collectors.toList()))))); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ public CompletableFuture<SearchResults> get(DataFetchingEnvironment environment) | |
"Executing search for multiple entities: entity types {}, query {}, filters: {}, start: {}, count: {}", | ||
input.getTypes(), input.getQuery(), input.getFilters(), start, count); | ||
return UrnSearchResultsMapper.map(_entityClient.searchAcrossEntities(entityNames, sanitizedQuery, | ||
ResolverUtils.buildFilter(input.getFilters()), start, count, ResolverUtils.getAuthentication(environment))); | ||
ResolverUtils.buildFilter(input.getFilters(), input.getOrFilters()), start, count, ResolverUtils.getAuthentication(environment))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit odd - input.getFilters vs input.getOrFilters -> are we saying we are just taking on this model semantics debt ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved in my update |
||
} catch (Exception e) { | ||
log.error( | ||
"Failed to execute search for multiple entities: entity types {}, query {}, filters: {}, start: {}, count: {}", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,17 +41,17 @@ public CompletableFuture<SearchResults> get(DataFetchingEnvironment environment) | |
|
||
return CompletableFuture.supplyAsync(() -> { | ||
try { | ||
log.debug("Executing search. entity type {}, query {}, filters: {}, start: {}, count: {}", input.getType(), | ||
input.getQuery(), input.getFilters(), start, count); | ||
log.debug("Executing search. entity type {}, query {}, filters: {}, orFilters: {}, start: {}, count: {}", input.getType(), | ||
input.getQuery(), input.getFilters(), input.getOrFilters(), start, count); | ||
return UrnSearchResultsMapper.map( | ||
_entityClient.search(entityName, sanitizedQuery, ResolverUtils.buildFilter(input.getFilters()), null, start, | ||
_entityClient.search(entityName, sanitizedQuery, ResolverUtils.buildFilter(input.getFilters(), input.getOrFilters()), null, start, | ||
count, ResolverUtils.getAuthentication(environment))); | ||
} catch (Exception e) { | ||
log.error("Failed to execute search: entity type {}, query {}, filters: {}, start: {}, count: {}", | ||
input.getType(), input.getQuery(), input.getFilters(), start, count); | ||
log.error("Failed to execute search: entity type {}, query {}, filters: {}, orFilters: {}, start: {}, count: {}", | ||
input.getType(), input.getQuery(), input.getFilters(), input.getOrFilters(), start, count); | ||
throw new RuntimeException( | ||
"Failed to execute search: " + String.format("entity type %s, query %s, filters: %s, start: %s, count: %s", | ||
input.getType(), input.getQuery(), input.getFilters(), start, count), e); | ||
"Failed to execute search: " + String.format("entity type %s, query %s, filters: %s, orFilters: %s, start: %s, count: %s", | ||
input.getType(), input.getQuery(), input.getFilters(), input.getOrFilters(), start, count), e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so wherever it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unfortunately yes. Otherwise, we'd need to make breaking changes to the graphql api which we know folks are already making programatic calls to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to see us taking our GraphQL API and making it an OR of ANDs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is nontrivial semantic model debt I think... |
||
} | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,7 +217,7 @@ type SearchParams { | |
""" | ||
Entity types to be searched. If this is not provided, all entities will be searched. | ||
""" | ||
types: [EntityType!] | ||
types: [EntityType!] | ||
|
||
""" | ||
Search query | ||
|
@@ -237,12 +237,22 @@ type Filter { | |
""" | ||
Name of field to filter by | ||
""" | ||
field: String! | ||
field: String! | ||
|
||
""" | ||
Value of the field to filter by | ||
""" | ||
value: String! | ||
""" | ||
Values, one of which the intended field should match. | ||
""" | ||
values: [String!]! | ||
|
||
""" | ||
If the filter should or should not be matched | ||
""" | ||
negated: Boolean | ||
|
||
""" | ||
Condition for the values. How to If unset, assumed to be equality | ||
""" | ||
condition: SearchCondition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SearchCondition? These operators seem a bit independent of search. What if we called this FilterOperator? or something There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed |
||
} | ||
|
||
""" | ||
|
@@ -269,4 +279,4 @@ type ContentParams { | |
Number of entities corresponding to the recommended content | ||
""" | ||
count: Long | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,11 @@ input SearchInput { | |
Facet filters to apply to search results | ||
""" | ||
filters: [FacetFilterInput!] | ||
|
||
""" | ||
Filters are by default 'AND'-ed together. This lets you provide a set of OR filters | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. answers my question. might be nice to make note of that "and" nature on the doc string for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point |
||
""" | ||
orFilters: [FacetFilterInput!] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use a nested model instead of reusing FacetFilterInput? basically:
This is a standard way to define filters, it's Disjunctive Normal Form There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason i call this out is that once we commit this code it's going to become very nontrivial to change this, for the same reason its hard to change the existing semantics around AND filters.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And unsurprisingly, this is how we chose to model the Filter.pdl model already, because we were looking ahead at this. It's shaped as
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated! |
||
} | ||
|
||
""" | ||
|
@@ -98,6 +103,11 @@ input SearchAcrossEntitiesInput { | |
Faceted filters applied to search results | ||
""" | ||
filters: [FacetFilterInput!] | ||
|
||
""" | ||
Filters are by default 'AND'-ed together. This lets you provide a set of OR filters | ||
""" | ||
orFilters: [FacetFilterInput!] | ||
} | ||
|
||
""" | ||
|
@@ -138,6 +148,11 @@ input SearchAcrossLineageInput { | |
Faceted filters applied to search results | ||
""" | ||
filters: [FacetFilterInput!] | ||
|
||
""" | ||
Filters are by default 'AND'-ed together. This lets you provide a set of OR filters | ||
""" | ||
orFilters: [FacetFilterInput!] | ||
} | ||
|
||
""" | ||
|
@@ -150,22 +165,17 @@ input FacetFilterInput { | |
field: String! | ||
|
||
""" | ||
Value of the field to filter by (soon to be deprecated) | ||
""" | ||
value: String! | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this is a breaking change (we are removing the |
||
""" | ||
Values of the field to filter by | ||
Values, one of which the intended field should match. | ||
""" | ||
values: [String!] | ||
values: [String!]! | ||
|
||
""" | ||
If the filter should or should not be matched | ||
""" | ||
negated: Boolean | ||
|
||
""" | ||
Condition for the values. If unset, assumed to be equality | ||
Condition for the values. How to If unset, assumed to be equality | ||
""" | ||
condition: SearchCondition | ||
} | ||
|
@@ -508,9 +518,14 @@ input BrowseInput { | |
count: Int | ||
|
||
""" | ||
Faceted filters applied to browse results | ||
Faceted filters applied to browse results. These are joined together using `AND`. | ||
""" | ||
filters: [FacetFilterInput!] | ||
|
||
""" | ||
Filters are by default 'AND'-ed together. This lets you provide a set of OR filters | ||
""" | ||
orFilters: [FacetFilterInput!] | ||
} | ||
|
||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no chance this can throw an NPE right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved