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

chore | adding the eds filter support to qs explore query #157

Merged
merged 19 commits into from
Dec 19, 2023
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
@@ -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 @@
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 @@
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 @@
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");

Check warning on line 566 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/common/converters/QueryAndGatewayDtoConverter.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/common/converters/QueryAndGatewayDtoConverter.java#L566

Added line #L566 was not covered by tests
aman-bansal marked this conversation as resolved.
Show resolved Hide resolved
}
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