From b48f5a576b300149e92167e16ecf70b8c6c34b27 Mon Sep 17 00:00:00 2001 From: Kashif Faraz Date: Thu, 25 Nov 2021 21:10:06 +0530 Subject: [PATCH] Fix: Do not require time condition on InlineDataSource (#11982) For queries on logical values, e.g. SELECT 1337, we need not check for a filter on __time column even if requireTimeCondition is true. --- .../sql/calcite/run/NativeQueryMaker.java | 4 +++- .../druid/sql/calcite/CalciteQueryTest.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/run/NativeQueryMaker.java b/sql/src/main/java/org/apache/druid/sql/calcite/run/NativeQueryMaker.java index 3f656d0e16c..d160230b7d7 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/run/NativeQueryMaker.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/run/NativeQueryMaker.java @@ -38,6 +38,7 @@ import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.java.util.common.guava.Sequences; import org.apache.druid.math.expr.Evals; +import org.apache.druid.query.InlineDataSource; import org.apache.druid.query.Query; import org.apache.druid.query.QueryToolChest; import org.apache.druid.query.planning.DataSourceAnalysis; @@ -113,7 +114,8 @@ public class NativeQueryMaker implements QueryMaker { final Query query = druidQuery.getQuery(); - if (plannerContext.getPlannerConfig().isRequireTimeCondition()) { + if (plannerContext.getPlannerConfig().isRequireTimeCondition() + && !(druidQuery.getDataSource() instanceof InlineDataSource)) { if (Intervals.ONLY_ETERNITY.equals(findBaseDataSourceIntervals(query))) { throw new CannotBuildQueryException( "requireTimeCondition is enabled, all queries must include a filter condition on the __time column" diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java index e2b0a24e429..c0736ccf694 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java @@ -11335,6 +11335,29 @@ public class CalciteQueryTest extends BaseCalciteQueryTest ); } + @Test + public void testRequireTimeConditionLogicalValuePositive() throws Exception + { + testQuery( + PLANNER_CONFIG_REQUIRE_TIME_CONDITION, + "SELECT 2 + 2 AS a", + CalciteTests.REGULAR_USER_AUTH_RESULT, + ImmutableList.of( + newScanQueryBuilder() + .dataSource(InlineDataSource.fromIterable( + ImmutableList.of(new Object[]{4L}), + RowSignature.builder().add("a", ColumnType.LONG).build() + )) + .columns("a") + .intervals(querySegmentSpec(Filtration.eternity())) + .resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST) + .context(QUERY_CONTEXT_DEFAULT) + .build() + ), + ImmutableList.of(new Object[]{4}) + ); + } + @Test public void testRequireTimeConditionSimpleQueryNegative() throws Exception {