Search in sources :

Example 6 with LikeDimFilter

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

the class CalciteJoinQueryTest method testUsingSubqueryAsPartOfOrFilter.

@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testUsingSubqueryAsPartOfOrFilter(Map<String, Object> queryContext) throws Exception {
    // Cannot vectorize JOIN operator.
    cannotVectorize();
    testQuery("SELECT dim1, dim2, COUNT(*) FROM druid.foo\n" + "WHERE dim1 = 'xxx' OR dim2 IN (SELECT dim1 FROM druid.foo WHERE dim1 LIKE '%bc')\n" + "group by dim1, dim2 ORDER BY dim2", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(join(new TableDataSource(CalciteTests.DATASOURCE1), new QueryDataSource(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).filters(new LikeDimFilter("dim1", "%bc", null, null)).granularity(Granularities.ALL).aggregators(new CountAggregatorFactory("a0")).context(QUERY_CONTEXT_DEFAULT).build()), "j0.", "1", JoinType.INNER), new QueryDataSource(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "1", ColumnType.LONG)).setDimFilter(new LikeDimFilter("dim1", "%bc", null, null)).setDimensions(dimensions(new DefaultDimensionSpec("dim1", "d0"), new DefaultDimensionSpec("v0", "d1", ColumnType.LONG))).setContext(queryContext).build()), "_j0.", equalsCondition(makeColumnExpression("dim2"), makeColumnExpression("_j0.d0")), JoinType.LEFT)).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(or(selector("dim1", "xxx", null), and(not(selector("j0.a0", "0", null)), not(selector("_j0.d1", null, null)), not(selector("dim2", null, null))))).setDimensions(dimensions(new DefaultDimensionSpec("dim1", "d0"), new DefaultDimensionSpec("dim2", "d1"))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("a0"))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("d1", OrderByColumnSpec.Direction.ASCENDING)), Integer.MAX_VALUE)).setContext(queryContext).build()), ImmutableList.of(new Object[] { "def", "abc", 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) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LikeDimFilter(org.apache.druid.query.filter.LikeDimFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

LikeDimFilter (org.apache.druid.query.filter.LikeDimFilter)6 Test (org.junit.Test)5 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)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 Nullable (javax.annotation.Nullable)1 Parameters (junitparams.Parameters)1 RexCall (org.apache.calcite.rex.RexCall)1 RexNode (org.apache.calcite.rex.RexNode)1 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)1 QueryDataSource (org.apache.druid.query.QueryDataSource)1 TableDataSource (org.apache.druid.query.TableDataSource)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)1 Filter (org.apache.druid.query.filter.Filter)1 ListFilteredVirtualColumn (org.apache.druid.segment.virtual.ListFilteredVirtualColumn)1 DruidExpression (org.apache.druid.sql.calcite.expression.DruidExpression)1