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

feat(graphql): Add sorting option to single-entity search GraphQL API #11315

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
16922b9
add sorting in the search method for graphql
Sukeerthi31 Sep 3, 2024
1e82116
Merge branch 'datahub-project:master' into graphql-sort
Sukeerthi31 Sep 3, 2024
1f231aa
correct method header params
Sukeerthi31 Sep 3, 2024
76e0c12
correct params for datajobtype search
Sukeerthi31 Sep 3, 2024
1c4f7a5
add sort field in search resolver
Sukeerthi31 Sep 3, 2024
27eb370
Merge branch 'datahub-project:master' into graphql-sort
Sukeerthi31 Sep 4, 2024
b115f1c
Merge branch 'datahub-project:master' into graphql-sort
Sukeerthi31 Sep 6, 2024
c77b9a5
map sort input criterion
Sukeerthi31 Sep 6, 2024
7964851
update logs to fix null pointer exception on generic search
Sukeerthi31 Sep 6, 2024
4b90639
update logs
Sukeerthi31 Sep 6, 2024
09f40d9
update tests with the latest search method
Sukeerthi31 Sep 6, 2024
2b0e978
update list tests resolver tests with latest search method
Sukeerthi31 Sep 6, 2024
af55163
resolve ambiguous funtion calls
Sukeerthi31 Sep 6, 2024
92f5ca3
resolve ambiguous function calls and refer to new method
Sukeerthi31 Sep 6, 2024
1f1ab6d
update unit test search params
Sukeerthi31 Sep 6, 2024
0c2ff31
pass arg of type Filter class
Sukeerthi31 Sep 7, 2024
e2afefe
invoke map filters search with null
Sukeerthi31 Sep 7, 2024
56b07b2
spotless fixes
Sukeerthi31 Sep 7, 2024
03a57b9
Merge branch 'master' into graphql-sort
Sukeerthi31 Sep 7, 2024
2c94f03
fix unit tests using Filter type class
Sukeerthi31 Sep 7, 2024
5eb88f5
Merge branch 'graphql-sort' of https://github.com/Sukeerthi31/datahub…
Sukeerthi31 Sep 7, 2024
71429b5
Merge branch 'master' into graphql-sort
Sukeerthi31 Sep 9, 2024
09904dc
Merge remote-tracking branch 'origin/master' into graphql-sort
Sukeerthi31 Sep 24, 2024
691c999
Merge remote-tracking branch 'origin/master' into graphql-sort
Sukeerthi31 Sep 24, 2024
f456694
Merge branch 'master' into graphql-sort
Sukeerthi31 Sep 24, 2024
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 @@ -61,6 +61,7 @@ public CompletableFuture<ListBusinessAttributesResult> get(
Constants.BUSINESS_ATTRIBUTE_ENTITY_NAME,
query,
Collections.emptyMap(),
Collections.emptyList(),
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public CompletableFuture<ListGroupsResult> get(final DataFetchingEnvironment env
.withSearchFlags(flags -> flags.setFulltext(true)),
CORP_GROUP_ENTITY_NAME,
query,
null,
(Map<String, String>) null,
Collections.singletonList(
new SortCriterion()
.setField(CORP_GROUP_CREATED_TIME_INDEX_FIELD_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public CompletableFuture<ListSecretsResult> get(final DataFetchingEnvironment en
.withSearchFlags(flags -> flags.setFulltext(true)),
Constants.SECRETS_ENTITY_NAME,
query,
null,
(Map<String, String>) null,
Collections.singletonList(
new SortCriterion()
.setField(DOMAIN_CREATED_TIME_INDEX_FIELD_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public CompletableFuture<ListPostsResult> get(final DataFetchingEnvironment envi
context.getOperationContext().withSearchFlags(flags -> flags.setFulltext(true)),
POST_ENTITY_NAME,
query,
null,
(Map<String, String>) null,
sortCriteria,
start,
count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public CompletableFuture<ListRolesResult> get(final DataFetchingEnvironment envi
DATAHUB_ROLE_ENTITY_NAME,
query,
Collections.emptyMap(),
Collections.emptyList(),
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument;
import static com.linkedin.metadata.Constants.*;
import static com.linkedin.metadata.search.utils.SearchUtils.applyDefaultSearchFlags;
import static com.linkedin.metadata.search.utils.SearchUtils.*;

import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.concurrency.GraphQLConcurrencyUtils;
Expand All @@ -17,11 +17,14 @@
import com.linkedin.metadata.query.GroupingCriterionArray;
import com.linkedin.metadata.query.GroupingSpec;
import com.linkedin.metadata.query.SearchFlags;
import com.linkedin.metadata.query.filter.SortCriterion;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import io.opentelemetry.extension.annotations.WithSpan;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -66,16 +69,34 @@ public CompletableFuture<SearchResults> get(DataFetchingEnvironment environment)
} else {
searchFlags = applyDefaultSearchFlags(null, sanitizedQuery, SEARCH_RESOLVER_DEFAULTS);
}
List<SortCriterion> sortCriteria;
if (input.getSortInput() != null) {
if (input.getSortInput().getSortCriteria() != null) {
sortCriteria =
input.getSortInput().getSortCriteria().stream()
.map(SearchUtils::mapSortCriterion)
.collect(Collectors.toList());
} else {
sortCriteria =
input.getSortInput().getSortCriterion() != null
? Collections.singletonList(
SearchUtils.mapSortCriterion(input.getSortInput().getSortCriterion()))
: Collections.emptyList();
}
} else {
sortCriteria = Collections.emptyList();
}

return GraphQLConcurrencyUtils.supplyAsync(
() -> {
try {
log.debug(
"Executing search. entity type {}, query {}, filters: {}, orFilters: {}, start: {}, count: {}, searchFlags: {}",
"Executing search. entity type {}, query {}, filters: {}, orFilters: {}, sortCriteria: {}, start: {}, count: {} searchFlags: {}",
input.getType(),
input.getQuery(),
input.getFilters(),
input.getOrFilters(),
input.getSortInput(),
start,
count,
searchFlags);
Expand All @@ -87,27 +108,29 @@ public CompletableFuture<SearchResults> get(DataFetchingEnvironment environment)
entityName,
sanitizedQuery,
ResolverUtils.buildFilter(input.getFilters(), input.getOrFilters()),
Collections.emptyList(),
sortCriteria,
start,
count));
} catch (Exception e) {
log.error(
"Failed to execute search: entity type {}, query {}, filters: {}, orFilters: {}, start: {}, count: {}, searchFlags: {}",
"Failed to execute search: entity type {}, query {}, filters: {}, orFilters: {}, sortCriteria: {}, start: {}, count: {}, searchFlags: {}",
input.getType(),
input.getQuery(),
input.getFilters(),
input.getOrFilters(),
input.getSortInput(),
start,
count,
searchFlags);
throw new RuntimeException(
"Failed to execute search: "
+ String.format(
"entity type %s, query %s, filters: %s, orFilters: %s, start: %s, count: %s, searchFlags: %s",
"entity type %s, query %s, filters: %s, orFilters: %s, sortCriteria: %s, start: %s, count: %s, searchFlags: %s",
input.getType(),
input.getQuery(),
input.getFilters(),
input.getOrFilters(),
input.getSortInput(),
start,
count,
searchFlags),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public CompletableFuture<ListTestsResult> get(final DataFetchingEnvironment envi
Constants.TEST_ENTITY_NAME,
query,
Collections.emptyMap(),
Collections.emptyList(),
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public CompletableFuture<ListUsersResult> get(final DataFetchingEnvironment envi
CORP_USER_ENTITY_NAME,
query,
Collections.emptyMap(),
Collections.emptyList(),
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.linkedin.datahub.graphql.generated.FacetFilterInput;
import com.linkedin.datahub.graphql.generated.SearchResults;
import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.query.filter.SortCriterion;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -40,6 +41,7 @@ public interface SearchableEntityType<T extends Entity, K> extends EntityType<T,
SearchResults search(
@Nonnull String query,
@Nullable List<FacetFilterInput> filters,
@Nullable SortCriterion sort,
int start,
int count,
@Nonnull final QueryContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
import com.linkedin.entity.client.EntityClient;
import com.linkedin.metadata.query.AutoCompleteResult;
import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.query.filter.SortCriterion;
import com.linkedin.metadata.search.SearchResult;
import graphql.execution.DataFetcherResult;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -103,17 +106,28 @@ public List<DataFetcherResult<BusinessAttribute>> batchLoad(
public SearchResults search(
@Nonnull String query,
@Nullable List<FacetFilterInput> filters,
@Nullable SortCriterion sort,
int start,
int count,
@Nonnull QueryContext context)
throws Exception {
final Map<String, String> facetFilters = ResolverUtils.buildFacetFilters(filters, FACET_FIELDS);

final SortCriterion sortCriterion = new SortCriterion();
Optional.ofNullable(sort)
.ifPresent(
s -> {
sortCriterion.setField(s.getField());
sortCriterion.setOrder(s.getOrder());
});

final SearchResult searchResult =
_entityClient.search(
context.getOperationContext().withSearchFlags(flags -> flags.setFulltext(true)),
"businessAttribute",
query,
facetFilters,
Collections.singletonList(sortCriterion),
start,
count);
return UrnSearchResultsMapper.map(context, searchResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@
import com.linkedin.metadata.browse.BrowseResult;
import com.linkedin.metadata.query.AutoCompleteResult;
import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.query.filter.SortCriterion;
import com.linkedin.metadata.search.SearchResult;
import com.linkedin.mxe.MetadataChangeProposal;
import com.linkedin.r2.RemoteInvocationException;
import graphql.execution.DataFetcherResult;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -147,17 +150,28 @@ public List<DataFetcherResult<Chart>> batchLoad(
public SearchResults search(
@Nonnull String query,
@Nullable List<FacetFilterInput> filters,
@Nullable SortCriterion sort,
int start,
int count,
@Nonnull QueryContext context)
throws Exception {
final Map<String, String> facetFilters = ResolverUtils.buildFacetFilters(filters, FACET_FIELDS);

final SortCriterion sortCriterion = new SortCriterion();
Optional.ofNullable(sort)
.ifPresent(
s -> {
sortCriterion.setField(s.getField());
sortCriterion.setOrder(s.getOrder());
});

final SearchResult searchResult =
_entityClient.search(
context.getOperationContext().withSearchFlags(flags -> flags.setFulltext(true)),
"chart",
query,
facetFilters,
Collections.singletonList(sortCriterion),
start,
count);
return UrnSearchResultsMapper.map(context, searchResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.query.AutoCompleteResult;
import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.query.filter.SortCriterion;
import com.linkedin.metadata.search.SearchResult;
import graphql.execution.DataFetcherResult;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -120,17 +123,28 @@ private Urn getUrn(final String urnStr) {
public SearchResults search(
@Nonnull String query,
@Nullable List<FacetFilterInput> filters,
@Nullable SortCriterion sort,
int start,
int count,
@Nonnull final QueryContext context)
throws Exception {
final Map<String, String> facetFilters = ResolverUtils.buildFacetFilters(filters, FACET_FIELDS);

final SortCriterion sortCriterion = new SortCriterion();
Optional.ofNullable(sort)
.ifPresent(
s -> {
sortCriterion.setField(s.getField());
sortCriterion.setOrder(s.getOrder());
});

final SearchResult searchResult =
_entityClient.search(
context.getOperationContext().withSearchFlags(flags -> flags.setFulltext(true)),
ENTITY_NAME,
query,
facetFilters,
Collections.singletonList(sortCriterion),
start,
count);
return UrnSearchResultsMapper.map(context, searchResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.linkedin.metadata.authorization.PoliciesConfig;
import com.linkedin.metadata.query.AutoCompleteResult;
import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.query.filter.SortCriterion;
import com.linkedin.metadata.search.SearchResult;
import com.linkedin.mxe.MetadataChangeProposal;
import graphql.execution.DataFetcherResult;
Expand All @@ -40,6 +41,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -110,16 +112,25 @@ public List<DataFetcherResult<CorpGroup>> batchLoad(
public SearchResults search(
@Nonnull String query,
@Nullable List<FacetFilterInput> filters,
@Nullable SortCriterion sort,
int start,
int count,
@Nonnull final QueryContext context)
throws Exception {
final SortCriterion sortCriterion = new SortCriterion();
Optional.ofNullable(sort)
.ifPresent(
s -> {
sortCriterion.setField(s.getField());
sortCriterion.setOrder(s.getOrder());
});
final SearchResult searchResult =
_entityClient.search(
context.getOperationContext().withSearchFlags(flags -> flags.setFulltext(true)),
"corpGroup",
query,
Collections.emptyMap(),
Collections.singletonList(sortCriterion),
start,
count);
return UrnSearchResultsMapper.map(context, searchResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.linkedin.metadata.authorization.PoliciesConfig;
import com.linkedin.metadata.query.AutoCompleteResult;
import com.linkedin.metadata.query.filter.Filter;
import com.linkedin.metadata.query.filter.SortCriterion;
import com.linkedin.metadata.search.SearchResult;
import com.linkedin.mxe.MetadataChangeProposal;
import graphql.execution.DataFetcherResult;
Expand Down Expand Up @@ -113,16 +114,26 @@ public List<DataFetcherResult<CorpUser>> batchLoad(
public SearchResults search(
@Nonnull String query,
@Nullable List<FacetFilterInput> filters,
@Nullable SortCriterion sort,
int start,
int count,
@Nonnull final QueryContext context)
throws Exception {

final SortCriterion sortCriterion = new SortCriterion();
Optional.ofNullable(sort)
.ifPresent(
s -> {
sortCriterion.setField(s.getField());
sortCriterion.setOrder(s.getOrder());
});
final SearchResult searchResult =
_entityClient.search(
context.getOperationContext().withSearchFlags(flags -> flags.setFulltext(true)),
"corpuser",
query,
Collections.emptyMap(),
Collections.singletonList(sortCriterion),
start,
count);
return UrnSearchResultsMapper.map(context, searchResult);
Expand Down
Loading
Loading