diff --git a/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/AggregatableOrderByExpressionListConverter.java b/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/AggregatableOrderByExpressionListConverter.java index 5790c6a7..6e3089c9 100644 --- a/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/AggregatableOrderByExpressionListConverter.java +++ b/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/AggregatableOrderByExpressionListConverter.java @@ -5,8 +5,8 @@ import io.reactivex.rxjava3.core.Maybe; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.core.Single; +import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import javax.inject.Inject; @@ -19,6 +19,7 @@ import org.hypertrace.gateway.service.v1.common.Expression; import org.hypertrace.gateway.service.v1.common.OrderByExpression; import org.hypertrace.gateway.service.v1.common.SortOrder; +import org.hypertrace.graphql.metric.request.MetricAggregationRequestBuilder; import org.hypertrace.graphql.metric.schema.argument.AggregatableOrderArgument; class AggregatableOrderByExpressionListConverter @@ -31,6 +32,7 @@ class AggregatableOrderByExpressionListConverter private final Converter sortOrderConverter; private final Converter aggregationTypeConverter; + private final MetricAggregationRequestBuilder metricAggregationRequestBuilder; @Inject AggregatableOrderByExpressionListConverter( @@ -38,11 +40,13 @@ class AggregatableOrderByExpressionListConverter MetricAggregationExpressionConverter metricAggregationExpressionConverter, Converter sortOrderConverter, Converter - aggregationTypeConverter) { + aggregationTypeConverter, + MetricAggregationRequestBuilder metricAggregationRequestBuilder) { this.columnExpressionConverter = columnExpressionConverter; this.metricAggregationExpressionConverter = metricAggregationExpressionConverter; this.sortOrderConverter = sortOrderConverter; this.aggregationTypeConverter = aggregationTypeConverter; + this.metricAggregationRequestBuilder = metricAggregationRequestBuilder; } @Override @@ -66,17 +70,20 @@ private Single buildSelectionExpression( AttributeAssociation orderArgument) { AttributeAssociation attributeExpressionAssociation = this.buildAttributeExpressionAssociation(orderArgument); + List aggregationArguments = + Optional.ofNullable(orderArgument.value().size()) + .map(List::of) + .orElseGet(Collections::emptyList); return Maybe.fromOptional(Optional.ofNullable(orderArgument.value().aggregation())) .flatMapSingle(this.aggregationTypeConverter::convert) - .flatMapSingle( + .map( aggregationType -> - orderArgument.value().size() == null - ? this.metricAggregationExpressionConverter.convertForNoArgsOrAlias( - attributeExpressionAssociation, aggregationType) - : this.metricAggregationExpressionConverter.convertForArgsButNoAlias( - attributeExpressionAssociation, - aggregationType, - List.of(Objects.requireNonNull(orderArgument.value().size())))) + this.metricAggregationRequestBuilder.build( + attributeExpressionAssociation, aggregationType, aggregationArguments)) + .flatMapSingle( + aggregationRequest -> + this.metricAggregationExpressionConverter.convert( + aggregationRequest, aggregationRequest.alias())) .switchIfEmpty(this.columnExpressionConverter.convert(attributeExpressionAssociation)); } diff --git a/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/GatewayMetricUtilsModule.java b/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/GatewayMetricUtilsModule.java index 09ba04a8..6d1144f5 100644 --- a/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/GatewayMetricUtilsModule.java +++ b/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/GatewayMetricUtilsModule.java @@ -24,6 +24,7 @@ import org.hypertrace.gateway.service.v1.common.Value; import org.hypertrace.gateway.service.v1.entity.Entity; import org.hypertrace.graphql.metric.request.MetricAggregationRequest; +import org.hypertrace.graphql.metric.request.MetricAggregationRequestBuilder; import org.hypertrace.graphql.metric.request.MetricRequest; import org.hypertrace.graphql.metric.request.MetricSeriesRequest; import org.hypertrace.graphql.metric.schema.BaselinedMetricAggregationContainer; @@ -76,5 +77,6 @@ protected void configure() { Key.get( new TypeLiteral< Converter>() {})); + requireBinding(MetricAggregationRequestBuilder.class); } } diff --git a/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/MetricAggregationExpressionConverter.java b/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/MetricAggregationExpressionConverter.java index 04828c49..2790e15b 100644 --- a/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/MetricAggregationExpressionConverter.java +++ b/hypertrace-graphql-gateway-service-metric-utils/src/main/java/org/hypertrace/graphql/utils/metrics/gateway/MetricAggregationExpressionConverter.java @@ -2,11 +2,9 @@ import static io.reactivex.rxjava3.core.Single.zip; -import com.google.protobuf.StringValue; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.core.Single; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -52,25 +50,6 @@ Single convert(MetricAggregationRequest metricAggregation, String al .map(functionExpression -> Expression.newBuilder().setFunction(functionExpression).build()); } - Single convertForNoArgsOrAlias( - AttributeAssociation attributeExpressionAssociation, - AttributeModelMetricAggregationType aggregationType) { - return convertForArgsButNoAlias( - attributeExpressionAssociation, aggregationType, Collections.emptyList()); - } - - Single convertForArgsButNoAlias( - AttributeAssociation attributeExpressionAssociation, - AttributeModelMetricAggregationType aggregationType, - List arguments) { - return this.buildAggregationFunctionExpression( - attributeExpressionAssociation, - aggregationType, - arguments, - StringValue.getDefaultInstance().getValue()) - .map(functionExpression -> Expression.newBuilder().setFunction(functionExpression).build()); - } - private Single buildAggregationFunctionExpression( AttributeAssociation attributeExpressionAssociation, AttributeModelMetricAggregationType aggregationType,