Search in sources :

Example 61 with TimeseriesQueryQueryToolChest

use of org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest in project druid by druid-io.

the class SpatialFilterTest method testSpatialQueryMorePoints.

@Test
public void testSpatialQueryMorePoints() {
    TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("test").granularity(Granularities.DAY).intervals(Collections.singletonList(Intervals.of("2013-01-01/2013-01-07"))).filters(new SpatialDimFilter("dim.geo", new RectangularBound(new float[] { 0.0f, 0.0f }, new float[] { 9.0f, 9.0f }))).aggregators(Arrays.asList(new CountAggregatorFactory("rows"), new LongSumAggregatorFactory("val", "val"))).build();
    List<Result<TimeseriesResultValue>> expectedResults = Arrays.asList(new Result<TimeseriesResultValue>(DateTimes.of("2013-01-01T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 1L).put("val", 17L).build())), new Result<TimeseriesResultValue>(DateTimes.of("2013-01-02T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 1L).put("val", 29L).build())), new Result<TimeseriesResultValue>(DateTimes.of("2013-01-03T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 1L).put("val", 13L).build())), new Result<TimeseriesResultValue>(DateTimes.of("2013-01-04T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 1L).put("val", 91L).build())), new Result<TimeseriesResultValue>(DateTimes.of("2013-01-05T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 1L).put("val", 47L).build())));
    try {
        TimeseriesQueryRunnerFactory factory = new TimeseriesQueryRunnerFactory(new TimeseriesQueryQueryToolChest(), new TimeseriesQueryEngine(), QueryRunnerTestHelper.NOOP_QUERYWATCHER);
        QueryRunner runner = new FinalizeResultsQueryRunner(factory.createRunner(segment), factory.getToolchest());
        TestHelper.assertExpectedResults(expectedResults, runner.run(QueryPlus.wrap(query)));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : TimeseriesResultValue(org.apache.druid.query.timeseries.TimeseriesResultValue) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) TimeseriesQueryQueryToolChest(org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest) QueryRunner(org.apache.druid.query.QueryRunner) FinalizeResultsQueryRunner(org.apache.druid.query.FinalizeResultsQueryRunner) IOException(java.io.IOException) RectangularBound(org.apache.druid.collections.spatial.search.RectangularBound) Result(org.apache.druid.query.Result) TimeseriesQueryEngine(org.apache.druid.query.timeseries.TimeseriesQueryEngine) SpatialDimFilter(org.apache.druid.query.filter.SpatialDimFilter) TimeseriesQueryRunnerFactory(org.apache.druid.query.timeseries.TimeseriesQueryRunnerFactory) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) FinalizeResultsQueryRunner(org.apache.druid.query.FinalizeResultsQueryRunner) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 62 with TimeseriesQueryQueryToolChest

use of org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest in project druid by druid-io.

the class IndexMergerV9WithSpatialIndexTest method testSpatialQueryMorePoints.

@Test
public void testSpatialQueryMorePoints() {
    TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("test").granularity(Granularities.DAY).intervals(Collections.singletonList(Intervals.of("2013-01-01/2013-01-07"))).filters(new SpatialDimFilter("dim.geo", new RectangularBound(new float[] { 0.0f, 0.0f }, new float[] { 9.0f, 9.0f }))).aggregators(Arrays.asList(new CountAggregatorFactory("rows"), new LongSumAggregatorFactory("val", "val"))).build();
    List<Result<TimeseriesResultValue>> expectedResults = Arrays.asList(new Result<>(DateTimes.of("2013-01-01T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 1L).put("val", 17L).build())), new Result<>(DateTimes.of("2013-01-02T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 1L).put("val", 29L).build())), new Result<>(DateTimes.of("2013-01-03T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 1L).put("val", 13L).build())), new Result<>(DateTimes.of("2013-01-04T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 1L).put("val", 91L).build())), new Result<>(DateTimes.of("2013-01-05T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 1L).put("val", 47L).build())));
    try {
        TimeseriesQueryRunnerFactory factory = new TimeseriesQueryRunnerFactory(new TimeseriesQueryQueryToolChest(), new TimeseriesQueryEngine(), QueryRunnerTestHelper.NOOP_QUERYWATCHER);
        QueryRunner runner = new FinalizeResultsQueryRunner(factory.createRunner(segment), factory.getToolchest());
        TestHelper.assertExpectedResults(expectedResults, runner.run(QueryPlus.wrap(query)));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : TimeseriesResultValue(org.apache.druid.query.timeseries.TimeseriesResultValue) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) TimeseriesQueryQueryToolChest(org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest) QueryRunner(org.apache.druid.query.QueryRunner) FinalizeResultsQueryRunner(org.apache.druid.query.FinalizeResultsQueryRunner) IOException(java.io.IOException) RectangularBound(org.apache.druid.collections.spatial.search.RectangularBound) Result(org.apache.druid.query.Result) TimeseriesQueryEngine(org.apache.druid.query.timeseries.TimeseriesQueryEngine) SpatialDimFilter(org.apache.druid.query.filter.SpatialDimFilter) TimeseriesQueryRunnerFactory(org.apache.druid.query.timeseries.TimeseriesQueryRunnerFactory) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) FinalizeResultsQueryRunner(org.apache.druid.query.FinalizeResultsQueryRunner) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 63 with TimeseriesQueryQueryToolChest

use of org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest in project druid by druid-io.

the class IndexMergerV9WithSpatialIndexTest method testSpatialQuery.

@Test
public void testSpatialQuery() {
    TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("test").granularity(Granularities.ALL).intervals(Collections.singletonList(Intervals.of("2013-01-01/2013-01-07"))).filters(new SpatialDimFilter("dim.geo", new RadiusBound(new float[] { 0.0f, 0.0f }, 5))).aggregators(Arrays.asList(new CountAggregatorFactory("rows"), new LongSumAggregatorFactory("val", "val"))).build();
    List<Result<TimeseriesResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2013-01-01T00:00:00.000Z"), new TimeseriesResultValue(ImmutableMap.<String, Object>builder().put("rows", 3L).put("val", 59L).build())));
    try {
        TimeseriesQueryRunnerFactory factory = new TimeseriesQueryRunnerFactory(new TimeseriesQueryQueryToolChest(), new TimeseriesQueryEngine(), QueryRunnerTestHelper.NOOP_QUERYWATCHER);
        QueryRunner runner = new FinalizeResultsQueryRunner(factory.createRunner(segment), factory.getToolchest());
        TestHelper.assertExpectedResults(expectedResults, runner.run(QueryPlus.wrap(query)));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : TimeseriesResultValue(org.apache.druid.query.timeseries.TimeseriesResultValue) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) TimeseriesQueryQueryToolChest(org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest) QueryRunner(org.apache.druid.query.QueryRunner) FinalizeResultsQueryRunner(org.apache.druid.query.FinalizeResultsQueryRunner) IOException(java.io.IOException) Result(org.apache.druid.query.Result) TimeseriesQueryEngine(org.apache.druid.query.timeseries.TimeseriesQueryEngine) SpatialDimFilter(org.apache.druid.query.filter.SpatialDimFilter) TimeseriesQueryRunnerFactory(org.apache.druid.query.timeseries.TimeseriesQueryRunnerFactory) RadiusBound(org.apache.druid.collections.spatial.search.RadiusBound) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) FinalizeResultsQueryRunner(org.apache.druid.query.FinalizeResultsQueryRunner) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 64 with TimeseriesQueryQueryToolChest

use of org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest in project druid by druid-io.

the class ArrayOfDoublesSketchToVariancesPostAggregatorTest method testResultArraySignature.

@Test
public void testResultArraySignature() {
    final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2000/3000").granularity(Granularities.HOUR).aggregators(new CountAggregatorFactory("count")).postAggregators(new ArrayOfDoublesSketchToVariancesPostAggregator("a", new ConstantPostAggregator("", 0))).build();
    Assert.assertEquals(RowSignature.builder().addTimeColumn().add("count", ColumnType.LONG).add("a", ColumnType.DOUBLE_ARRAY).build(), new TimeseriesQueryQueryToolChest().resultArraySignature(query));
}
Also used : TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) ConstantPostAggregator(org.apache.druid.query.aggregation.post.ConstantPostAggregator) TimeseriesQueryQueryToolChest(org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest) Test(org.junit.Test)

Example 65 with TimeseriesQueryQueryToolChest

use of org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest in project druid by druid-io.

the class ExpressionLambdaAggregatorFactoryTest method testResultArraySignature.

@Test
public void testResultArraySignature() {
    final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2000/3000").granularity(Granularities.HOUR).aggregators(new ExpressionLambdaAggregatorFactory("string_expr", ImmutableSet.of("some_column", "some_other_column"), null, "''", "''", null, false, false, "concat(__acc, some_column, some_other_column)", "concat(__acc, string_expr)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("double_expr", ImmutableSet.of("some_column", "some_other_column"), null, "0.0", null, null, false, false, "__acc + some_column + some_other_column", "__acc + double_expr", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("long_expr", ImmutableSet.of("some_column", "some_other_column"), null, "0", null, null, false, false, "__acc + some_column + some_other_column", "__acc + long_expr", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("string_array_expr", ImmutableSet.of("some_column", "some_other_column"), null, "ARRAY<STRING>[]", "ARRAY<STRING>[]", null, true, false, "array_set_add(__acc, concat(some_column, some_other_column))", "array_set_add_all(__acc, string_array_expr)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("double_array_expr", ImmutableSet.of("some_column", "some_other_column_expr"), null, "0.0", "ARRAY<DOUBLE>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, double_array)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("long_array_expr", ImmutableSet.of("some_column", "some_other_column"), null, "0", "ARRAY<LONG>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, long_array_expr)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("string_array_expr_finalized", ImmutableSet.of("some_column", "some_other_column"), null, "''", "ARRAY<STRING>[]", null, false, false, "concat(__acc, some_column, some_other_column)", "array_set_add(__acc, string_array_expr)", null, "array_to_string(o, ';')", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("double_array_expr_finalized", ImmutableSet.of("some_column", "some_other_column_expr"), null, "0.0", "ARRAY<DOUBLE>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, double_array)", null, "array_to_string(o, ';')", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("long_array_expr_finalized", ImmutableSet.of("some_column", "some_other_column"), null, "0", "ARRAY<LONG>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, long_array_expr)", null, "fold((x, acc) -> x + acc, o, 0)", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("complex_expr", ImmutableSet.of("some_column"), null, "hyper_unique()", null, null, false, false, "hyper_unique_add(some_column, __acc)", "hyper_unique_add(__acc, expr_agg_name)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("complex_expr_finalized", ImmutableSet.of("some_column"), null, "hyper_unique()", null, null, false, false, "hyper_unique_add(some_column, __acc)", "hyper_unique_add(__acc, expr_agg_name)", null, "hyper_unique_estimate(o)", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE)).postAggregators(new FieldAccessPostAggregator("string-array-expr-access", "string_array_expr_finalized"), new FinalizingFieldAccessPostAggregator("string-array-expr-finalize", "string_array_expr_finalized"), new FieldAccessPostAggregator("double-array-expr-access", "double_array_expr_finalized"), new FinalizingFieldAccessPostAggregator("double-array-expr-finalize", "double_array_expr_finalized"), new FieldAccessPostAggregator("long-array-expr-access", "long_array_expr_finalized"), new FinalizingFieldAccessPostAggregator("long-array-expr-finalize", "long_array_expr_finalized"), new FieldAccessPostAggregator("complex-expr-access", "complex_expr_finalized"), new FinalizingFieldAccessPostAggregator("complex-expr-finalize", "complex_expr_finalized")).build();
    Assert.assertEquals(RowSignature.builder().addTimeColumn().add("string_expr", ColumnType.STRING).add("double_expr", ColumnType.DOUBLE).add("long_expr", ColumnType.LONG).add("string_array_expr", ColumnType.STRING_ARRAY).add("double_array_expr", null).add("long_array_expr", null).add("string_array_expr_finalized", ColumnType.STRING).add("double_array_expr_finalized", null).add("long_array_expr_finalized", ColumnType.LONG).add("complex_expr", HyperUniquesAggregatorFactory.TYPE).add("complex_expr_finalized", null).add("string-array-expr-access", ColumnType.STRING).add("string-array-expr-finalize", ColumnType.STRING).add("double-array-expr-access", ColumnType.DOUBLE).add("double-array-expr-finalize", ColumnType.STRING).add("long-array-expr-access", ColumnType.LONG).add("long-array-expr-finalize", ColumnType.LONG).add("complex-expr-access", HyperUniquesAggregatorFactory.TYPE).add("complex-expr-finalize", ColumnType.DOUBLE).build(), new TimeseriesQueryQueryToolChest().resultArraySignature(query));
}
Also used : FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) FieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FieldAccessPostAggregator) TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) TimeseriesQueryQueryToolChest(org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest) HumanReadableBytes(org.apache.druid.java.util.common.HumanReadableBytes) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

TimeseriesQueryQueryToolChest (org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest)71 TimeseriesQuery (org.apache.druid.query.timeseries.TimeseriesQuery)62 Test (org.junit.Test)62 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)41 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)21 TimeseriesQueryEngine (org.apache.druid.query.timeseries.TimeseriesQueryEngine)20 TimeseriesQueryRunnerFactory (org.apache.druid.query.timeseries.TimeseriesQueryRunnerFactory)20 QueryRunner (org.apache.druid.query.QueryRunner)18 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)18 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)18 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)17 TimeseriesResultValue (org.apache.druid.query.timeseries.TimeseriesResultValue)17 Result (org.apache.druid.query.Result)15 FinalizingFieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator)13 IOException (java.io.IOException)11 Druids (org.apache.druid.query.Druids)10 SpatialDimFilter (org.apache.druid.query.filter.SpatialDimFilter)9 ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)8 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)6 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)6