use of org.apache.druid.query.aggregation.variance.VarianceAggregatorFactory in project druid by druid-io.
the class VarianceSqlAggregatorTest method testVarianceOrderBy.
@Test
public void testVarianceOrderBy() throws Exception {
List<Object[]> expectedResults = NullHandling.sqlCompatible() ? ImmutableList.of(new Object[] { "a", 0f }, new Object[] { null, 0f }, new Object[] { "", 0f }, new Object[] { "abc", null }) : ImmutableList.of(new Object[] { "a", 0.5f }, new Object[] { "", 0.0033333334f }, new Object[] { "abc", 0f });
testQuery("select dim2, VARIANCE(f1) from druid.numfoo group by 1 order by 2 desc", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE3).setInterval(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("dim2", "_d0")).setAggregatorSpecs(new VarianceAggregatorFactory("a0:agg", "f1", "sample", "float")).setLimitSpec(DefaultLimitSpec.builder().orderBy(new OrderByColumnSpec("a0:agg", OrderByColumnSpec.Direction.DESCENDING, StringComparators.NUMERIC)).build()).setContext(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
use of org.apache.druid.query.aggregation.variance.VarianceAggregatorFactory in project druid by druid-io.
the class VarianceSqlAggregatorTest method testStdDevSamp.
@Test
public void testStdDevSamp() throws Exception {
VarianceAggregatorCollector holder1 = new VarianceAggregatorCollector();
VarianceAggregatorCollector holder2 = new VarianceAggregatorCollector();
VarianceAggregatorCollector holder3 = new VarianceAggregatorCollector();
for (InputRow row : CalciteTests.ROWS1_WITH_NUMERIC_DIMS) {
Object raw1 = row.getRaw("d1");
Object raw2 = row.getRaw("f1");
Object raw3 = row.getRaw("l1");
addToHolder(holder1, raw1);
addToHolder(holder2, raw2);
addToHolder(holder3, raw3);
}
final List<Object[]> expectedResults = ImmutableList.of(new Object[] { Math.sqrt(holder1.getVariance(false)), (float) Math.sqrt(holder2.getVariance(false)), (long) Math.sqrt(holder3.getVariance(false)) });
testQuery("SELECT\n" + "STDDEV_SAMP(d1),\n" + "STDDEV_SAMP(f1),\n" + "STDDEV_SAMP(l1)\n" + "FROM numfoo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new VarianceAggregatorFactory("a0:agg", "d1", "sample", "double"), new VarianceAggregatorFactory("a1:agg", "f1", "sample", "float"), new VarianceAggregatorFactory("a2:agg", "l1", "sample", "long"))).postAggregators(new StandardDeviationPostAggregator("a0", "a0:agg", "sample"), new StandardDeviationPostAggregator("a1", "a1:agg", "sample"), new StandardDeviationPostAggregator("a2", "a2:agg", "sample")).context(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
Aggregations