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.
This commit is contained in:
Kashif Faraz 2021-11-25 21:10:06 +05:30 committed by GitHub
parent c381cae51b
commit b48f5a576b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -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.Sequence;
import org.apache.druid.java.util.common.guava.Sequences; import org.apache.druid.java.util.common.guava.Sequences;
import org.apache.druid.math.expr.Evals; import org.apache.druid.math.expr.Evals;
import org.apache.druid.query.InlineDataSource;
import org.apache.druid.query.Query; import org.apache.druid.query.Query;
import org.apache.druid.query.QueryToolChest; import org.apache.druid.query.QueryToolChest;
import org.apache.druid.query.planning.DataSourceAnalysis; import org.apache.druid.query.planning.DataSourceAnalysis;
@ -113,7 +114,8 @@ public class NativeQueryMaker implements QueryMaker
{ {
final Query<?> query = druidQuery.getQuery(); final Query<?> query = druidQuery.getQuery();
if (plannerContext.getPlannerConfig().isRequireTimeCondition()) { if (plannerContext.getPlannerConfig().isRequireTimeCondition()
&& !(druidQuery.getDataSource() instanceof InlineDataSource)) {
if (Intervals.ONLY_ETERNITY.equals(findBaseDataSourceIntervals(query))) { if (Intervals.ONLY_ETERNITY.equals(findBaseDataSourceIntervals(query))) {
throw new CannotBuildQueryException( throw new CannotBuildQueryException(
"requireTimeCondition is enabled, all queries must include a filter condition on the __time column" "requireTimeCondition is enabled, all queries must include a filter condition on the __time column"

View File

@ -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 @Test
public void testRequireTimeConditionSimpleQueryNegative() throws Exception public void testRequireTimeConditionSimpleQueryNegative() throws Exception
{ {