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

chore | adding the support pagination in explore #202

Merged
merged 11 commits into from
Jun 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hypertrace.entity.query.service.v1.ColumnMetadata;
import org.hypertrace.entity.query.service.v1.EntityQueryRequest;
import org.hypertrace.entity.query.service.v1.Expression;
import org.hypertrace.entity.query.service.v1.Expression.Builder;
import org.hypertrace.entity.query.service.v1.Filter;
import org.hypertrace.entity.query.service.v1.Function;
import org.hypertrace.entity.query.service.v1.LiteralConstant;
Expand Down Expand Up @@ -133,6 +134,19 @@
return Operator.valueOf(operator.name());
}

public static OrderByExpression.Builder convertToEntityServiceOrderByExpression(
org.hypertrace.gateway.service.v1.common.OrderByExpression orderByExpression) {
Builder expressionBuilder = convertToEntityServiceExpression(orderByExpression.getExpression());
return OrderByExpression.newBuilder()
.setExpression(expressionBuilder)
.setOrder(convertToEntityServiceSortOrder(orderByExpression.getOrder()));

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

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/common/converters/EntityServiceAndGatewayServiceConverter.java#L139-L142

Added lines #L139 - L142 were not covered by tests
}

public static SortOrder convertToEntityServiceSortOrder(
org.hypertrace.gateway.service.v1.common.SortOrder sortOrder) {
return SortOrder.valueOf(sortOrder.name());

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

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/common/converters/EntityServiceAndGatewayServiceConverter.java#L147

Added line #L147 was not covered by tests
}

public static Expression.Builder convertToEntityServiceExpression(
org.hypertrace.gateway.service.v1.common.Expression expression) {
Expression.Builder builder = Expression.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ private IRequestHandler getRequestHandler(
ExploreRequest request,
Map<String, AttributeMetadata> attributeMetadataMap,
RequestContext requestContext) {
if (isContextAnEntityType(request, requestContext)
&& !hasTimeAggregations(request)
&& !request.getGroupByList().isEmpty()) {
if (isContextAnEntityType(request, requestContext) && !hasTimeAggregations(request)) {
ExpressionContext expressionContext =
new ExpressionContext(
gatewayServiceConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public ExploreResponse.Builder handleRequest(
buildQueryRequest(requestContext, request, attributeMetadataProvider);

Iterator<ResultSetChunk> resultSetChunkIterator = executeQuery(requestContext, queryRequest);

return handleQueryServiceResponse(
request, requestContext, resultSetChunkIterator, requestContext, attributeMetadataProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
*/
public class EntityRequestHandler extends RequestHandler {
private final EntityServiceEntityFetcher entityServiceEntityFetcher;
private final AttributeMetadataProvider attributeMetadataProvider;
private final QueryServiceEntityFetcher queryServiceEntityFetcher;

public EntityRequestHandler(
AttributeMetadataProvider attributeMetadataProvider,
Expand All @@ -50,9 +48,7 @@ public EntityRequestHandler(
entityIdColumnsConfig,
queryServiceEntityFetcher,
entityServiceEntityFetcher);
this.attributeMetadataProvider = attributeMetadataProvider;
this.entityServiceEntityFetcher = entityServiceEntityFetcher;
this.queryServiceEntityFetcher = queryServiceEntityFetcher;
}

@Override
Expand All @@ -67,7 +63,8 @@ public ExploreResponse.Builder handleRequest(
ExploreResponse.Builder builder = ExploreResponse.newBuilder();
Set<String> entityIds = new HashSet<>();
Optional<EntityOption> maybeEntityOption = getEntityOption(exploreRequest);
if (requestOnLiveEntities(maybeEntityOption)) {
boolean requestOnLiveEntities = requestOnLiveEntities(maybeEntityOption);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
boolean requestOnLiveEntities = requestOnLiveEntities(maybeEntityOption);
boolean canRequestLiveEntities = canRequestLiveEntities(maybeEntityOption);

if (requestOnLiveEntities) {
entityIds.addAll(getEntityIdsInTimeRangeFromQueryService(requestContext, exploreRequest));
if (entityIds.isEmpty()) {
return builder;
Expand All @@ -76,16 +73,6 @@ public ExploreResponse.Builder handleRequest(

builder.addAllRow(
entityServiceEntityFetcher.getResults(requestContext, exploreRequest, entityIds));

// If there's a Group By in the request, we need to do the sorting and pagination ourselves.
aman-bansal marked this conversation as resolved.
Show resolved Hide resolved
if (requestContext.hasGroupBy()) {
sortAndPaginatePostProcess(
builder,
requestContext.getOrderByExpressions(),
requestContext.getRowLimitBeforeRest(),
requestContext.getOffset());
}

if (requestContext.hasGroupBy() && requestContext.getIncludeRestGroup()) {
getTheRestGroupRequestHandler()
.getRowsForTheRestGroup(requestContext, exploreRequest, builder);
Expand Down Expand Up @@ -122,10 +109,7 @@ protected List<org.hypertrace.gateway.service.v1.common.Row.Builder> sortAndPagi
}

private boolean requestOnLiveEntities(Optional<EntityOption> entityOption) {
if (entityOption.isEmpty()) {
return true;
}
return !entityOption.get().getIncludeNonLiveEntities();
return entityOption.map(option -> !option.getIncludeNonLiveEntities()).orElse(true);
}

private Optional<EntityOption> getEntityOption(ExploreRequest exploreRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

public class EntityServiceEntityFetcher {
private static final Logger LOGGER = LoggerFactory.getLogger(EntityServiceEntityFetcher.class);
private static final int DEFAULT_ENTITY_REQUEST_LIMIT = 10_000;
private final AttributeMetadataProvider attributeMetadataProvider;
private final EntityIdColumnsConfig entityIdColumnsConfig;
private final EntityQueryServiceClient entityQueryServiceClient;
Expand Down Expand Up @@ -168,11 +167,24 @@
.setFilter(buildFilter(exploreRequest, entityIdAttributeIds, entityIds));

addGroupBys(exploreRequest, builder);
addSortBy(exploreRequest, builder);
addSelections(requestContext, exploreRequest, builder);
builder.setLimit(DEFAULT_ENTITY_REQUEST_LIMIT);
builder.setLimit(exploreRequest.getLimit());
aman-bansal marked this conversation as resolved.
Show resolved Hide resolved
builder.setOffset(exploreRequest.getOffset());
return builder.build();
}

private void addSortBy(ExploreRequest exploreRequest, EntityQueryRequest.Builder builder) {
List<org.hypertrace.gateway.service.v1.common.OrderByExpression> orderBys =
exploreRequest.getOrderByList();
orderBys.forEach(
orderBy ->
builder.addOrderBy(
EntityServiceAndGatewayServiceConverter.convertToEntityServiceOrderByExpression(

Check warning on line 183 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L182-L183

Added lines #L182 - L183 were not covered by tests
orderBy)
.build()));

Check warning on line 185 in gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java

View check run for this annotation

Codecov / codecov/patch

gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java#L185

Added line #L185 was not covered by tests
}

private void addGroupBys(ExploreRequest exploreRequest, EntityQueryRequest.Builder builder) {
List<org.hypertrace.gateway.service.v1.common.Expression> groupBys =
ExpressionReader.getAttributeExpressions(exploreRequest.getGroupByList());
Expand Down
Loading