Search in sources :

Example 6 with LongMinAggregatorFactory

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

the class CalciteJoinQueryTest method testSemiAndAntiJoinSimultaneouslyUsingWhereInSubquery.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testSemiAndAntiJoinSimultaneouslyUsingWhereInSubquery(Map<String, Object> queryContext) throws Exception {
    cannotVectorize();
    testQuery("SELECT dim1, COUNT(*) FROM foo\n" + "WHERE dim1 IN ('abc', 'def')\n" + "AND __time IN (SELECT MAX(__time) FROM foo)\n" + "AND __time NOT IN (SELECT MIN(__time) FROM foo)\n" + "GROUP BY 1", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(join(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(new LongMaxAggregatorFactory("a0", "__time")).context(QUERY_CONTEXT_DEFAULT).build()), "j0.", "(\"__time\" == \"j0.a0\")", JoinType.INNER), new QueryDataSource(GroupByQuery.builder().setDataSource(new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(new LongMinAggregatorFactory("a0", "__time")).context(QUERY_CONTEXT_DEFAULT).build())).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(new CountAggregatorFactory("_a0"), NullHandling.sqlCompatible() ? new FilteredAggregatorFactory(new CountAggregatorFactory("_a1"), not(selector("a0", null, null))) : new CountAggregatorFactory("_a1")).setContext(QUERY_CONTEXT_DEFAULT).build()), "_j0.", "1", JoinType.INNER), new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(new LongMinAggregatorFactory("a0", "__time")).postAggregators(expressionPostAgg("p0", "1")).context(QUERY_CONTEXT_DEFAULT).build()), "__j0.", "(\"__time\" == \"__j0.a0\")", JoinType.LEFT)).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(and(in("dim1", ImmutableList.of("abc", "def"), null), or(selector("_j0._a0", "0", null), and(selector("__j0.p0", null, null), expressionFilter("(\"_j0._a1\" >= \"_j0._a0\")"))))).setDimensions(dimensions(new DefaultDimensionSpec("dim1", "d0", ColumnType.STRING))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(queryContext).build()), ImmutableList.of(new Object[] { "abc", 1L }));
}
Also used : FilteredAggregatorFactory(org.apache.druid.query.aggregation.FilteredAggregatorFactory) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) LongMaxAggregatorFactory(org.apache.druid.query.aggregation.LongMaxAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) LongMinAggregatorFactory(org.apache.druid.query.aggregation.LongMinAggregatorFactory) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 7 with LongMinAggregatorFactory

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

the class CalciteJoinQueryTest method testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins(Map<String, Object> queryContext) throws Exception {
    cannotVectorize();
    testQuery("SELECT dim1, COUNT(*) FROM\n" + "foo\n" + "INNER JOIN (SELECT MAX(__time) t FROM foo) t0 on t0.t = foo.__time\n" + "LEFT JOIN (SELECT MIN(__time) t FROM foo) t1 on t1.t = foo.__time\n" + "WHERE dim1 IN ('abc', 'def') AND t1.t is null\n" + "GROUP BY 1", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(new LongMaxAggregatorFactory("a0", "__time")).context(QUERY_CONTEXT_DEFAULT).build()), "j0.", "(\"__time\" == \"j0.a0\")", JoinType.INNER), new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(new LongMinAggregatorFactory("a0", "__time")).context(QUERY_CONTEXT_DEFAULT).build()), "_j0.", "(\"__time\" == \"_j0.a0\")", JoinType.LEFT)).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(and(in("dim1", ImmutableList.of("abc", "def"), null), selector("_j0.a0", null, null))).setDimensions(dimensions(new DefaultDimensionSpec("dim1", "d0", ColumnType.STRING))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(queryContext).build()), ImmutableList.of(new Object[] { "abc", 1L }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) LongMaxAggregatorFactory(org.apache.druid.query.aggregation.LongMaxAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) LongMinAggregatorFactory(org.apache.druid.query.aggregation.LongMinAggregatorFactory) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)7 LongMinAggregatorFactory (org.apache.druid.query.aggregation.LongMinAggregatorFactory)7 Test (org.junit.Test)6 QueryDataSource (org.apache.druid.query.QueryDataSource)5 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)5 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)4 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)4 Parameters (junitparams.Parameters)3 LongMaxAggregatorFactory (org.apache.druid.query.aggregation.LongMaxAggregatorFactory)3 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)2 TableDataSource (org.apache.druid.query.TableDataSource)2 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)2 GroupingAggregatorFactory (org.apache.druid.query.aggregation.GroupingAggregatorFactory)2 ISE (org.apache.druid.java.util.common.ISE)1 PeriodGranularity (org.apache.druid.java.util.common.granularity.PeriodGranularity)1 FloatSumAggregatorFactory (org.apache.druid.query.aggregation.FloatSumAggregatorFactory)1 HyperUniquesAggregatorFactory (org.apache.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFactory)1 ArithmeticPostAggregator (org.apache.druid.query.aggregation.post.ArithmeticPostAggregator)1 ExpressionPostAggregator (org.apache.druid.query.aggregation.post.ExpressionPostAggregator)1 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)1