Skip to content
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

fix(graphql) Fix entity type filter clash with legacy filters #10362

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.linkedin.view.DataHubViewInfo;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -68,15 +69,21 @@ public CompletableFuture<AggregateResults> get(DataFetchingEnvironment environme
final List<String> facets =
input.getFacets() != null && input.getFacets().size() > 0 ? input.getFacets() : null;

List<String> finalEntities =
maybeResolvedView != null
? SearchUtils.intersectEntityTypes(
entityNames, maybeResolvedView.getDefinition().getEntityTypes())
: entityNames;
if (finalEntities.size() == 0) {
return createEmptyAggregateResults();
}

try {
return mapAggregateResults(
context,
_entityClient.searchAcrossEntities(
context.getOperationContext().withSearchFlags(flags -> searchFlags),
maybeResolvedView != null
? SearchUtils.intersectEntityTypes(
entityNames, maybeResolvedView.getDefinition().getEntityTypes())
: entityNames,
finalEntities,
sanitizedQuery,
maybeResolvedView != null
? SearchUtils.combineFilters(
Expand Down Expand Up @@ -112,4 +119,10 @@ static AggregateResults mapAggregateResults(

return results;
}

AggregateResults createEmptyAggregateResults() {
final AggregateResults result = new AggregateResults();
result.setFacets(new ArrayList<>());
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ public CompletableFuture<SearchResults> get(DataFetchingEnvironment environment)
start,
count);

List<String> finalEntities =
maybeResolvedView != null
? SearchUtils.intersectEntityTypes(
entityNames, maybeResolvedView.getDefinition().getEntityTypes())
: entityNames;
if (finalEntities.size() == 0) {
return SearchUtils.createEmptySearchResults(start, count);
}

return UrnSearchResultsMapper.map(
context,
_entityClient.searchAcrossEntities(
context.getOperationContext().withSearchFlags(flags -> searchFlags),
maybeResolvedView != null
? SearchUtils.intersectEntityTypes(
entityNames, maybeResolvedView.getDefinition().getEntityTypes())
: entityNames,
finalEntities,
sanitizedQuery,
maybeResolvedView != null
? SearchUtils.combineFilters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.generated.EntityType;
import com.linkedin.datahub.graphql.generated.FacetFilterInput;
import com.linkedin.datahub.graphql.generated.SearchResults;
import com.linkedin.datahub.graphql.types.common.mappers.SearchFlagsInputMapper;
import com.linkedin.datahub.graphql.types.entitytype.EntityTypeMapper;
import com.linkedin.metadata.query.SearchFlags;
Expand Down Expand Up @@ -314,4 +315,15 @@ public static List<String> getEntityNames(List<EntityType> inputTypes) {
(inputTypes == null || inputTypes.isEmpty()) ? SEARCHABLE_ENTITY_TYPES : inputTypes;
return entityTypes.stream().map(EntityTypeMapper::getName).collect(Collectors.toList());
}

public static SearchResults createEmptySearchResults(final int start, final int count) {
final SearchResults result = new SearchResults();
result.setStart(start);
result.setCount(count);
result.setTotal(0);
result.setSearchResults(new ArrayList<>());
result.setSuggestions(new ArrayList<>());
result.setFacets(new ArrayList<>());
return result;
}
}
Loading