Search in sources :

Example 26 with LookupDataSource

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

the class CalciteJoinQueryTest method testFilterAndGroupByLookupUsingJoinOperatorAllowNulls.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testFilterAndGroupByLookupUsingJoinOperatorAllowNulls(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT lookyloo.v, COUNT(*)\n" + "FROM foo LEFT JOIN lookup.lookyloo ON foo.dim2 = lookyloo.k\n" + "WHERE lookyloo.v <> 'xa' OR lookyloo.v IS NULL\n" + "GROUP BY lookyloo.v", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(new TableDataSource(CalciteTests.DATASOURCE1), new LookupDataSource("lookyloo"), "j0.", equalsCondition(makeColumnExpression("dim2"), makeColumnExpression("j0.k")), JoinType.LEFT)).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(or(not(selector("j0.v", "xa", null)), selector("j0.v", null, null))).setDimensions(dimensions(new DefaultDimensionSpec("j0.v", "d0"))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setContext(queryContext).build()), ImmutableList.of(new Object[] { NULL_STRING, 3L }, new Object[] { "xabc", 1L }));
}
Also used : GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) 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 27 with LookupDataSource

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

the class CalciteJoinQueryTest method testInnerJoinQueryOfLookup.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testInnerJoinQueryOfLookup(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize the subquery.
    cannotVectorize();
    testQuery("SELECT dim1, dim2, t1.v, t1.v\n" + "FROM foo\n" + "INNER JOIN \n" + "  (SELECT SUBSTRING(k, 1, 1) k, LATEST(v, 10) v FROM lookup.lookyloo GROUP BY 1) t1\n" + "  ON foo.dim2 = t1.k", 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).setDimensions(new ExtractionDimensionSpec("k", "d0", new SubstringDimExtractionFn(0, 1))).setAggregatorSpecs(new StringLastAggregatorFactory("a0", "v", null, 10)).build()), "j0.", equalsCondition(makeColumnExpression("dim2"), makeColumnExpression("j0.d0")), JoinType.INNER)).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "dim2", "j0.a0").context(queryContext).build()), ImmutableList.of(new Object[] { "", "a", "xabc", "xabc" }, new Object[] { "1", "a", "xabc", "xabc" }));
}
Also used : SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) GlobalTableDataSource(org.apache.druid.query.GlobalTableDataSource) TableDataSource(org.apache.druid.query.TableDataSource) QueryDataSource(org.apache.druid.query.QueryDataSource) LookupDataSource(org.apache.druid.query.LookupDataSource) StringLastAggregatorFactory(org.apache.druid.query.aggregation.last.StringLastAggregatorFactory) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

LookupDataSource (org.apache.druid.query.LookupDataSource)27 Test (org.junit.Test)25 Parameters (junitparams.Parameters)19 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)19 TableDataSource (org.apache.druid.query.TableDataSource)19 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)14 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)14 QueryDataSource (org.apache.druid.query.QueryDataSource)12 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)3 DataSource (org.apache.druid.query.DataSource)3 PreJoinableClause (org.apache.druid.query.planning.PreJoinableClause)3 Optional (java.util.Optional)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)2 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)2 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)2 DefaultLimitSpec (org.apache.druid.query.groupby.orderby.DefaultLimitSpec)2 OrderByColumnSpec (org.apache.druid.query.groupby.orderby.OrderByColumnSpec)2 SegmentReference (org.apache.druid.segment.SegmentReference)2 Inject (com.google.inject.Inject)1