use of org.apache.druid.query.aggregation.datasketches.hll.HllSketchUnionPostAggregator in project druid by druid-io.
the class HllSketchSetUnionOperatorConversion method toPostAggregator.
@Nullable
@Override
public PostAggregator toPostAggregator(PlannerContext plannerContext, RowSignature rowSignature, RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) {
final List<RexNode> operands = ((RexCall) rexNode).getOperands();
final List<PostAggregator> inputPostAggs = new ArrayList<>();
Integer lgK = null;
String tgtHllType = null;
int operandCounter = 0;
for (RexNode operand : operands) {
final PostAggregator convertedPostAgg = OperatorConversions.toPostAggregator(plannerContext, rowSignature, operand, postAggregatorVisitor);
if (convertedPostAgg == null) {
if (operandCounter == 0) {
if (!operand.isA(SqlKind.LITERAL)) {
return null;
}
try {
lgK = RexLiteral.intValue(operand);
} catch (ClassCastException re) {
return null;
}
} else if (operandCounter == 1) {
if (!operand.isA(SqlKind.LITERAL)) {
return null;
}
// both lgK and tgtHllType must be specified
if (lgK == null) {
return null;
}
try {
tgtHllType = RexLiteral.stringValue(operand);
} catch (ClassCastException re) {
return null;
}
} else {
return null;
}
} else {
inputPostAggs.add(convertedPostAgg);
operandCounter++;
}
}
return new HllSketchUnionPostAggregator(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), inputPostAggs, lgK, tgtHllType);
}
Aggregations