Search in sources :

Example 76 with QueryDataSource

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

the class CalciteJoinQueryTest method testInnerJoinOnTwoInlineDataSourcesWithOuterWhere.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testInnerJoinOnTwoInlineDataSourcesWithOuterWhere(Map<String, Object> queryContext) throws Exception {
    Druids.ScanQueryBuilder baseScanBuilder = newScanQueryBuilder().dataSource(join(new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).filters(new SelectorDimFilter("dim1", "10.1", null)).virtualColumns(expressionVirtualColumn("v0", "\'10.1\'", ColumnType.STRING)).columns(ImmutableList.of("__time", "v0")).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).context(queryContext).build()), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).filters(new SelectorDimFilter("dim1", "10.1", null)).columns(ImmutableList.of("dim1")).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).context(queryContext).build()), "j0.", equalsCondition(makeColumnExpression("v0"), makeColumnExpression("j0.dim1")), JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).virtualColumns(expressionVirtualColumn("_v0", "\'10.1\'", ColumnType.STRING)).columns("__time", "_v0").context(queryContext);
    testQuery("with abc as\n" + "(\n" + "  SELECT dim1, \"__time\", m1 from foo WHERE \"dim1\" = '10.1'\n" + ")\n" + "SELECT t1.dim1, t1.\"__time\" from abc as t1 INNER JOIN abc as t2 on t1.dim1 = t2.dim1 WHERE t1.dim1 = '10.1'\n", queryContext, ImmutableList.of(NullHandling.sqlCompatible() ? baseScanBuilder.build() : baseScanBuilder.filters(new NotDimFilter(new SelectorDimFilter("v0", null, null))).build()), ImmutableList.of(new Object[] { "10.1", 946771200000L }));
}
Also used : NotDimFilter(org.apache.druid.query.filter.NotDimFilter) QueryDataSource(org.apache.druid.query.QueryDataSource) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Druids(org.apache.druid.query.Druids) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 77 with QueryDataSource

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

the class CalciteJoinQueryTest method testLeftJoinRightTableCanBeEmpty.

@Test
public void testLeftJoinRightTableCanBeEmpty() throws Exception {
    // HashJoinSegmentStorageAdapter is not vectorizable
    cannotVectorize();
    final DataSource rightTable;
    if (useDefault) {
        rightTable = InlineDataSource.fromIterable(ImmutableList.of(), RowSignature.builder().add("dim2", ColumnType.STRING).add("m2", ColumnType.DOUBLE).build());
    } else {
        rightTable = new QueryDataSource(Druids.newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).filters(new SelectorDimFilter("m2", null, null)).columns("dim2").legacy(false).build());
    }
    testQuery("SELECT v1.dim2, count(1) " + "FROM (SELECT * FROM foo where m1 > 2) v1 " + "LEFT OUTER JOIN (" + "  select dim2 from (select * from foo where m2 is null)" + ") sm ON v1.dim2 = sm.dim2 " + "group by 1", ImmutableList.of(new GroupByQuery.Builder().setDataSource(JoinDataSource.create(new QueryDataSource(Druids.newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).filters(new BoundDimFilter("m1", "2", null, true, false, null, null, StringComparators.NUMERIC)).columns("dim2").legacy(false).build()), rightTable, "j0.", "(\"dim2\" == \"j0.dim2\")", JoinType.LEFT, null, ExprMacroTable.nil())).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("dim2", "d0", ColumnType.STRING)).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(QUERY_CONTEXT_DEFAULT).build()), useDefault ? ImmutableList.of(new Object[] { "", 2L }, new Object[] { "a", 1L }, new Object[] { "abc", 1L }) : ImmutableList.of(new Object[] { null, 1L }, new Object[] { "", 1L }, new Object[] { "a", 1L }, new Object[] { "abc", 1L }));
}
Also used : GroupByQuery(org.apache.druid.query.groupby.GroupByQuery) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) DataSource(org.apache.druid.query.DataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) JoinDataSource(org.apache.druid.query.JoinDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) InlineDataSource(org.apache.druid.query.InlineDataSource) TableDataSource(org.apache.druid.query.TableDataSource) UnionDataSource(org.apache.druid.query.UnionDataSource) Test(org.junit.Test)

Example 78 with QueryDataSource

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

the class CalciteJoinQueryTest method testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess(Map<String, Object> queryContext) throws Exception {
    queryContext = withLeftDirectAccessEnabled(queryContext);
    testQuery("with abc as\n" + "(\n" + "  SELECT dim1, \"__time\", m1 from foo WHERE \"dim1\" = '10.1'\n" + ")\n" + "SELECT t1.dim1, t1.\"__time\" from abc as t1 INNER JOIN abc as t2 on t1.dim1 = t2.dim1\n", queryContext, ImmutableList.of(newScanQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).filters(new SelectorDimFilter("dim1", "10.1", null)).columns(ImmutableList.of("dim1")).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).context(queryContext).build()), "j0.", equalsCondition(makeExpression("'10.1'"), makeColumnExpression("j0.dim1")), JoinType.INNER, selector("dim1", "10.1", null))).intervals(querySegmentSpec(Filtration.eternity())).virtualColumns(expressionVirtualColumn("v0", "\'10.1\'", ColumnType.STRING)).columns("__time", "v0").context(queryContext).build()), ImmutableList.of(new Object[] { "10.1", 946771200000L }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 79 with QueryDataSource

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

the class CalciteJoinQueryTest method testFilterAndGroupByLookupUsingJoinOperatorBackwards.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testFilterAndGroupByLookupUsingJoinOperatorBackwards(Map<String, Object> queryContext) throws Exception {
    // Like "testFilterAndGroupByLookupUsingJoinOperator", but with the table and lookup reversed.
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT lookyloo.v, COUNT(*)\n" + "FROM lookup.lookyloo RIGHT JOIN foo ON foo.dim2 = lookyloo.k\n" + "WHERE lookyloo.v <> 'xa'\n" + "GROUP BY lookyloo.v", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(new LookupDataSource("lookyloo"), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).columns("dim2").context(QUERY_CONTEXT_DEFAULT).build()), "j0.", equalsCondition(makeColumnExpression("k"), makeColumnExpression("j0.dim2")), JoinType.RIGHT)).setInterval(querySegmentSpec(Filtration.eternity())).setDimFilter(not(selector("v", "xa", null))).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("v", "d0"))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(queryContext).build()), ImmutableList.of(new Object[] { NULL_STRING, 3L }, new Object[] { "xabc", 1L }));
}
Also used : QueryDataSource(org.apache.druid.query.QueryDataSource) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) LookupDataSource(org.apache.druid.query.LookupDataSource) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 80 with QueryDataSource

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

the class CalciteJoinQueryTest method testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess(Map<String, Object> queryContext) throws Exception {
    queryContext = withLeftDirectAccessEnabled(queryContext);
    testQuery("with abc as\n" + "(\n" + "  SELECT dim1, \"__time\", m1 from foo WHERE \"dim1\" = '10.1' AND \"__time\" >= '1999'\n" + ")\n" + "SELECT t1.dim1, t1.\"__time\" from abc as t1 LEFT JOIN abc as t2 on t1.dim1 = t2.dim1 WHERE t1.dim1 = '10.1'\n", queryContext, ImmutableList.of(newScanQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Intervals.utc(DateTimes.of("1999-01-01").getMillis(), JodaUtils.MAX_INSTANT))).filters(new SelectorDimFilter("dim1", "10.1", null)).virtualColumns(expressionVirtualColumn("v0", "\'10.1\'", ColumnType.STRING)).columns(ImmutableList.of("v0")).resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST).context(queryContext).build()), "j0.", equalsCondition(makeExpression("'10.1'"), makeColumnExpression("j0.v0")), JoinType.LEFT, selector("dim1", "10.1", null))).intervals(querySegmentSpec(Intervals.utc(DateTimes.of("1999-01-01").getMillis(), JodaUtils.MAX_INSTANT))).virtualColumns(expressionVirtualColumn("v0", "\'10.1\'", ColumnType.STRING)).columns("__time", "v0").context(queryContext).build()), ImmutableList.of(new Object[] { "10.1", 946771200000L }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

QueryDataSource (org.apache.druid.query.QueryDataSource)95 Test (org.junit.Test)81 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)51 TableDataSource (org.apache.druid.query.TableDataSource)44 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)41 Parameters (junitparams.Parameters)30 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)29 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)23 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)14 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)14 LookupDataSource (org.apache.druid.query.LookupDataSource)13 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)11 GroupByQuery (org.apache.druid.query.groupby.GroupByQuery)11 ArithmeticPostAggregator (org.apache.druid.query.aggregation.post.ArithmeticPostAggregator)10 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)10 DataSource (org.apache.druid.query.DataSource)8 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)8 LongMaxAggregatorFactory (org.apache.druid.query.aggregation.LongMaxAggregatorFactory)8 ExpressionVirtualColumn (org.apache.druid.segment.virtual.ExpressionVirtualColumn)8 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)8