From 90c9295db3330a7ec44cba5fb25d5e795662edc1 Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Mon, 10 Jun 2024 15:54:36 +0530 Subject: [PATCH] adding order by --- .../EntityServiceAndGatewayServiceConverter.java | 14 ++++++++++++++ .../explore/entity/EntityServiceEntityFetcher.java | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/gateway-service-impl/src/main/java/org/hypertrace/gateway/service/common/converters/EntityServiceAndGatewayServiceConverter.java b/gateway-service-impl/src/main/java/org/hypertrace/gateway/service/common/converters/EntityServiceAndGatewayServiceConverter.java index 51851ba5..a8e25346 100644 --- a/gateway-service-impl/src/main/java/org/hypertrace/gateway/service/common/converters/EntityServiceAndGatewayServiceConverter.java +++ b/gateway-service-impl/src/main/java/org/hypertrace/gateway/service/common/converters/EntityServiceAndGatewayServiceConverter.java @@ -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; @@ -133,6 +134,19 @@ public static Operator convertOperator( 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())); + } + + public static SortOrder convertToEntityServiceSortOrder( + org.hypertrace.gateway.service.v1.common.SortOrder sortOrder) { + return SortOrder.valueOf(sortOrder.name()); + } + public static Expression.Builder convertToEntityServiceExpression( org.hypertrace.gateway.service.v1.common.Expression expression) { Expression.Builder builder = Expression.newBuilder(); diff --git a/gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java b/gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java index 4a4aad1c..2565c6eb 100644 --- a/gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java +++ b/gateway-service-impl/src/main/java/org/hypertrace/gateway/service/explore/entity/EntityServiceEntityFetcher.java @@ -167,12 +167,24 @@ private EntityQueryRequest buildRequest( .setFilter(buildFilter(exploreRequest, entityIdAttributeIds, entityIds)); addGroupBys(exploreRequest, builder); + addSortBy(exploreRequest, builder); addSelections(requestContext, exploreRequest, builder); builder.setLimit(exploreRequest.getLimit()); builder.setOffset(exploreRequest.getOffset()); return builder.build(); } + private void addSortBy(ExploreRequest exploreRequest, EntityQueryRequest.Builder builder) { + List orderBys = + exploreRequest.getOrderByList(); + orderBys.forEach( + orderBy -> + builder.addOrderBy( + EntityServiceAndGatewayServiceConverter.convertToEntityServiceOrderByExpression( + orderBy) + .build())); + } + private void addGroupBys(ExploreRequest exploreRequest, EntityQueryRequest.Builder builder) { List groupBys = ExpressionReader.getAttributeExpressions(exploreRequest.getGroupByList());