Search in sources :

Example 1 with HllSketchUnionPostAggregator

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);
}
Also used : RexCall(org.apache.calcite.rex.RexCall) HllSketchUnionPostAggregator(org.apache.druid.query.aggregation.datasketches.hll.HllSketchUnionPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) ArrayList(java.util.ArrayList) HllSketchUnionPostAggregator(org.apache.druid.query.aggregation.datasketches.hll.HllSketchUnionPostAggregator) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Aggregations

ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 RexCall (org.apache.calcite.rex.RexCall)1 RexNode (org.apache.calcite.rex.RexNode)1 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)1 HllSketchUnionPostAggregator (org.apache.druid.query.aggregation.datasketches.hll.HllSketchUnionPostAggregator)1