use of org.apache.druid.query.filter.NotDimFilter in project druid by druid-io.
the class CalciteJoinQueryTest method testExactTopNOnInnerJoinWithLimit.
@Test
public void testExactTopNOnInnerJoinWithLimit() throws Exception {
// Adjust topN threshold, so that the topN engine keeps only 1 slot for aggregates, which should be enough
// to compute the query with limit 1.
minTopNThreshold = 1;
Map<String, Object> context = new HashMap<>(QUERY_CONTEXT_DEFAULT);
context.put(PlannerConfig.CTX_KEY_USE_APPROXIMATE_TOPN, false);
testQuery("select f1.\"dim4\", sum(\"m1\") from numfoo f1 inner join (\n" + " select \"dim4\" from numfoo where dim4 <> 'a' group by 1\n" + ") f2 on f1.\"dim4\" = f2.\"dim4\" group by 1 limit 1", // turn on exact topN
context, ImmutableList.of(new TopNQueryBuilder().intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).dimension(new DefaultDimensionSpec("dim4", "_d0")).aggregators(new DoubleSumAggregatorFactory("a0", "m1")).metric(new DimensionTopNMetricSpec(null, StringComparators.LEXICOGRAPHIC)).threshold(1).dataSource(JoinDataSource.create(new TableDataSource("numfoo"), new QueryDataSource(GroupByQuery.builder().setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(new NotDimFilter(new SelectorDimFilter("dim4", "a", null))).setDataSource(new TableDataSource("numfoo")).setDimensions(new DefaultDimensionSpec("dim4", "_d0")).setContext(context).build()), "j0.", "(\"dim4\" == \"j0._d0\")", JoinType.INNER, null, ExprMacroTable.nil())).context(context).build()), ImmutableList.of(new Object[] { "b", 15.0 }));
}
use of org.apache.druid.query.filter.NotDimFilter 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 }));
}
use of org.apache.druid.query.filter.NotDimFilter in project druid by druid-io.
the class CalciteJoinQueryTest method testLeftJoinSubqueryWithNullKeyFilter.
@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testLeftJoinSubqueryWithNullKeyFilter(Map<String, Object> queryContext) throws Exception {
// Cannot vectorize due to 'concat' expression.
cannotVectorize();
ScanQuery nullCompatibleModePlan = 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.INNER)).intervals(querySegmentSpec(Filtration.eternity())).columns("dim1", "j0.d0").context(queryContext).build();
ScanQuery nonNullCompatibleModePlan = 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(new NotDimFilter(new SelectorDimFilter("j0.d0", null, null))).context(queryContext).build();
boolean isJoinFilterRewriteEnabled = queryContext.getOrDefault(JOIN_FILTER_REWRITE_ENABLE_KEY, true).toString().equals("true");
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 IS NOT NULL\n", queryContext, ImmutableList.of(NullHandling.sqlCompatible() ? nullCompatibleModePlan : nonNullCompatibleModePlan), NullHandling.sqlCompatible() || !isJoinFilterRewriteEnabled ? ImmutableList.of(new Object[] { "abc", "abc" }) : ImmutableList.of(new Object[] { "10.1", "" }, // this result is incorrect. TODO : fix this result when the JoinFilterAnalyzer bug is fixed
new Object[] { "2", "" }, new Object[] { "1", "" }, new Object[] { "def", "" }, new Object[] { "abc", "abc" }));
}
Aggregations