use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class HllSketchEstimateOperatorConversion method toPostAggregator.
@Nullable
@Override
public PostAggregator toPostAggregator(PlannerContext plannerContext, RowSignature rowSignature, RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) {
final List<RexNode> operands = ((RexCall) rexNode).getOperands();
final PostAggregator firstOperand = OperatorConversions.toPostAggregator(plannerContext, rowSignature, operands.get(0), postAggregatorVisitor);
if (firstOperand == null) {
return null;
}
boolean round = HllSketchAggregatorFactory.DEFAULT_ROUND;
if (operands.size() == 2) {
if (!operands.get(1).isA(SqlKind.LITERAL)) {
return null;
}
round = RexLiteral.booleanValue(operands.get(1));
}
return new HllSketchToEstimatePostAggregator(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), firstOperand, round);
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class PostAveragerAggregatorCalculator method apply.
@Override
public Row apply(final Row row) {
if (postAveragers.isEmpty()) {
return row;
}
final Map<String, Object> newMap;
newMap = Maps.newLinkedHashMap(((MapBasedRow) row).getEvent());
for (PostAggregator postAverager : postAveragers) {
boolean allColsPresent = postAverager.getDependentFields().stream().allMatch(c -> newMap.get(c) != null);
newMap.put(postAverager.getName(), allColsPresent ? postAverager.compute(newMap) : null);
}
return new MapBasedRow(row.getTimestamp(), newMap);
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class HllSketchUnionPostAggregator method compute.
@Override
public HllSketch compute(final Map<String, Object> combinedAggregators) {
final Union union = new Union(lgK);
for (final PostAggregator field : fields) {
final HllSketch sketch = (HllSketch) field.compute(combinedAggregators);
union.update(sketch);
}
return union.getResult(tgtHllType);
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class HllSketchEstimateWithErrorBoundsOperatorConversion method toPostAggregator.
@Nullable
@Override
public PostAggregator toPostAggregator(PlannerContext plannerContext, RowSignature rowSignature, RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) {
final List<RexNode> operands = ((RexCall) rexNode).getOperands();
final PostAggregator firstOperand = OperatorConversions.toPostAggregator(plannerContext, rowSignature, operands.get(0), postAggregatorVisitor);
if (firstOperand == null) {
return null;
}
Integer numStdDev = null;
if (operands.size() == 2) {
if (!operands.get(1).isA(SqlKind.LITERAL)) {
return null;
}
numStdDev = ((Number) RexLiteral.value(operands.get(1))).intValue();
}
return new HllSketchToEstimateWithBoundsPostAggregator(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), firstOperand, numStdDev);
}
use of org.apache.druid.query.aggregation.PostAggregator 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