use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class TDigestSketchToQuantilePostAggregatorTest method testToString.
@Test
public void testToString() {
PostAggregator postAgg = new TDigestSketchToQuantilePostAggregator("post", new ConstantPostAggregator("", 100), 0.5);
Assert.assertEquals("TDigestSketchToQuantilePostAggregator{name='post', field=ConstantPostAggregator{name='', constantValue=100}, fraction=0.5}", postAgg.toString());
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class DoublesSketchListArgBaseOperatorConversion method toPostAggregator.
@Nullable
@Override
public PostAggregator toPostAggregator(PlannerContext plannerContext, RowSignature rowSignature, RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) {
final List<RexNode> operands = ((RexCall) rexNode).getOperands();
final double[] args = new double[operands.size() - 1];
PostAggregator inputSketchPostAgg = null;
int operandCounter = 0;
for (RexNode operand : operands) {
final PostAggregator convertedPostAgg = OperatorConversions.toPostAggregator(plannerContext, rowSignature, operand, postAggregatorVisitor);
if (convertedPostAgg == null) {
if (operandCounter > 0) {
try {
if (!operand.isA(SqlKind.LITERAL)) {
return null;
}
double arg = ((Number) RexLiteral.value(operand)).doubleValue();
args[operandCounter - 1] = arg;
} catch (ClassCastException cce) {
return null;
}
} else {
return null;
}
} else {
if (operandCounter == 0) {
inputSketchPostAgg = convertedPostAgg;
} else {
if (!operand.isA(SqlKind.LITERAL)) {
return null;
}
}
}
operandCounter++;
}
if (inputSketchPostAgg == null) {
return null;
}
return makePostAgg(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), inputSketchPostAgg, args);
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class DoublesSketchSingleArgBaseOperatorConversion 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;
}
if (!operands.get(1).isA(SqlKind.LITERAL)) {
return null;
}
final float arg = ((Number) RexLiteral.value(operands.get(1))).floatValue();
return makePostAgg(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), firstOperand, arg);
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class DoublesSketchToHistogramPostAggregatorTest method emptySketch.
@Test
public void emptySketch() {
final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(null);
final Aggregator agg = new DoublesSketchBuildAggregator(selector, 8);
final Map<String, Object> fields = new HashMap<>();
fields.put("sketch", agg.get());
final PostAggregator postAgg = new DoublesSketchToHistogramPostAggregator("histogram", new FieldAccessPostAggregator("field", "sketch"), new double[] { 3.5 }, null);
final double[] histogram = (double[]) postAgg.compute(fields);
Assert.assertNotNull(histogram);
Assert.assertEquals(2, histogram.length);
Assert.assertTrue(Double.isNaN(histogram[0]));
Assert.assertTrue(Double.isNaN(histogram[1]));
}
use of org.apache.druid.query.aggregation.PostAggregator in project druid by druid-io.
the class DoublesSketchToHistogramPostAggregatorTest method testToString.
@Test
public void testToString() {
final PostAggregator postAgg = new DoublesSketchToHistogramPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"), new double[] { 0.25, 0.75 }, null);
Assert.assertEquals("DoublesSketchToHistogramPostAggregator{name='post', field=FieldAccessPostAggregator{name='field1', fieldName='sketch'}, splitPoints=[0.25, 0.75], numBins=null}", postAgg.toString());
}
Aggregations