Skip to content

Commit

Permalink
fix(graphql) Fix entity type filter clash with legacy filters (datahu…
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscollins3456 authored Apr 29, 2024
1 parent 8e5c0dc commit 1af050c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
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;
}
}

0 comments on commit 1af050c

Please sign in to comment.