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 {