use of org.hypertrace.entity.query.service.v1.Function in project entity-service by hypertrace.
the class AggregationAliasProviderTest method testGetSetAlias.
@Test
void testGetSetAlias() throws ConversionException {
Function expression = aggregateExpressionBuilder.setFunctionName("DISTINCT").setAlias("total_population_in_Mars").build();
assertEquals("total_population_in_Mars", aggregationAliasProvider.getAlias(expression));
}
use of org.hypertrace.entity.query.service.v1.Function in project entity-service by hypertrace.
the class QueryConverter method getExpressionsForFromClause.
private List<Expression> getExpressionsForFromClause(final EntityQueryRequest request) throws ConversionException {
final List<Expression> list = new ArrayList<>(request.getGroupByList());
for (Expression expression : request.getSelectionList()) {
if (expression.hasFunction()) {
org.hypertrace.entity.query.service.v1.Function function = expression.getFunction();
final Expression aggregationColumn = aggregationColumnProvider.getAggregationColumn(function);
list.add(aggregationColumn);
}
}
return unmodifiableList(list);
}
use of org.hypertrace.entity.query.service.v1.Function in project entity-service by hypertrace.
the class AggregationAliasProvider method getAlias.
@Override
public String getAlias(final Function aggregateExpression) throws ConversionException {
final Expression expression = aggregationColumnProvider.getAggregationColumn(aggregateExpression);
final ColumnIdentifier containingIdentifier = expressionAccessor.access(expression, expression.getValueCase(), Set.of(COLUMNIDENTIFIER));
final String alias = aggregateExpression.getAlias();
if (StringUtils.isNotBlank(alias)) {
return alias;
}
return aggregateExpression.getFunctionName() + ALIAS_SEPARATOR + identifierAliasProvider.getAlias(containingIdentifier);
}
use of org.hypertrace.entity.query.service.v1.Function in project entity-service by hypertrace.
the class EntityQueryServiceImpl method buildMetadataForSelections.
private ResultSetMetadata buildMetadataForSelections(List<Expression> selections) throws ConversionException {
final AliasProvider<ColumnIdentifier> identifierAliasProvider = getIdentifierAliasProvider();
final AliasProvider<Function> aggregateExpressionAliasProvider = getAggregateExpressionAliasProvider();
final List<ColumnMetadata> list = new ArrayList<>();
for (final Expression selection : selections) {
final String columnName;
if (selection.hasFunction()) {
columnName = aggregateExpressionAliasProvider.getAlias(selection.getFunction());
} else if (selection.hasColumnIdentifier()) {
columnName = identifierAliasProvider.getAlias(selection.getColumnIdentifier());
} else {
throw new ConversionException(String.format("Selection of non-identifier and non-aggregation is not supported. Found: %s", selection));
}
ColumnMetadata build = ColumnMetadata.newBuilder().setColumnName(columnName).build();
list.add(build);
}
return ResultSetMetadata.newBuilder().addAllColumnMetadata(list).build();
}
use of org.hypertrace.entity.query.service.v1.Function in project entity-service by hypertrace.
the class AggregateExpressionConverter method convert.
@Override
public AggregateExpression convert(final Function aggregateExpression, final RequestContext requestContext) throws ConversionException {
final AggregationOperator operator = OPERATOR_MAP.get().get(aggregateExpression.getFunctionName());
if (operator == null) {
throw new ConversionException(String.format("Operator not found for: %s", aggregateExpression));
}
final List<Expression> innerExpressions = aggregateExpression.getArgumentsList();
if (innerExpressions.size() != 1) {
throw new ConversionException("Aggregation function should have exactly one argument");
}
final Expression innerExpression = innerExpressions.get(0);
final ColumnIdentifier containingIdentifier = expressionAccessor.access(innerExpression, innerExpression.getValueCase(), Set.of(COLUMNIDENTIFIER));
final IdentifierExpression identifierExpression = identifierExpressionConverter.convert(containingIdentifier, requestContext);
return AggregateExpression.of(operator, identifierExpression);
}
Aggregations