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

Commit

Permalink
fix(explore): missing attribute kind, due to incorrect metadata map (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
skjindal93 authored Mar 26, 2022
1 parent 1de3e4c commit b505531
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ExploreRequestContext(
this.orderByExpressions = exploreRequest.getOrderByList();
}

ExploreRequest getExploreRequest() {
public ExploreRequest getExploreRequest() {
return this.exploreRequest;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.hypertrace.gateway.service.explore;

import com.google.common.collect.Streams;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.hypertrace.core.attribute.service.v1.AttributeMetadata;
import org.hypertrace.core.query.service.api.ColumnMetadata;
import org.hypertrace.core.query.service.api.Filter;
Expand All @@ -24,6 +26,7 @@
import org.hypertrace.gateway.service.v1.common.Expression;
import org.hypertrace.gateway.service.v1.common.FunctionExpression;
import org.hypertrace.gateway.service.v1.common.OrderByExpression;
import org.hypertrace.gateway.service.v1.common.TimeAggregation;
import org.hypertrace.gateway.service.v1.explore.ExploreRequest;
import org.hypertrace.gateway.service.v1.explore.ExploreResponse;
import org.slf4j.Logger;
Expand Down Expand Up @@ -271,17 +274,22 @@ void handleQueryServiceResponseSingleColumn(
Map<String, AttributeMetadata> attributeMetadataMap =
attributeMetadataProvider.getAttributesMetadata(
requestContext, requestContext.getContext());
Map<String, AttributeMetadata> resultKeyToAttributeMetadataMap =
this.remapAttributeMetadataByResultName(
requestContext.getExploreRequest(), attributeMetadataMap);
org.hypertrace.gateway.service.v1.common.Value gwValue;
if (function != null) { // Function expression value
gwValue =
QueryAndGatewayDtoConverter.convertToGatewayValueForMetricValue(
MetricAggregationFunctionUtil.getValueTypeForFunctionType(
function, attributeMetadataMap),
attributeMetadataMap,
resultKeyToAttributeMetadataMap,
metadata,
queryServiceValue);
} else { // Simple columnId Expression value eg. groupBy columns or column selections
gwValue = getValueForColumnIdExpression(queryServiceValue, metadata, attributeMetadataMap);
gwValue =
getValueForColumnIdExpression(
queryServiceValue, metadata, resultKeyToAttributeMetadataMap);
}

rowBuilder.putColumns(metadata.getColumnName(), gwValue);
Expand All @@ -290,9 +298,9 @@ void handleQueryServiceResponseSingleColumn(
private org.hypertrace.gateway.service.v1.common.Value getValueForColumnIdExpression(
Value queryServiceValue,
ColumnMetadata metadata,
Map<String, AttributeMetadata> attributeMetadataMap) {
Map<String, AttributeMetadata> resultKeyToAttributeMetadataMap) {
return QueryAndGatewayDtoConverter.convertToGatewayValue(
metadata.getColumnName(), queryServiceValue, attributeMetadataMap);
metadata.getColumnName(), queryServiceValue, resultKeyToAttributeMetadataMap);
}

@Override
Expand Down Expand Up @@ -329,4 +337,18 @@ protected Logger getLogger() {
protected TheRestGroupRequestHandler getTheRestGroupRequestHandler() {
return this.theRestGroupRequestHandler;
}

private Map<String, AttributeMetadata> remapAttributeMetadataByResultName(
ExploreRequest request, Map<String, AttributeMetadata> attributeMetadataByIdMap) {
return AttributeMetadataUtil.remapAttributeMetadataByResultKey(
Streams.concat(
request.getSelectionList().stream(),
request.getTimeAggregationList().stream().map(TimeAggregation::getAggregation),
// Add groupBy to Selection list.
// The expectation from the Gateway service client is that they do not add the group
// by expressions to the selection expressions in the request
request.getGroupByList().stream())
.collect(Collectors.toUnmodifiableList()),
attributeMetadataByIdMap);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hypertrace.gateway.service.explore.entity;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Streams;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -218,23 +219,39 @@ void handleColumn(
Map<String, AttributeMetadata> attributeMetadataMap =
attributeMetadataProvider.getAttributesMetadata(
requestContext, requestContext.getContext());
Map<String, AttributeMetadata> resultKeyToAttributeMetadataMap =
this.remapAttributeMetadataByResultName(
requestContext.getExploreRequest(), attributeMetadataMap);
org.hypertrace.gateway.service.v1.common.Value gwValue;
if (function != null) {
// Function expression value
gwValue =
EntityServiceAndGatewayServiceConverter.convertToGatewayValueForMetricValue(
MetricAggregationFunctionUtil.getValueTypeForFunctionType(
function, attributeMetadataMap),
attributeMetadataMap,
resultKeyToAttributeMetadataMap,
metadata,
value);
} else {
// Simple columnId expression value eg. groupBy columns or column selections
gwValue =
EntityServiceAndGatewayServiceConverter.convertToGatewayValue(
metadata.getColumnName(), value, attributeMetadataMap);
metadata.getColumnName(), value, resultKeyToAttributeMetadataMap);
}

rowBuilder.putColumns(metadata.getColumnName(), gwValue);
}

private Map<String, AttributeMetadata> remapAttributeMetadataByResultName(
ExploreRequest request, Map<String, AttributeMetadata> attributeMetadataByIdMap) {
return AttributeMetadataUtil.remapAttributeMetadataByResultKey(
Streams.concat(
request.getSelectionList().stream(),
// Add groupBy to Selection list.
// The expectation from the Gateway service client is that they do not add the group
// by expressions to the selection expressions in the request
request.getGroupByList().stream())
.collect(Collectors.toUnmodifiableList()),
attributeMetadataByIdMap);
}
}

0 comments on commit b505531

Please sign in to comment.