use of com.facebook.presto.druid.DruidAggregationColumnNode.GroupByColumnNode in project presto by prestodb.
the class DruidPushdownUtils method computeAggregationNodes.
public static List<DruidAggregationColumnNode> computeAggregationNodes(AggregationNode aggregationNode) {
int groupByKeyIndex = 0;
ImmutableList.Builder<DruidAggregationColumnNode> nodeBuilder = ImmutableList.builder();
for (VariableReferenceExpression outputColumn : aggregationNode.getOutputVariables()) {
AggregationNode.Aggregation aggregation = aggregationNode.getAggregations().get(outputColumn);
if (aggregation != null) {
if (aggregation.getFilter().isPresent() || aggregation.isDistinct() || aggregation.getOrderBy().isPresent()) {
throw new PrestoException(DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION, "Unsupported aggregation node " + aggregationNode);
}
if (aggregation.getMask().isPresent()) {
// E.g. `SELECT count(distinct COL_A), sum(COL_B) FROM myTable` to Druid as `SELECT distinctCount(COL_A), sum(COL_B) FROM myTable`
if (aggregation.getCall().getDisplayName().equalsIgnoreCase(COUNT_FUNCTION_NAME) && aggregation.getMask().get().getName().equalsIgnoreCase(aggregation.getArguments().get(0) + DISTINCT_MASK)) {
nodeBuilder.add(new AggregationFunctionColumnNode(outputColumn, new CallExpression(aggregation.getCall().getSourceLocation(), DRUID_COUNT_DISTINCT_FUNCTION_NAME, aggregation.getCall().getFunctionHandle(), aggregation.getCall().getType(), aggregation.getCall().getArguments())));
continue;
}
// Druid doesn't support push down aggregation functions other than count on top of distinct function.
throw new PrestoException(DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION, "Unsupported aggregation node with mask " + aggregationNode);
}
if (handlePushDownSingleDistinctCount(nodeBuilder, aggregationNode, outputColumn, aggregation)) {
continue;
}
nodeBuilder.add(new AggregationFunctionColumnNode(outputColumn, aggregation.getCall()));
} else {
// group by output
VariableReferenceExpression inputColumn = aggregationNode.getGroupingKeys().get(groupByKeyIndex);
nodeBuilder.add(new GroupByColumnNode(inputColumn, outputColumn));
groupByKeyIndex++;
}
}
return nodeBuilder.build();
}
Aggregations