Search in sources :

Example 11 with TableDataSource

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

the class CalciteJoinQueryTest method testLeftJoinSubqueryWithSelectorFilter.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testLeftJoinSubqueryWithSelectorFilter(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize due to 'concat' expression.
    cannotVectorize();
    // disable the cost model where inner join is treated like a filter
    // this leads to cost(left join) < cost(converted inner join) for the below query
    queryContext = QueryContextForJoinProvider.withOverrides(queryContext, ImmutableMap.of("computeInnerJoinCostAsFilter", "false"));
    testQuery("SELECT dim1, l1.k\n" + "FROM foo\n" + "LEFT JOIN (select k || '' as k from lookup.lookyloo group by 1) l1 ON foo.dim1 = l1.k\n" + "WHERE l1.k = 'abc'\n", queryContext, ImmutableList.of(newScanQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(GroupByQuery.builder().setDataSource(new LookupDataSource("lookyloo")).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "concat(\"k\",'')", ColumnType.STRING)).setDimensions(new DefaultDimensionSpec("v0", "d0")).build()), "j0.", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.d0")), JoinType.LEFT)).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "j0.d0").filters(selector("j0.d0", "abc", null)).context(queryContext).build()), ImmutableList.of(new Object[] { "abc", "abc" }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 12 with TableDataSource

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

the class CalciteJoinQueryTest method testSemiJoinWithOuterTimeExtractAggregateWithOrderBy.

@Test
public void testSemiJoinWithOuterTimeExtractAggregateWithOrderBy() throws Exception {
    // Cannot vectorize due to virtual columns.
    cannotVectorize();
    testQuery("SELECT COUNT(DISTINCT dim1), EXTRACT(MONTH FROM __time) FROM druid.foo\n" + " WHERE dim2 IN (\n" + "   SELECT dim2\n" + "   FROM druid.foo\n" + "   WHERE dim1 = 'def'\n" + " ) AND dim1 <> ''" + "GROUP BY EXTRACT(MONTH FROM __time)\n" + "ORDER BY EXTRACT(MONTH FROM __time)", ImmutableList.of(GroupByQuery.builder().setDataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("dim2", "d0"))).setDimFilter(selector("dim1", "def", null)).setContext(QUERY_CONTEXT_DEFAULT).build()), "j0.", equalsCondition(makeColumnExpression("dim2"), makeColumnExpression("j0.d0")), JoinType.INNER)).setVirtualColumns(expressionVirtualColumn("v0", "timestamp_extract(\"__time\",'MONTH','UTC')", ColumnType.LONG)).setDimFilter(not(selector("dim1", "", null))).setDimensions(dimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.LONG))).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setAggregatorSpecs(aggregators(new CardinalityAggregatorFactory("a0", null, ImmutableList.of(new DefaultDimensionSpec("dim1", "dim1", ColumnType.STRING)), false, true))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("d0", OrderByColumnSpec.Direction.ASCENDING, StringComparators.NUMERIC)), Integer.MAX_VALUE)).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 1L, 1L }));
}
Also used : OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) CardinalityAggregatorFactory(org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 13 with TableDataSource

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

the class CalciteJoinQueryTest method testCountDistinctOfLookupUsingJoinOperator.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testCountDistinctOfLookupUsingJoinOperator(Map<String, Object> queryContext) throws Exception {
    // Cannot yet vectorize the JOIN operator.
    cannotVectorize();
    testQuery("SELECT COUNT(DISTINCT lookyloo.v)\n" + "FROM foo LEFT JOIN lookup.lookyloo ON foo.dim1 = lookyloo.k", queryContext, ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new LookupDataSource("lookyloo"), "j0.", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.k")), JoinType.LEFT)).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).aggregators(aggregators(new CardinalityAggregatorFactory("a0", null, ImmutableList.of(DefaultDimensionSpec.of("j0.v")), false, true))).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { NullHandling.replaceWithDefault() ? 2L : 1L }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) CardinalityAggregatorFactory(org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorFactory) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 14 with TableDataSource

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

the class CalciteJoinQueryTest method testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_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 WHERE t1.dim1 = '10.1'\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 15 with TableDataSource

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

the class CalciteJoinQueryTest method testInnerJoinSubqueryWithSelectorFilter.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testInnerJoinSubqueryWithSelectorFilter(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize due to 'concat' expression.
    cannotVectorize();
    testQuery("SELECT dim1, l1.k " + "FROM foo INNER JOIN (select k || '' as k from lookup.lookyloo group by 1) l1 " + "ON foo.dim1 = l1.k and l1.k = 'abc'", queryContext, ImmutableList.of(newScanQueryBuilder().dataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(GroupByQuery.builder().setDataSource(new LookupDataSource("lookyloo")).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "concat(\"k\",'')", ColumnType.STRING)).setDimensions(new DefaultDimensionSpec("v0", "d0")).build()), "j0.", StringUtils.format("(%s && %s)", equalsCondition(makeColumnExpression("dim1"), makeColumnExpression("j0.d0")), equalsCondition(makeExpression("'abc'"), makeColumnExpression("j0.d0"))), JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "j0.d0").context(queryContext).build()), ImmutableList.of(new Object[] { "abc", "abc" }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

TableDataSource (org.apache.druid.query.TableDataSource)118 Test (org.junit.Test)94 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)46 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)43 QueryDataSource (org.apache.druid.query.QueryDataSource)41 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)40 Parameters (junitparams.Parameters)30 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)19 LookupDataSource (org.apache.druid.query.LookupDataSource)18 DataSegment (org.apache.druid.timeline.DataSegment)15 Result (org.apache.druid.query.Result)14 CountDownLatch (java.util.concurrent.CountDownLatch)11 Query (org.apache.druid.query.Query)11 TimelineObjectHolder (org.apache.druid.timeline.TimelineObjectHolder)11 Interval (org.joda.time.Interval)11 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)10 ArrayList (java.util.ArrayList)9 GroupByQuery (org.apache.druid.query.groupby.GroupByQuery)9 ISE (org.apache.druid.java.util.common.ISE)8 SegmentDescriptor (org.apache.druid.query.SegmentDescriptor)8