Search in sources :

Example 1 with LongLastAggregatorFactory

use of org.apache.druid.query.aggregation.last.LongLastAggregatorFactory in project druid by druid-io.

the class CalciteQueryTest method testGroupByAggregatorDefaultValuesNonVectorized.

@Test
public void testGroupByAggregatorDefaultValuesNonVectorized() throws Exception {
    cannotVectorize();
    testQuery("SELECT\n" + " dim2,\n" + " ANY_VALUE(dim1, 1024) FILTER(WHERE dim1 = 'nonexistent'),\n" + " ANY_VALUE(l1) FILTER(WHERE dim1 = 'nonexistent'),\n" + " EARLIEST(dim1, 1024) FILTER(WHERE dim1 = 'nonexistent'),\n" + " EARLIEST(l1) FILTER(WHERE dim1 = 'nonexistent'),\n" + " LATEST(dim1, 1024) FILTER(WHERE dim1 = 'nonexistent'),\n" + " LATEST(l1) FILTER(WHERE dim1 = 'nonexistent'),\n" + " ARRAY_AGG(DISTINCT dim3) FILTER(WHERE dim1 = 'nonexistent'),\n" + " STRING_AGG(DISTINCT dim3, '|') FILTER(WHERE dim1 = 'nonexistent'),\n" + " BIT_AND(l1) FILTER(WHERE dim1 = 'nonexistent'),\n" + " BIT_OR(l1) FILTER(WHERE dim1 = 'nonexistent'),\n" + " BIT_XOR(l1) FILTER(WHERE dim1 = 'nonexistent')\n" + "FROM druid.numfoo WHERE dim2 = 'a' GROUP BY dim2", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE3).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 StringAnyAggregatorFactory("a0", "dim1", 1024), selector("dim1", "nonexistent", null)), new FilteredAggregatorFactory(new LongAnyAggregatorFactory("a1", "l1"), selector("dim1", "nonexistent", null)), new FilteredAggregatorFactory(new StringFirstAggregatorFactory("a2", "dim1", null, 1024), selector("dim1", "nonexistent", null)), new FilteredAggregatorFactory(new LongFirstAggregatorFactory("a3", "l1", null), selector("dim1", "nonexistent", null)), new FilteredAggregatorFactory(new StringLastAggregatorFactory("a4", "dim1", null, 1024), selector("dim1", "nonexistent", null)), new FilteredAggregatorFactory(new LongLastAggregatorFactory("a5", "l1", null), selector("dim1", "nonexistent", null)), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a6", ImmutableSet.of("dim3"), "__acc", "ARRAY<STRING>[]", "ARRAY<STRING>[]", true, true, false, "array_set_add(\"__acc\", \"dim3\")", "array_set_add_all(\"__acc\", \"a6\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), selector("dim1", "nonexistent", null)), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a7", ImmutableSet.of("dim3"), "__acc", "[]", "[]", true, false, false, "array_set_add(\"__acc\", \"dim3\")", "array_set_add_all(\"__acc\", \"a7\")", null, "if(array_length(o) == 0, null, array_to_string(o, '|'))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), and(not(selector("dim3", null, null)), selector("dim1", "nonexistent", null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a8", ImmutableSet.of("l1"), "__acc", "0", "0", NullHandling.sqlCompatible(), false, false, "bitwiseAnd(\"__acc\", \"l1\")", "bitwiseAnd(\"__acc\", \"a8\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), and(not(selector("l1", null, null)), selector("dim1", "nonexistent", null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a9", ImmutableSet.of("l1"), "__acc", "0", "0", NullHandling.sqlCompatible(), false, false, "bitwiseOr(\"__acc\", \"l1\")", "bitwiseOr(\"__acc\", \"a9\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), and(not(selector("l1", null, null)), selector("dim1", "nonexistent", null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a10", ImmutableSet.of("l1"), "__acc", "0", "0", NullHandling.sqlCompatible(), false, false, "bitwiseXor(\"__acc\", \"l1\")", "bitwiseXor(\"__acc\", \"a10\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), and(not(selector("l1", null, null)), selector("dim1", "nonexistent", null))))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(useDefault ? new Object[] { "a", "", 0L, "", 0L, "", 0L, null, "", 0L, 0L, 0L } : new Object[] { "a", null, null, null, null, null, null, null, null, null, null, null }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) LongLastAggregatorFactory(org.apache.druid.query.aggregation.last.LongLastAggregatorFactory) ExpressionLambdaAggregatorFactory(org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory) LongAnyAggregatorFactory(org.apache.druid.query.aggregation.any.LongAnyAggregatorFactory) StringAnyAggregatorFactory(org.apache.druid.query.aggregation.any.StringAnyAggregatorFactory) StringLastAggregatorFactory(org.apache.druid.query.aggregation.last.StringLastAggregatorFactory) StringFirstAggregatorFactory(org.apache.druid.query.aggregation.first.StringFirstAggregatorFactory) LongFirstAggregatorFactory(org.apache.druid.query.aggregation.first.LongFirstAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 2 with LongLastAggregatorFactory

use of org.apache.druid.query.aggregation.last.LongLastAggregatorFactory in project druid by druid-io.

the class CalciteQueryTest method testFirstLatestAggregatorsSkipNulls.

@Test
public void testFirstLatestAggregatorsSkipNulls() throws Exception {
    // Cannot vectorize LATEST aggregator.
    skipVectorize();
    final DimFilter filter;
    if (useDefault) {
        filter = not(selector("dim1", null, null));
    } else {
        filter = and(not(selector("dim1", null, null)), not(selector("l1", null, null)), not(selector("d1", null, null)), not(selector("f1", null, null)));
    }
    testQuery("SELECT EARLIEST(dim1, 32), LATEST(l1), LATEST(d1), LATEST(f1) " + "FROM druid.numfoo " + "WHERE dim1 IS NOT NULL AND l1 IS NOT NULL AND d1 IS NOT NULL AND f1 is NOT NULL", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).filters(filter).aggregators(aggregators(new StringFirstAggregatorFactory("a0", "dim1", null, 32), new LongLastAggregatorFactory("a1", "l1", null), new DoubleLastAggregatorFactory("a2", "d1", null), new FloatLastAggregatorFactory("a3", "f1", null))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(// first row of dim1 is empty string, which is null in default mode, last non-null numeric rows are zeros
    new Object[] { useDefault ? "10.1" : "", 0L, 0.0, 0.0f }));
}
Also used : LongLastAggregatorFactory(org.apache.druid.query.aggregation.last.LongLastAggregatorFactory) DoubleLastAggregatorFactory(org.apache.druid.query.aggregation.last.DoubleLastAggregatorFactory) FloatLastAggregatorFactory(org.apache.druid.query.aggregation.last.FloatLastAggregatorFactory) StringFirstAggregatorFactory(org.apache.druid.query.aggregation.first.StringFirstAggregatorFactory) RegexDimFilter(org.apache.druid.query.filter.RegexDimFilter) DimFilter(org.apache.druid.query.filter.DimFilter) InDimFilter(org.apache.druid.query.filter.InDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) LikeDimFilter(org.apache.druid.query.filter.LikeDimFilter) Test(org.junit.Test)

Example 3 with LongLastAggregatorFactory

use of org.apache.druid.query.aggregation.last.LongLastAggregatorFactory in project druid by druid-io.

the class CalciteQueryTest method testTimeseriesEmptyResultsAggregatorDefaultValuesNonVectorized.

@Test
public void testTimeseriesEmptyResultsAggregatorDefaultValuesNonVectorized() throws Exception {
    cannotVectorize();
    // timeseries with all granularity have a single group, so should return default results for given aggregators
    testQuery("SELECT\n" + " ANY_VALUE(dim1, 1024),\n" + " ANY_VALUE(l1),\n" + " EARLIEST(dim1, 1024),\n" + " EARLIEST(l1),\n" + " LATEST(dim1, 1024),\n" + " LATEST(l1),\n" + " ARRAY_AGG(DISTINCT dim3),\n" + " STRING_AGG(DISTINCT dim3, '|'),\n" + " BIT_AND(l1),\n" + " BIT_OR(l1),\n" + " BIT_XOR(l1)\n" + "FROM druid.numfoo WHERE dim2 = 0", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).filters(bound("dim2", "0", "0", false, false, null, StringComparators.NUMERIC)).granularity(Granularities.ALL).aggregators(aggregators(new StringAnyAggregatorFactory("a0", "dim1", 1024), new LongAnyAggregatorFactory("a1", "l1"), new StringFirstAggregatorFactory("a2", "dim1", null, 1024), new LongFirstAggregatorFactory("a3", "l1", null), new StringLastAggregatorFactory("a4", "dim1", null, 1024), new LongLastAggregatorFactory("a5", "l1", null), new ExpressionLambdaAggregatorFactory("a6", ImmutableSet.of("dim3"), "__acc", "ARRAY<STRING>[]", "ARRAY<STRING>[]", true, true, false, "array_set_add(\"__acc\", \"dim3\")", "array_set_add_all(\"__acc\", \"a6\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a7", ImmutableSet.of("dim3"), "__acc", "[]", "[]", true, false, false, "array_set_add(\"__acc\", \"dim3\")", "array_set_add_all(\"__acc\", \"a7\")", null, "if(array_length(o) == 0, null, array_to_string(o, '|'))", ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("dim3", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a8", ImmutableSet.of("l1"), "__acc", "0", "0", NullHandling.sqlCompatible(), false, false, "bitwiseAnd(\"__acc\", \"l1\")", "bitwiseAnd(\"__acc\", \"a8\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("l1", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a9", ImmutableSet.of("l1"), "__acc", "0", "0", NullHandling.sqlCompatible(), false, false, "bitwiseOr(\"__acc\", \"l1\")", "bitwiseOr(\"__acc\", \"a9\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("l1", null, null))), new FilteredAggregatorFactory(new ExpressionLambdaAggregatorFactory("a10", ImmutableSet.of("l1"), "__acc", "0", "0", NullHandling.sqlCompatible(), false, false, "bitwiseXor(\"__acc\", \"l1\")", "bitwiseXor(\"__acc\", \"a10\")", null, null, ExpressionLambdaAggregatorFactory.DEFAULT_MAX_SIZE_BYTES, TestExprMacroTable.INSTANCE), not(selector("l1", null, null))))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(useDefault ? new Object[] { "", 0L, "", 0L, "", 0L, null, "", 0L, 0L, 0L } : new Object[] { null, null, null, null, null, null, null, null, null, null, null }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) LongLastAggregatorFactory(org.apache.druid.query.aggregation.last.LongLastAggregatorFactory) ExpressionLambdaAggregatorFactory(org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory) LongAnyAggregatorFactory(org.apache.druid.query.aggregation.any.LongAnyAggregatorFactory) StringAnyAggregatorFactory(org.apache.druid.query.aggregation.any.StringAnyAggregatorFactory) StringLastAggregatorFactory(org.apache.druid.query.aggregation.last.StringLastAggregatorFactory) StringFirstAggregatorFactory(org.apache.druid.query.aggregation.first.StringFirstAggregatorFactory) LongFirstAggregatorFactory(org.apache.druid.query.aggregation.first.LongFirstAggregatorFactory) Test(org.junit.Test)

Example 4 with LongLastAggregatorFactory

use of org.apache.druid.query.aggregation.last.LongLastAggregatorFactory in project druid by druid-io.

the class CalciteQueryTest method testOrderByLatestLong.

@Test
public void testOrderByLatestLong() throws Exception {
    // Cannot vectorize LATEST aggregator.
    skipVectorize();
    List<Object[]> expected;
    if (NullHandling.replaceWithDefault()) {
        expected = ImmutableList.of(new Object[] { "1", 0L }, new Object[] { "2", 0L }, new Object[] { "abc", 0L }, new Object[] { "def", 0L }, new Object[] { "", 7L }, new Object[] { "10.1", 325323L });
    } else {
        expected = ImmutableList.of(new Object[] { "1", null }, new Object[] { "abc", null }, new Object[] { "def", null }, new Object[] { "2", 0L }, new Object[] { "", 7L }, new Object[] { "10.1", 325323L });
    }
    testQuery("SELECT dim1, LATEST(l1) FROM druid.numfoo GROUP BY 1 ORDER BY 2 LIMIT 10", ImmutableList.of(new TopNQueryBuilder().dataSource(CalciteTests.DATASOURCE3).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).dimension(new DefaultDimensionSpec("dim1", "_d0")).aggregators(aggregators(new LongLastAggregatorFactory("a0", "l1", null))).metric(new InvertedTopNMetricSpec(new NumericTopNMetricSpec("a0"))).threshold(10).context(QUERY_CONTEXT_DEFAULT).build()), expected);
}
Also used : TopNQueryBuilder(org.apache.druid.query.topn.TopNQueryBuilder) LongLastAggregatorFactory(org.apache.druid.query.aggregation.last.LongLastAggregatorFactory) InvertedTopNMetricSpec(org.apache.druid.query.topn.InvertedTopNMetricSpec) NumericTopNMetricSpec(org.apache.druid.query.topn.NumericTopNMetricSpec) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 5 with LongLastAggregatorFactory

use of org.apache.druid.query.aggregation.last.LongLastAggregatorFactory in project druid by druid-io.

the class CalciteQueryTest method testPrimitiveLatestInSubquery.

// This test the off-heap (buffer) version of the LatestAggregator (Double/Float/Long)
@Test
public void testPrimitiveLatestInSubquery() throws Exception {
    // Cannot vectorize LATEST aggregator.
    skipVectorize();
    testQuery("SELECT SUM(val1), SUM(val2), SUM(val3) FROM (SELECT dim2, LATEST(m1) AS val1, LATEST(cnt) AS val2, LATEST(m2) AS val3 FROM foo GROUP BY dim2)", ImmutableList.of(GroupByQuery.builder().setDataSource(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("dim2", "d0"))).setAggregatorSpecs(aggregators(new FloatLastAggregatorFactory("a0:a", "m1", null), new LongLastAggregatorFactory("a1:a", "cnt", null), new DoubleLastAggregatorFactory("a2:a", "m2", null))).setPostAggregatorSpecs(ImmutableList.of(new FinalizingFieldAccessPostAggregator("a0", "a0:a"), new FinalizingFieldAccessPostAggregator("a1", "a1:a"), new FinalizingFieldAccessPostAggregator("a2", "a2:a"))).setContext(QUERY_CONTEXT_DEFAULT).build()).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(aggregators(new DoubleSumAggregatorFactory("_a0", "a0"), new LongSumAggregatorFactory("_a1", "a1"), new DoubleSumAggregatorFactory("_a2", "a2"))).setContext(QUERY_CONTEXT_DEFAULT).build()), NullHandling.sqlCompatible() ? ImmutableList.of(new Object[] { 18.0, 4L, 18.0 }) : ImmutableList.of(new Object[] { 15.0, 3L, 15.0 }));
}
Also used : LongLastAggregatorFactory(org.apache.druid.query.aggregation.last.LongLastAggregatorFactory) DoubleLastAggregatorFactory(org.apache.druid.query.aggregation.last.DoubleLastAggregatorFactory) DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) FloatLastAggregatorFactory(org.apache.druid.query.aggregation.last.FloatLastAggregatorFactory) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) FinalizingFieldAccessPostAggregator(org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Aggregations

LongLastAggregatorFactory (org.apache.druid.query.aggregation.last.LongLastAggregatorFactory)9 Test (org.junit.Test)9 LongFirstAggregatorFactory (org.apache.druid.query.aggregation.first.LongFirstAggregatorFactory)6 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)6 StringFirstAggregatorFactory (org.apache.druid.query.aggregation.first.StringFirstAggregatorFactory)4 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)4 LongAnyAggregatorFactory (org.apache.druid.query.aggregation.any.LongAnyAggregatorFactory)3 StringAnyAggregatorFactory (org.apache.druid.query.aggregation.any.StringAnyAggregatorFactory)3 DoubleLastAggregatorFactory (org.apache.druid.query.aggregation.last.DoubleLastAggregatorFactory)3 FloatLastAggregatorFactory (org.apache.druid.query.aggregation.last.FloatLastAggregatorFactory)3 StringLastAggregatorFactory (org.apache.druid.query.aggregation.last.StringLastAggregatorFactory)3 ExpressionLambdaAggregatorFactory (org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory)2 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)2 FinalizingFieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator)2 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)2 JavaScriptConfig (org.apache.druid.js.JavaScriptConfig)1 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)1 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)1 DoubleAnyAggregatorFactory (org.apache.druid.query.aggregation.any.DoubleAnyAggregatorFactory)1 FloatAnyAggregatorFactory (org.apache.druid.query.aggregation.any.FloatAnyAggregatorFactory)1