Search in sources :

Example 91 with FieldAccessPostAggregator

use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.

the class TopNQueryTest method testGetRequiredColumns.

@Test
public void testGetRequiredColumns() {
    final TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).virtualColumns(new ExpressionVirtualColumn("v", "\"other\"", ColumnType.STRING, ExprMacroTable.nil())).dimension(DefaultDimensionSpec.of("v")).aggregators(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).granularity(QueryRunnerTestHelper.DAY_GRAN).postAggregators(ImmutableList.of(new FieldAccessPostAggregator("x", "idx"))).metric(new NumericTopNMetricSpec("idx")).threshold(100).build();
    Assert.assertEquals(ImmutableSet.of("__time", "other", "index"), query.getRequiredColumns());
}
Also used : ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) Test(org.junit.Test)

Example 92 with FieldAccessPostAggregator

use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.

the class DoublesSketchToHistogramPostAggregatorTest method testSerde.

@Test
public void testSerde() throws JsonProcessingException {
    final PostAggregator there = new DoublesSketchToHistogramPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"), new double[] { 0.25, 0.75 }, null);
    DefaultObjectMapper mapper = new DefaultObjectMapper();
    DoublesSketchToHistogramPostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), DoublesSketchToHistogramPostAggregator.class);
    Assert.assertEquals(there, andBackAgain);
    Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 93 with FieldAccessPostAggregator

use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.

the class DoublesSketchToHistogramPostAggregatorTest method splitPoints.

@Test
public void splitPoints() {
    final double[] values = new double[] { 1, 2, 3, 4, 5, 6 };
    final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(values);
    final Aggregator agg = new DoublesSketchBuildAggregator(selector, 8);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < values.length; i++) {
        agg.aggregate();
        selector.increment();
    }
    final Map<String, Object> fields = new HashMap<>();
    fields.put("sketch", agg.get());
    final PostAggregator postAgg = new DoublesSketchToHistogramPostAggregator("histogram", new FieldAccessPostAggregator("field", "sketch"), // splits distribution into two bins of equal mass
    new double[] { 3.5 }, null);
    final double[] histogram = (double[]) postAgg.compute(fields);
    Assert.assertNotNull(histogram);
    Assert.assertEquals(2, histogram.length);
    Assert.assertEquals(3.0, histogram[0], 0);
    Assert.assertEquals(3.0, histogram[1], 0);
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) HashMap(java.util.HashMap) Aggregator(org.apache.druid.query.aggregation.Aggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) TestDoubleColumnSelectorImpl(org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl) Test(org.junit.Test)

Example 94 with FieldAccessPostAggregator

use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.

the class DoublesSketchToHistogramPostAggregatorTest method numBins.

@Test
public void numBins() {
    final double[] values = new double[] { 1, 2, 3, 4, 5, 6 };
    final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(values);
    final Aggregator agg = new DoublesSketchBuildAggregator(selector, 8);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < values.length; i++) {
        agg.aggregate();
        selector.increment();
    }
    final Map<String, Object> fields = new HashMap<>();
    fields.put("sketch", agg.get());
    final PostAggregator postAgg = new DoublesSketchToHistogramPostAggregator("histogram", new FieldAccessPostAggregator("field", "sketch"), null, // two bins of equal mass
    2);
    final double[] histogram = (double[]) postAgg.compute(fields);
    Assert.assertNotNull(histogram);
    Assert.assertEquals(2, histogram.length);
    Assert.assertEquals(3.0, histogram[0], 0);
    Assert.assertEquals(3.0, histogram[1], 0);
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) HashMap(java.util.HashMap) Aggregator(org.apache.druid.query.aggregation.Aggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) TestDoubleColumnSelectorImpl(org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl) Test(org.junit.Test)

Example 95 with FieldAccessPostAggregator

use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.

the class DoublesSketchToQuantilesPostAggregatorTest method normalCase.

@Test
public void normalCase() {
    final double[] values = new double[] { 1, 2, 3, 4, 5 };
    final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(values);
    final Aggregator agg = new DoublesSketchBuildAggregator(selector, 8);
    // noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < values.length; i++) {
        agg.aggregate();
        selector.increment();
    }
    final Map<String, Object> fields = new HashMap<>();
    fields.put("sketch", agg.get());
    final PostAggregator postAgg = new DoublesSketchToQuantilesPostAggregator("quantiles", new FieldAccessPostAggregator("field", "sketch"), new double[] { 0, 0.5, 1 });
    final double[] quantiles = (double[]) postAgg.compute(fields);
    Assert.assertNotNull(quantiles);
    Assert.assertEquals(3, quantiles.length);
    Assert.assertEquals(1.0, quantiles[0], 0);
    Assert.assertEquals(3.0, quantiles[1], 0);
    Assert.assertEquals(5.0, quantiles[2], 0);
}
Also used : FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) HashMap(java.util.HashMap) Aggregator(org.apache.druid.query.aggregation.Aggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) TestDoubleColumnSelectorImpl(org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl) Test(org.junit.Test)

Aggregations

FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)108 Test (org.junit.Test)97 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)45 ArithmeticPostAggregator (org.apache.druid.query.aggregation.post.ArithmeticPostAggregator)32 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)30 FinalizingFieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator)24 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)22 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)22 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)17 TimeseriesQueryQueryToolChest (org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest)17 ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)15 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)15 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)14 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)12 HashMap (java.util.HashMap)11 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)11 QueryDataSource (org.apache.druid.query.QueryDataSource)10 Aggregator (org.apache.druid.query.aggregation.Aggregator)10 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)10 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)10