Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: send alias on order by expression #225

Merged
merged 1 commit into from
May 18, 2024
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
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -31,18 +32,21 @@ class AggregatableOrderByExpressionListConverter
private final Converter<OrderDirection, SortOrder> sortOrderConverter;
private final Converter<MetricAggregationType, AttributeModelMetricAggregationType>
aggregationTypeConverter;
private final MetricAggregationRequestBuilder metricAggregationRequestBuilder;

@Inject
AggregatableOrderByExpressionListConverter(
Converter<AttributeAssociation<AttributeExpression>, Expression> columnExpressionConverter,
MetricAggregationExpressionConverter metricAggregationExpressionConverter,
Converter<OrderDirection, SortOrder> sortOrderConverter,
Converter<MetricAggregationType, AttributeModelMetricAggregationType>
aggregationTypeConverter) {
aggregationTypeConverter,
MetricAggregationRequestBuilder metricAggregationRequestBuilder) {
this.columnExpressionConverter = columnExpressionConverter;
this.metricAggregationExpressionConverter = metricAggregationExpressionConverter;
this.sortOrderConverter = sortOrderConverter;
this.aggregationTypeConverter = aggregationTypeConverter;
this.metricAggregationRequestBuilder = metricAggregationRequestBuilder;
}

@Override
Expand All @@ -66,17 +70,20 @@ private Single<Expression> buildSelectionExpression(
AttributeAssociation<AggregatableOrderArgument> orderArgument) {
AttributeAssociation<AttributeExpression> attributeExpressionAssociation =
this.buildAttributeExpressionAssociation(orderArgument);
List<Object> aggregationArguments =
Optional.<Object>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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,5 +77,6 @@ protected void configure() {
Key.get(
new TypeLiteral<
Converter<MetricAggregationType, AttributeModelMetricAggregationType>>() {}));
requireBinding(MetricAggregationRequestBuilder.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,25 +50,6 @@ Single<Expression> convert(MetricAggregationRequest metricAggregation, String al
.map(functionExpression -> Expression.newBuilder().setFunction(functionExpression).build());
}

Single<Expression> convertForNoArgsOrAlias(
AttributeAssociation<AttributeExpression> attributeExpressionAssociation,
AttributeModelMetricAggregationType aggregationType) {
return convertForArgsButNoAlias(
attributeExpressionAssociation, aggregationType, Collections.emptyList());
}

Single<Expression> convertForArgsButNoAlias(
AttributeAssociation<AttributeExpression> attributeExpressionAssociation,
AttributeModelMetricAggregationType aggregationType,
List<Object> arguments) {
return this.buildAggregationFunctionExpression(
attributeExpressionAssociation,
aggregationType,
arguments,
StringValue.getDefaultInstance().getValue())
.map(functionExpression -> Expression.newBuilder().setFunction(functionExpression).build());
}

private Single<FunctionExpression> buildAggregationFunctionExpression(
AttributeAssociation<AttributeExpression> attributeExpressionAssociation,
AttributeModelMetricAggregationType aggregationType,
Expand Down
Loading