-
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 all 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,13 @@ | |
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.datahub.graphql.generated.OrFilter; | ||
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 +84,77 @@ 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()); | ||
if (!facetFilterInput.getValues().isEmpty()) { | ||
facetFilters.put(facetFilterInput.getField(), facetFilterInput.getValues().get(0)); | ||
} | ||
}); | ||
|
||
return facetFilters; | ||
} | ||
|
||
public static List<Criterion> criterionListFromAndFilter(List<FacetFilterInput> andFilters) { | ||
return andFilters != null && !andFilters.isEmpty() | ||
? andFilters.stream() | ||
.map(filter -> criterionFromFilter(filter)) | ||
.collect(Collectors.toList()) : Collections.emptyList(); | ||
|
||
} | ||
|
||
// In the case that user sends filters to be or-d together, we need to build a series of conjunctive criterion | ||
// 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. 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! |
||
@Nonnull List<OrFilter> 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 andCriterionForOr = new CriterionArray(criterionListFromAndFilter(orFilter.getAnd())); | ||
return new ConjunctiveCriterion().setAnd( | ||
andCriterionForOr | ||
); | ||
} | ||
).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<OrFilter> 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()))))); | ||
|
||
// Or filters are the new default. We will check them first. | ||
// If we have OR filters, we need to build a series of CriterionArrays | ||
if (orFilters != null && !orFilters.isEmpty()) { | ||
return new Filter().setOr(buildConjunctiveCriterionArrayWithOr(orFilters)); | ||
} | ||
|
||
// If or filters are not set, someone may be using the legacy and filters | ||
final List<Criterion> andCriterions = criterionListFromAndFilter(andFilters); | ||
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())); | ||
if (filter.getValues() != null) { | ||
result.setValues(new StringArray(filter.getValues())); | ||
if (!filter.getValues().isEmpty()) { | ||
result.setValue(filter.getValues().get(0)); | ||
} else { | ||
result.setValue(""); | ||
} | ||
} | ||
|
||
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... |
||
} | ||
}); | ||
} | ||
|
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.
nit: annotation this
@Nonnull
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