use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class ApproximateHistogramGroupByQueryTest method testGroupByWithSameNameComplexPostAgg.
@Test(expected = IllegalArgumentException.class)
public void testGroupByWithSameNameComplexPostAgg() {
ApproximateHistogramAggregatorFactory aggFactory = new ApproximateHistogramAggregatorFactory("quantile", "index", 10, 5, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, false);
GroupByQuery query = new GroupByQuery.Builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setGranularity(QueryRunnerTestHelper.ALL_GRAN).setDimensions(new DefaultDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, "marketalias")).setInterval(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).setLimitSpec(new DefaultLimitSpec(Collections.singletonList(new OrderByColumnSpec("marketalias", OrderByColumnSpec.Direction.DESCENDING)), 1)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, aggFactory).setPostAggregatorSpecs(Collections.singletonList(new QuantilePostAggregator("quantile", "quantile", 0.5f))).build();
List<ResultRow> expectedResults = Collections.singletonList(GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970-01-01T00:00:00.000Z", "marketalias", "upfront", "rows", 186L, "quantile", 880.9881f));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "approx-histo");
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class ApproximateHistogramGroupByQueryTest method testGroupByWithApproximateHistogramAgg.
@Test
public void testGroupByWithApproximateHistogramAgg() {
ApproximateHistogramAggregatorFactory aggFactory = new ApproximateHistogramAggregatorFactory("apphisto", "index", 10, 5, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, false);
GroupByQuery query = new GroupByQuery.Builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setGranularity(QueryRunnerTestHelper.ALL_GRAN).setDimensions(new DefaultDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, "marketalias")).setInterval(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).setLimitSpec(new DefaultLimitSpec(Collections.singletonList(new OrderByColumnSpec("marketalias", OrderByColumnSpec.Direction.DESCENDING)), 1)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, aggFactory).setPostAggregatorSpecs(Collections.singletonList(new QuantilePostAggregator("quantile", "apphisto", 0.5f))).build();
List<ResultRow> expectedResults = Collections.singletonList(GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970-01-01T00:00:00.000Z", "marketalias", "upfront", "rows", 186L, "quantile", 880.9881f, "apphisto", new Histogram(new float[] { 214.97299194335938f, 545.9906005859375f, 877.0081787109375f, 1208.0257568359375f, 1539.0433349609375f, 1870.06103515625f }, new double[] { 0.0, 67.53287506103516, 72.22068786621094, 31.984678268432617, 14.261756896972656 })));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "approx-histo");
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class FixedBucketsHistogramGroupByQueryTest method testGroupByWithFixedHistogramAgg.
@Test
public void testGroupByWithFixedHistogramAgg() {
FixedBucketsHistogramAggregatorFactory aggFactory = new FixedBucketsHistogramAggregatorFactory("histo", "index", 10, 0, 2000, FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, false);
GroupByQuery query = new GroupByQuery.Builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setGranularity(QueryRunnerTestHelper.ALL_GRAN).setDimensions(new DefaultDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, "marketalias")).setInterval(QueryRunnerTestHelper.FULL_ON_INTERVAL).setLimitSpec(new DefaultLimitSpec(Collections.singletonList(new OrderByColumnSpec("marketalias", OrderByColumnSpec.Direction.DESCENDING)), 1)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, aggFactory).setPostAggregatorSpecs(Collections.singletonList(new QuantilePostAggregator("quantile", "histo", 0.5f))).build();
List<ResultRow> expectedResults = Collections.singletonList(GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970-01-01T00:00:00.000Z", "marketalias", "upfront", "rows", 186L, "quantile", 969.6969604492188f, "histo", new FixedBucketsHistogram(0, 2000, 10, FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, new long[] { 0, 0, 4, 33, 66, 35, 25, 11, 10, 2 }, 186, 1870.061029, 545.990623, 0, 0, 0).toString()));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "fixed-histo");
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class FixedBucketsHistogramGroupByQueryTest method testGroupByWithSameNameComplexPostAgg.
@Test(expected = IllegalArgumentException.class)
public void testGroupByWithSameNameComplexPostAgg() {
FixedBucketsHistogramAggregatorFactory aggFactory = new FixedBucketsHistogramAggregatorFactory("histo", "index", 10, 0, 2000, FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, false);
GroupByQuery query = new GroupByQuery.Builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setGranularity(QueryRunnerTestHelper.ALL_GRAN).setDimensions(new DefaultDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, "marketalias")).setInterval(QueryRunnerTestHelper.FULL_ON_INTERVAL).setLimitSpec(new DefaultLimitSpec(Collections.singletonList(new OrderByColumnSpec("marketalias", OrderByColumnSpec.Direction.DESCENDING)), 1)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, aggFactory).setPostAggregatorSpecs(Collections.singletonList(new QuantilePostAggregator("quantile", "quantile", 0.5f))).build();
List<ResultRow> expectedResults = Collections.singletonList(GroupByQueryRunnerTestHelper.createExpectedRow(query, "1970-01-01T00:00:00.000Z", "marketalias", "upfront", "rows", 186L, "quantile", 969.6969604492188f));
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "fixed-histo");
}
use of org.apache.druid.query.groupby.orderby.OrderByColumnSpec in project druid by druid-io.
the class LimitedBufferHashGrouperTest method makeGrouperWithOrderBy.
private static LimitedBufferHashGrouper<Integer> makeGrouperWithOrderBy(TestColumnSelectorFactory columnSelectorFactory, String orderByColumn, OrderByColumnSpec.Direction direction) {
final StringComparator stringComparator = "value".equals(orderByColumn) ? StringComparators.LEXICOGRAPHIC : StringComparators.NUMERIC;
final DefaultLimitSpec orderBy = DefaultLimitSpec.builder().orderBy(new OrderByColumnSpec(orderByColumn, direction, stringComparator)).limit(LIMIT).build();
LimitedBufferHashGrouper<Integer> grouper = new LimitedBufferHashGrouper<>(Suppliers.ofInstance(ByteBuffer.allocate(12120)), new GroupByIshKeySerde(orderBy), AggregatorAdapters.factorizeBuffered(columnSelectorFactory, ImmutableList.of(new LongSumAggregatorFactory("valueSum", "value"), new CountAggregatorFactory("count"))), Integer.MAX_VALUE, 0.5f, 2, LIMIT, !orderBy.getColumns().get(0).getDimension().equals("value"));
grouper.init();
return grouper;
}
Aggregations