Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
chore | adding the eds filter support to qs explore query (#157)
Browse files Browse the repository at this point in the history
* chore | adding the eds filter support to qs explore query
  • Loading branch information
aman-bansal authored Dec 19, 2023
1 parent f280fa7 commit 481e7a3
Show file tree
Hide file tree
Showing 13 changed files with 1,176 additions and 249 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.hypertrace.gateway.service.common.converters;

import static java.lang.String.format;
import static org.hypertrace.gateway.service.v1.common.FunctionType.DISTINCT_ARRAY;

import com.google.common.base.Strings;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -472,6 +472,27 @@ public static Filter addTimeAndSpaceFiltersAndConvertToQueryFilter(
String spacesAttributeId,
org.hypertrace.gateway.service.v1.common.Filter providedFilter) {

return addTimeSpaceAndIdFiltersAndConvertToQueryFilter(
startTimeMillis,
endTimeMillis,
spaceId,
Collections.emptyList(),
timestampAttributeId,
spacesAttributeId,
Collections.emptyList(),
providedFilter);
}

public static Filter addTimeSpaceAndIdFiltersAndConvertToQueryFilter(
long startTimeMillis,
long endTimeMillis,
String spaceId,
List<String> entityIds,
String timestampAttributeId,
String spacesAttributeId,
List<String> entityIdAttributes,
org.hypertrace.gateway.service.v1.common.Filter providedFilter) {

Filter.Builder compositeFilter = Filter.newBuilder().setOperator(Operator.AND);
Filter convertedProvidedFilter =
isNonDefaultFilter(providedFilter)
Expand All @@ -493,6 +514,14 @@ public static Filter addTimeAndSpaceFiltersAndConvertToQueryFilter(
QueryRequestUtil.createStringFilter(spacesAttributeId, Operator.EQ, spaceId));
}

if (!entityIds.isEmpty()) {
compositeFilter.addChildFilter(
createEntityIdAttributeFilter(
entityIdAttributes,
Operator.IN,
QueryRequestUtil.createStringArrayLiteralExpression(entityIds)));
}

// If only one filter was added, unwrap the one child filter and use that
return compositeFilter.getChildFilterCount() == 1
? compositeFilter.getChildFilter(0)
Expand Down Expand Up @@ -531,6 +560,14 @@ private static boolean isNonDefaultFilter(Filter filter) {
return filter != null && !Filter.getDefaultInstance().equals(filter);
}

private static Filter createEntityIdAttributeFilter(
List<String> entityIdAttributes, Operator operator, Expression expression) {
if (entityIdAttributes.size() != 1) {
throw new RuntimeException("Cannot have more than one id attribute for an entity");
}
return QueryRequestUtil.createFilter(entityIdAttributes.get(0), operator, expression);
}

public static List<OrderByExpression> convertToQueryOrderByExpressions(
List<org.hypertrace.gateway.service.v1.common.OrderByExpression> gatewayOrderBy) {
return gatewayOrderBy.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import org.hypertrace.gateway.service.common.ExpressionContext;
import org.hypertrace.gateway.service.common.RequestContext;
import org.hypertrace.gateway.service.common.config.ScopeFilterConfigs;
import org.hypertrace.gateway.service.common.datafetcher.QueryServiceEntityFetcher;
import org.hypertrace.gateway.service.common.util.QueryServiceClient;
import org.hypertrace.gateway.service.entity.config.EntityIdColumnsConfigs;
import org.hypertrace.gateway.service.explore.entity.EntityRequestHandler;
import org.hypertrace.gateway.service.explore.entity.EntityServiceEntityFetcher;
import org.hypertrace.gateway.service.v1.explore.ExploreRequest;
import org.hypertrace.gateway.service.v1.explore.ExploreResponse;

Expand All @@ -46,10 +48,27 @@ public ExploreService(
ScopeFilterConfigs scopeFiltersConfig,
EntityIdColumnsConfigs entityIdColumnsConfigs,
EntityTypesProvider entityTypesProvider) {
QueryServiceEntityFetcher queryServiceEntityFetcher =
new QueryServiceEntityFetcher(
queryServiceClient, attributeMetadataProvider, entityIdColumnsConfigs);
EntityServiceEntityFetcher entityServiceEntityFetcher =
new EntityServiceEntityFetcher(
attributeMetadataProvider, entityIdColumnsConfigs, entityQueryServiceClient);
this.attributeMetadataProvider = attributeMetadataProvider;
this.normalRequestHandler = new RequestHandler(queryServiceClient, attributeMetadataProvider);
this.normalRequestHandler =
new RequestHandler(
queryServiceClient,
attributeMetadataProvider,
entityIdColumnsConfigs,
queryServiceEntityFetcher,
entityServiceEntityFetcher);
this.timeAggregationsRequestHandler =
new TimeAggregationsRequestHandler(queryServiceClient, attributeMetadataProvider);
new TimeAggregationsRequestHandler(
queryServiceClient,
attributeMetadataProvider,
entityIdColumnsConfigs,
queryServiceEntityFetcher,
entityServiceEntityFetcher);
this.timeAggregationsWithGroupByRequestHandler =
new TimeAggregationsWithGroupByRequestHandler(
attributeMetadataProvider, normalRequestHandler, timeAggregationsRequestHandler);
Expand All @@ -58,7 +77,8 @@ public ExploreService(
attributeMetadataProvider,
entityIdColumnsConfigs,
queryServiceClient,
entityQueryServiceClient);
queryServiceEntityFetcher,
entityServiceEntityFetcher);
this.scopeFilterConfigs = scopeFiltersConfig;
this.entityTypesProvider = entityTypesProvider;
initMetrics();
Expand Down
Loading

0 comments on commit 481e7a3

Please sign in to comment.