use of org.hypertrace.gateway.service.v1.common.FunctionExpression in project gateway-service by hypertrace.
the class EntityInteractionsFetcher method parseResultSet.
private void parseResultSet(String entityType, String otherEntityType, Collection<Expression> selections, Map<String, FunctionExpression> metricToAggFunction, Iterator<ResultSetChunk> resultset, boolean incoming, Map<EntityKey, Builder> entityIdToBuilders, RequestContext requestContext) {
Map<String, AttributeMetadata> attributeMetadataMap = metadataProvider.getAttributesMetadata(requestContext, SCOPE);
Map<String, AttributeKind> aliasToAttributeKind = MetricAggregationFunctionUtil.getValueTypeForFunctionType(metricToAggFunction, attributeMetadataMap);
while (resultset.hasNext()) {
ResultSetChunk chunk = resultset.next();
if (LOG.isDebugEnabled()) {
LOG.debug("Received chunk: " + chunk.toString());
}
if (chunk.getRowCount() < 1) {
break;
}
for (Row row : chunk.getRowList()) {
// Construct the from/to EntityKeys from the columns
List<String> idColumns = getEntityIdColumnsFromInteraction(DomainEntityType.valueOf(entityType.toUpperCase()), // Note: We add the selections it in this order
!incoming);
EntityKey entityId = EntityKey.of(IntStream.range(0, idColumns.size()).mapToObj(value -> row.getColumn(value).getString()).toArray(String[]::new));
List<String> otherIdColumns = getEntityIdColumnsFromInteraction(DomainEntityType.valueOf(otherEntityType.toUpperCase()), incoming);
EntityKey otherEntityId = EntityKey.of(IntStream.range(idColumns.size(), idColumns.size() + otherIdColumns.size()).mapToObj(value -> row.getColumn(value).getString()).toArray(String[]::new));
EntityInteraction.Builder interaction = EntityInteraction.newBuilder();
addInteractionEdges(interaction, selections, incoming ? otherEntityType : entityType, incoming ? otherEntityId : entityId, incoming ? entityType : otherEntityType, incoming ? entityId : otherEntityId);
for (int i = idColumns.size() + otherIdColumns.size(); i < chunk.getResultSetMetadata().getColumnMetadataCount(); i++) {
ColumnMetadata metadata = chunk.getResultSetMetadata().getColumnMetadata(i);
// Ignore the count column since we introduced that ourselves into the query.
if (StringUtils.equalsIgnoreCase(COUNT_COLUMN_NAME, metadata.getColumnName())) {
continue;
}
// Check if this is an attribute vs metric and set it accordingly on the interaction.
if (metricToAggFunction.containsKey(metadata.getColumnName())) {
Value value = QueryAndGatewayDtoConverter.convertToGatewayValueForMetricValue(aliasToAttributeKind, attributeMetadataMap, metadata, row.getColumn(i));
interaction.putMetrics(metadata.getColumnName(), AggregatedMetricValue.newBuilder().setValue(value).setFunction(metricToAggFunction.get(metadata.getColumnName()).getFunction()).build());
} else {
interaction.putAttribute(metadata.getColumnName(), QueryAndGatewayDtoConverter.convertQueryValueToGatewayValue(row.getColumn(i), attributeMetadataMap.get(metadata.getColumnName())));
}
}
if (incoming) {
entityIdToBuilders.get(entityId).addIncomingInteraction(interaction);
} else {
entityIdToBuilders.get(entityId).addOutgoingInteraction(interaction);
}
if (LOG.isDebugEnabled()) {
LOG.debug(interaction.build().toString());
}
}
}
}
use of org.hypertrace.gateway.service.v1.common.FunctionExpression in project gateway-service by hypertrace.
the class BaselineServiceImpl method getTimeAggregationsForAggregateExpr.
private List<TimeAggregation> getTimeAggregationsForAggregateExpr(BaselineEntitiesRequest originalRequest, long alignedStartTime, long alignedEndTime) {
List<FunctionExpression> aggregateList = originalRequest.getBaselineAggregateRequestList();
List<TimeAggregation> timeAggregationList = new ArrayList<>();
for (FunctionExpression function : aggregateList) {
TimeAggregation timeAggregation = getAggregationFunction(function, alignedStartTime, alignedEndTime);
timeAggregationList.add(timeAggregation);
}
return timeAggregationList;
}
use of org.hypertrace.gateway.service.v1.common.FunctionExpression in project gateway-service by hypertrace.
the class ExpressionReader method getSelectionResultName.
public static Optional<String> getSelectionResultName(Expression expression) {
switch(expression.getValueCase()) {
case COLUMNIDENTIFIER:
return Optional.of(expression.getColumnIdentifier().getAlias().isEmpty() ? expression.getColumnIdentifier().getColumnName() : expression.getColumnIdentifier().getAlias());
case ATTRIBUTE_EXPRESSION:
return Optional.of(expression.getAttributeExpression().getAlias().isEmpty() ? expression.getAttributeExpression().getAttributeId() : expression.getAttributeExpression().getAlias());
case FUNCTION:
FunctionExpression functionExpression = expression.getFunction();
if (!functionExpression.getAlias().isEmpty()) {
return Optional.of(functionExpression.getAlias());
}
String argumentString = functionExpression.getArgumentsList().stream().map(ExpressionReader::getSelectionResultName).flatMap(Optional::stream).collect(Collectors.joining(","));
return Optional.of(String.format("%s_%s", functionExpression.getFunction(), argumentString));
default:
return Optional.empty();
}
}
use of org.hypertrace.gateway.service.v1.common.FunctionExpression in project gateway-service by hypertrace.
the class RequestHandler method handleQueryServiceResponseSingleColumn.
protected void handleQueryServiceResponseSingleColumn(Value queryServiceValue, ColumnMetadata metadata, org.hypertrace.gateway.service.v1.common.Row.Builder rowBuilder, ExploreRequestContext requestContext, AttributeMetadataProvider attributeMetadataProvider) {
FunctionExpression function = requestContext.getFunctionExpressionByAlias(metadata.getColumnName());
handleQueryServiceResponseSingleColumn(queryServiceValue, metadata, rowBuilder, requestContext, attributeMetadataProvider, function);
}
use of org.hypertrace.gateway.service.v1.common.FunctionExpression in project gateway-service by hypertrace.
the class GatewayValueToQueryValueConverterTest method getFunctionMap.
private Map<FunctionExpression, Function> getFunctionMap() {
Expression gatewayExprArgument = QueryExpressionUtil.buildAttributeExpression("API.apiId").build();
org.hypertrace.core.query.service.api.Expression queryExprArgument = QueryRequestUtil.createAttributeExpression("API.apiId");
return Map.of(FunctionExpression.newBuilder().setFunction(FunctionType.SUM).addArguments(gatewayExprArgument).build(), Function.newBuilder().setFunctionName("SUM").addArguments(queryExprArgument).build(), FunctionExpression.newBuilder().setFunction(FunctionType.AVG).addArguments(gatewayExprArgument).build(), Function.newBuilder().setFunctionName("AVG").addArguments(queryExprArgument).build(), FunctionExpression.newBuilder().setFunction(FunctionType.COUNT).addArguments(gatewayExprArgument).build(), Function.newBuilder().setFunctionName("COUNT").addArguments(queryExprArgument).build(), FunctionExpression.newBuilder().setFunction(FunctionType.DISTINCTCOUNT).addArguments(gatewayExprArgument).build(), Function.newBuilder().setFunctionName("DISTINCTCOUNT").addArguments(queryExprArgument).build(), FunctionExpression.newBuilder().setFunction(FunctionType.MAX).addArguments(gatewayExprArgument).build(), Function.newBuilder().setFunctionName("MAX").addArguments(queryExprArgument).build(), FunctionExpression.newBuilder().setFunction(FunctionType.MIN).addArguments(gatewayExprArgument).build(), Function.newBuilder().setFunctionName("MIN").addArguments(queryExprArgument).build(), FunctionExpression.newBuilder().setFunction(FunctionType.LATEST).addArguments(gatewayExprArgument).build(), Function.newBuilder().setFunctionName("LATEST").addArguments(queryExprArgument).build());
}
Aggregations