Skip to content

Commit

Permalink
feat(search): support sorting on multiple fields (#10775)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHolstien authored Aug 9, 2024
1 parent 4d2af40 commit 06562f3
Show file tree
Hide file tree
Showing 69 changed files with 519 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ private SearchResult searchForNewUsers(@Nonnull final OperationContext opContext
.setValue(
String.valueOf(
trailingMonthDateRange.getStart())))))))),
new SortCriterion()
.setField(CORP_USER_STATUS_LAST_MODIFIED_FIELD_NAME)
.setOrder(SortOrder.DESCENDING),
Collections.singletonList(
new SortCriterion()
.setField(CORP_USER_STATUS_LAST_MODIFIED_FIELD_NAME)
.setOrder(SortOrder.DESCENDING)),
0,
100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ private List<AnalyticsChart> getCharts(MetadataAnalyticsInput input, OperationCo
}

SearchResult searchResult =
_entityClient.searchAcrossEntities(opContext, entities, query, filter, 0, 0, null, null);
_entityClient.searchAcrossEntities(
opContext, entities, query, filter, 0, 0, Collections.emptyList(), null);

List<AggregationMetadata> aggregationMetadataList =
searchResult.getMetadata().getAggregations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -181,7 +182,7 @@ private Set<Urn> getPoliciesFor(
Constants.POLICY_ENTITY_NAME,
"",
buildFilterToGetPolicies(user, groups, roles),
sortCriterion,
Collections.singletonList(sortCriterion),
0,
10000)
.getEntities()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ public CompletableFuture<ListAccessTokenResult> get(DataFetchingEnvironment envi
if (AuthorizationUtils.canManageTokens(context)
|| isListingSelfTokens(filters, context)) {
try {
final SortCriterion sortCriterion =
new SortCriterion()
.setField(EXPIRES_AT_FIELD_NAME)
.setOrder(SortOrder.DESCENDING);
final List<SortCriterion> sortCriteria =
Collections.singletonList(
new SortCriterion()
.setField(EXPIRES_AT_FIELD_NAME)
.setOrder(SortOrder.DESCENDING));
final SearchResult searchResult =
_entityClient.search(
context
Expand All @@ -74,7 +75,7 @@ public CompletableFuture<ListAccessTokenResult> get(DataFetchingEnvironment envi
filters,
Collections.emptyList(),
context.getOperationContext().getAspectRetriever()),
sortCriterion,
sortCriteria,
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.linkedin.metadata.query.filter.Filter;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -92,7 +93,7 @@ public CompletableFuture<SearchResults> get(final DataFetchingEnvironment enviro
new CriterionArray(ImmutableList.of(filterCriterion))))),
start,
count,
null,
Collections.emptyList(),
null));

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.linkedin.metadata.query.filter.Filter;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -98,7 +99,7 @@ public CompletableFuture<SearchResults> get(final DataFetchingEnvironment enviro
new ConjunctiveCriterion().setAnd(criteria))),
start,
count,
null,
Collections.emptyList(),
null));

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -66,9 +67,10 @@ public CompletableFuture<ListDomainsResult> get(final DataFetchingEnvironment en
Constants.DOMAIN_ENTITY_NAME,
query,
filter,
new SortCriterion()
.setField(DOMAIN_CREATED_TIME_INDEX_FIELD_NAME)
.setOrder(SortOrder.DESCENDING),
Collections.singletonList(
new SortCriterion()
.setField(DOMAIN_CREATED_TIME_INDEX_FIELD_NAME)
.setOrder(SortOrder.DESCENDING)),
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -64,9 +65,10 @@ public CompletableFuture<ListGroupsResult> get(final DataFetchingEnvironment env
CORP_GROUP_ENTITY_NAME,
query,
null,
new SortCriterion()
.setField(CORP_GROUP_CREATED_TIME_INDEX_FIELD_NAME)
.setOrder(SortOrder.DESCENDING),
Collections.singletonList(
new SortCriterion()
.setField(CORP_GROUP_CREATED_TIME_INDEX_FIELD_NAME)
.setOrder(SortOrder.DESCENDING)),
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import graphql.schema.DataFetchingEnvironment;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -60,13 +61,13 @@ public CompletableFuture<EntityIncidentsResult> get(DataFetchingEnvironment envi
// Index!
// We use the search index so that we can easily sort by the last updated time.
final Filter filter = buildIncidentsEntityFilter(entityUrn, maybeState);
final SortCriterion sortCriterion = buildIncidentsSortCriterion();
final List<SortCriterion> sortCriteria = buildIncidentsSortCriteria();
final SearchResult searchResult =
_entityClient.filter(
context.getOperationContext(),
Constants.INCIDENT_ENTITY_NAME,
filter,
sortCriterion,
sortCriteria,
start,
count);

Expand Down Expand Up @@ -118,10 +119,10 @@ private Filter buildIncidentsEntityFilter(
return QueryUtils.newFilter(criterionMap);
}

private SortCriterion buildIncidentsSortCriterion() {
private List<SortCriterion> buildIncidentsSortCriteria() {
final SortCriterion sortCriterion = new SortCriterion();
sortCriterion.setField(CREATED_TIME_SEARCH_INDEX_FIELD_NAME);
sortCriterion.setOrder(SortOrder.DESCENDING);
return sortCriterion;
return Collections.singletonList(sortCriterion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.linkedin.metadata.search.SearchResult;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -76,9 +77,10 @@ public CompletableFuture<IngestionSourceExecutionRequests> get(
new ConjunctiveCriterion()
.setAnd(
new CriterionArray(ImmutableList.of(filterCriterion))))),
new SortCriterion()
.setField(REQUEST_TIME_MS_FIELD_NAME)
.setOrder(SortOrder.DESCENDING),
Collections.singletonList(
new SortCriterion()
.setField(REQUEST_TIME_MS_FIELD_NAME)
.setOrder(SortOrder.DESCENDING)),
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -73,9 +74,10 @@ public CompletableFuture<ListSecretsResult> get(final DataFetchingEnvironment en
Constants.SECRETS_ENTITY_NAME,
query,
null,
new SortCriterion()
.setField(DOMAIN_CREATED_TIME_INDEX_FIELD_NAME)
.setOrder(SortOrder.DESCENDING),
Collections.singletonList(
new SortCriterion()
.setField(DOMAIN_CREATED_TIME_INDEX_FIELD_NAME)
.setOrder(SortOrder.DESCENDING)),
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import graphql.schema.DataFetchingEnvironment;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -61,13 +62,13 @@ public CompletableFuture<DataProcessInstanceResult> get(DataFetchingEnvironment
// Index!
// We use the search index so that we can easily sort by the last updated time.
final Filter filter = buildTaskRunsEntityFilter(entityUrn);
final SortCriterion sortCriterion = buildTaskRunsSortCriterion();
final List<SortCriterion> sortCriteria = buildTaskRunsSortCriteria();
final SearchResult gmsResult =
_entityClient.filter(
context.getOperationContext(),
Constants.DATA_PROCESS_INSTANCE_ENTITY_NAME,
filter,
sortCriterion,
sortCriteria,
start,
count);
final List<Urn> dataProcessInstanceUrns =
Expand Down Expand Up @@ -123,10 +124,10 @@ private Filter buildTaskRunsEntityFilter(final String entityUrn) {
return filter;
}

private SortCriterion buildTaskRunsSortCriterion() {
private List<SortCriterion> buildTaskRunsSortCriteria() {
final SortCriterion sortCriterion = new SortCriterion();
sortCriterion.setField(CREATED_TIME_SEARCH_INDEX_FIELD_NAME);
sortCriterion.setOrder(SortOrder.DESCENDING);
return sortCriterion;
return Collections.singletonList(sortCriterion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import graphql.schema.DataFetchingEnvironment;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -67,13 +68,13 @@ public CompletableFuture<DataProcessInstanceResult> get(DataFetchingEnvironment
// Index!
// We use the search index so that we can easily sort by the last updated time.
final Filter filter = buildTaskRunsEntityFilter(entityUrn, direction);
final SortCriterion sortCriterion = buildTaskRunsSortCriterion();
final List<SortCriterion> sortCriteria = buildTaskRunsSortCriteria();
final SearchResult gmsResult =
_entityClient.filter(
context.getOperationContext(),
Constants.DATA_PROCESS_INSTANCE_ENTITY_NAME,
filter,
sortCriterion,
sortCriteria,
start,
count);
final List<Urn> dataProcessInstanceUrns =
Expand Down Expand Up @@ -133,10 +134,10 @@ private Filter buildTaskRunsEntityFilter(
return filter;
}

private SortCriterion buildTaskRunsSortCriterion() {
private List<SortCriterion> buildTaskRunsSortCriteria() {
final SortCriterion sortCriterion = new SortCriterion();
sortCriterion.setField(CREATED_TIME_SEARCH_INDEX_FIELD_NAME);
sortCriterion.setOrder(SortOrder.DESCENDING);
return sortCriterion;
return Collections.singletonList(sortCriterion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public CompletableFuture<ListOwnershipTypesResult> get(DataFetchingEnvironment e
filters,
Collections.emptyList(),
context.getOperationContext().getAspectRetriever()),
DEFAULT_SORT_CRITERION,
Collections.singletonList(DEFAULT_SORT_CRITERION),
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import com.linkedin.metadata.search.SearchResult;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -49,10 +51,11 @@ public CompletableFuture<ListPostsResult> get(final DataFetchingEnvironment envi
return GraphQLConcurrencyUtils.supplyAsync(
() -> {
try {
final SortCriterion sortCriterion =
new SortCriterion()
.setField(LAST_MODIFIED_FIELD_NAME)
.setOrder(SortOrder.DESCENDING);
final List<SortCriterion> sortCriteria =
Collections.singletonList(
new SortCriterion()
.setField(LAST_MODIFIED_FIELD_NAME)
.setOrder(SortOrder.DESCENDING));

// First, get all Post Urns.
final SearchResult gmsResult =
Expand All @@ -61,7 +64,7 @@ public CompletableFuture<ListPostsResult> get(final DataFetchingEnvironment envi
POST_ENTITY_NAME,
query,
null,
sortCriterion,
sortCriteria,
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public CompletableFuture<ListQueriesResult> get(final DataFetchingEnvironment en
return GraphQLConcurrencyUtils.supplyAsync(
() -> {
try {
final SortCriterion sortCriterion =
new SortCriterion().setField(CREATED_AT_FIELD).setOrder(SortOrder.DESCENDING);
final List<SortCriterion> sortCriteria =
Collections.singletonList(
new SortCriterion().setField(CREATED_AT_FIELD).setOrder(SortOrder.DESCENDING));

// First, get all Query Urns.
final SearchResult gmsResult =
Expand All @@ -74,7 +75,7 @@ public CompletableFuture<ListQueriesResult> get(final DataFetchingEnvironment en
QUERY_ENTITY_NAME,
query,
buildFilters(input, context.getOperationContext().getAspectRetriever()),
sortCriterion,
sortCriteria,
start,
count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -94,7 +95,7 @@ public CompletableFuture<AggregateResults> get(DataFetchingEnvironment environme
: inputFilter,
0,
0, // 0 entity count because we don't want resolved entities
null,
Collections.emptyList(),
facets));
} catch (Exception e) {
log.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import graphql.schema.DataFetchingEnvironment;
import io.datahubproject.metadata.context.OperationContext;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -107,7 +108,7 @@ private SearchResult getSearchResults(
: null,
0,
0,
null,
Collections.emptyList(),
null);
}

Expand Down
Loading

0 comments on commit 06562f3

Please sign in to comment.