Search in sources :

Example 6 with TDigestSketchAggregatorFactory

use of org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory in project druid by druid-io.

the class TDigestSketchSqlAggregatorTest method createQuerySegmentWalker.

@Override
public SpecificSegmentsQuerySegmentWalker createQuerySegmentWalker() throws IOException {
    TDigestSketchModule.registerSerde();
    final QueryableIndex index = IndexBuilder.create(CalciteTests.getJsonMapper()).tmpDir(temporaryFolder.newFolder()).segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()).schema(new IncrementalIndexSchema.Builder().withMetrics(new CountAggregatorFactory("cnt"), new DoubleSumAggregatorFactory("m1", "m1"), new TDigestSketchAggregatorFactory("qsketch_m1", "m1", 128)).withRollup(false).build()).rows(CalciteTests.ROWS1).buildMMappedIndex();
    return new SpecificSegmentsQuerySegmentWalker(conglomerate).add(DataSegment.builder().dataSource(CalciteTests.DATASOURCE1).interval(index.getDataInterval()).version("1").shardSpec(new LinearShardSpec(0)).size(0).build(), index);
}
Also used : TDigestSketchAggregatorFactory(org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) SpecificSegmentsQuerySegmentWalker(org.apache.druid.sql.calcite.util.SpecificSegmentsQuerySegmentWalker) QueryableIndex(org.apache.druid.segment.QueryableIndex) LinearShardSpec(org.apache.druid.timeline.partition.LinearShardSpec) IndexBuilder(org.apache.druid.segment.IndexBuilder)

Example 7 with TDigestSketchAggregatorFactory

use of org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory in project druid by druid-io.

the class TDigestSketchSqlAggregatorTest method testQuantileOnNumericValues.

@Test
public void testQuantileOnNumericValues() throws Exception {
    cannotVectorize();
    final List<Object[]> expectedResults = ImmutableList.of(new Object[] { 1.0, 3.5, 6.0 });
    testQuery("SELECT\n" + "TDIGEST_QUANTILE(m1, 0.0), TDIGEST_QUANTILE(m1, 0.5), TDIGEST_QUANTILE(m1, 1.0)\n" + "FROM foo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new TDigestSketchAggregatorFactory("a0:agg", "m1", null))).postAggregators(new TDigestSketchToQuantilePostAggregator("a0", makeFieldAccessPostAgg("a0:agg"), 0.0f), new TDigestSketchToQuantilePostAggregator("a1", makeFieldAccessPostAgg("a0:agg"), 0.5f), new TDigestSketchToQuantilePostAggregator("a2", makeFieldAccessPostAgg("a0:agg"), 1.0f)).context(QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
Also used : TDigestSketchAggregatorFactory(org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory) TDigestSketchToQuantilePostAggregator(org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchToQuantilePostAggregator) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 8 with TDigestSketchAggregatorFactory

use of org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory in project druid by druid-io.

the class TDigestSketchSqlAggregatorTest method testQuantileOnCastedString.

@Test
public void testQuantileOnCastedString() throws Exception {
    cannotVectorize();
    testQuery("SELECT\n" + "  TDIGEST_QUANTILE(CAST(dim1 AS DOUBLE), 0.0),\n" + "  TDIGEST_QUANTILE(CAST(dim1 AS DOUBLE), 0.5),\n" + "  TDIGEST_QUANTILE(CAST(dim1 AS DOUBLE), 1.0)\n" + "FROM foo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).virtualColumns(new ExpressionVirtualColumn("v0", "CAST(\"dim1\", 'DOUBLE')", ColumnType.FLOAT, ExprMacroTable.nil())).aggregators(new TDigestSketchAggregatorFactory("a0:agg", "v0", 100)).postAggregators(new TDigestSketchToQuantilePostAggregator("a0", new FieldAccessPostAggregator("a0:agg", "a0:agg"), 0.0), new TDigestSketchToQuantilePostAggregator("a1", new FieldAccessPostAggregator("a0:agg", "a0:agg"), 0.5), new TDigestSketchToQuantilePostAggregator("a2", new FieldAccessPostAggregator("a0:agg", "a0:agg"), 1.0)).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(NullHandling.replaceWithDefault() ? new Object[] { 0.0, 0.5, 10.1 } : new Object[] { 1.0, 2.0, 10.1 }));
}
Also used : TDigestSketchAggregatorFactory(org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory) ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) TDigestSketchToQuantilePostAggregator(org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchToQuantilePostAggregator) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 9 with TDigestSketchAggregatorFactory

use of org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory in project druid by druid-io.

the class TDigestSketchSqlAggregatorTest method testGroupByAggregatorDefaultValues.

@Test
public void testGroupByAggregatorDefaultValues() throws Exception {
    cannotVectorize();
    testQuery("SELECT\n" + "dim2,\n" + "TDIGEST_GENERATE_SKETCH(m1) FILTER(WHERE dim1 = 'nonexistent')," + "TDIGEST_QUANTILE(qsketch_m1, 0.1) FILTER(WHERE dim1 = 'nonexistent')" + "FROM foo WHERE dim2 = 'a' GROUP BY dim2", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setDimFilter(selector("dim2", "a", null)).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "'a'", ColumnType.STRING)).setDimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.STRING)).setAggregatorSpecs(aggregators(new FilteredAggregatorFactory(new TDigestSketchAggregatorFactory("a0:agg", "m1", TDigestSketchAggregatorFactory.DEFAULT_COMPRESSION), selector("dim1", "nonexistent", null)), new FilteredAggregatorFactory(new TDigestSketchAggregatorFactory("a1:agg", "qsketch_m1", 100), selector("dim1", "nonexistent", null)))).setPostAggregatorSpecs(ImmutableList.of(new TDigestSketchToQuantilePostAggregator("a1", makeFieldAccessPostAgg("a1:agg"), 0.1f))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { "a", "\"AAAAAX/wAAAAAAAA//AAAAAAAABAWQAAAAAAAAAAAAA=\"", Double.NaN }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) TDigestSketchAggregatorFactory(org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory) TDigestSketchToQuantilePostAggregator(org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchToQuantilePostAggregator) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 10 with TDigestSketchAggregatorFactory

use of org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory in project druid by druid-io.

the class TDigestSketchSqlAggregatorTest method testComputingSketchOnNumericValues.

@Test
public void testComputingSketchOnNumericValues() throws Exception {
    cannotVectorize();
    testQuery("SELECT\n" + "TDIGEST_GENERATE_SKETCH(m1, 200)" + "FROM foo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new TDigestSketchAggregatorFactory("a0:agg", "m1", 200))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new String[] { "\"AAAAAT/wAAAAAAAAQBgAAAAAAABAaQAAAAAAAAAAAAY/8AAAAAAAAD/wAAAAAAAAP/AAAAAAAABAAAAAAAAAAD/wAAAAAAAAQAgAAAAAAAA/8AAAAAAAAEAQAAAAAAAAP/AAAAAAAABAFAAAAAAAAD/wAAAAAAAAQBgAAAAAAAA=\"" }));
}
Also used : TDigestSketchAggregatorFactory(org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Aggregations

TDigestSketchAggregatorFactory (org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory)12 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)9 Test (org.junit.Test)9 TDigestSketchToQuantilePostAggregator (org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchToQuantilePostAggregator)8 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)7 Nullable (javax.annotation.Nullable)2 RexNode (org.apache.calcite.rex.RexNode)2 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)2 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)2 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)2 Aggregation (org.apache.druid.sql.calcite.aggregation.Aggregation)2 DruidExpression (org.apache.druid.sql.calcite.expression.DruidExpression)2 QueryDataSource (org.apache.druid.query.QueryDataSource)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)1 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)1 IndexBuilder (org.apache.druid.segment.IndexBuilder)1 QueryableIndex (org.apache.druid.segment.QueryableIndex)1 ExpressionVirtualColumn (org.apache.druid.segment.virtual.ExpressionVirtualColumn)1 SpecificSegmentsQuerySegmentWalker (org.apache.druid.sql.calcite.util.SpecificSegmentsQuerySegmentWalker)1