Repository navigation
feat: sqlTimeCondition context parameter. #20607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ The table below lists the query context parameters you can use with Druid SQL. | |
| |`sqlReverseLookup`|Whether to consider the [reverse-lookup rewrite](lookups.md#reverse-lookup) of the `LOOKUP` function during SQL planning.<br /><br />Druid reverses calls to `LOOKUP` only when the number of matching keys is lower than both `inSubQueryThreshold` and `sqlReverseLookupThreshold`.|`true`| | ||
| |`sqlReverseLookupThreshold`|Maximum size of `IN` filter to create when applying a [reverse-lookup rewrite](lookups.md#reverse-lookup). If a `LOOKUP` call matches more keys than the specified threshold, it remains unchanged.<br /><br />If `inSubQueryThreshold` is lower than `sqlReverseLookupThreshold`, Druid uses `inSubQueryThreshold` threshold instead.|10000| | ||
| |`sqlPullUpLookup`|Whether to consider the [pull-up rewrite](lookups.md#pull-up) of the `LOOKUP` function during SQL planning.|`true`| | ||
| |`sqlTimeCondition`|Time condition to apply to all tables that the query reads. Provide either a comma-separated string of ISO8601 intervals, such as `"2000-01-01/2000-02-01,2001-01-01/2001-02-01"`, or an array of ISO8601 interval strings. An empty array matches nothing. An empty string is an error.<br /><br />Druid ANDs this condition with any other condition you provide on the `__time` column. Intervals without an explicit offset are in UTC; `sqlTimeZone` doesn't affect them.<br /><br />You can't use this parameter with `INSERT`, `REPLACE`, or [catalog DDL](../development/extensions-core/catalog.md#sql-ddl) statements.|none| | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also wonder how this feature would interplay with the existing @gianm @NishthaShah thoughts?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also want to know if the supporting of ARRAY is needed. SET sqlTimeCondition = ['a/b', 'c/d'];The only case that current simple String type can't express is the empty array case. But I'm not sure under which case we need to support this case,. If this is a must case, I think maybe we can following existing SET sqlTimeCondition = ''; -- error
SET sqlTimeCondition = '[]'; -- match nothing
SET sqlTimeCondition = '["2000-01-01/2000-02-01","2001-01-01/2001-02-01"]';
SET sqlTimeCondition = '2000-01-01/2000-02-01,2001-01-01/2001-02-01'; |
||
| |`enableJoinLeftTableScanDirect`|This parameter applies to queries with joins. By default, when the left child is a simple scan with a filter, Druid runs the scan as a query, then joins it with the right child on the Broker. Setting this parameter to `true` overrides that behavior and pushes the join to the data servers instead. Even if a query doesn't explicitly include a join, this parameter may still apply since the SQL planner can translate the query into a join internally.|`false`| | ||
| |`maxNumericInFilters`|Max limit for the amount of numeric values that Druid can compare for a string type dimension when the entire SQL WHERE clause of a query translates only to an [OR](../querying/filters.md#or) of [bound filter](../querying/filters.md#bound-filter). By default, Druid doesn't restrict the amount of numeric bound filters on string columns, although this situation may block other queries from running. Set this parameter to a smaller value to prevent Druid from running queries that have prohibitively long segment processing times. The optimal limit requires some trial and error. We recommend starting with 100. Users who submit a query that exceeds the limit of `maxNumericInFilters` should rewrite their queries to use strings in the `WHERE` clause instead of numbers. For example, `WHERE someString IN (‘123’, ‘456’)`. This value can't exceed the set system configuration `druid.sql.planner.maxNumericInFilters`. If `druid.sql.planner.maxNumericInFilters` isn't set explicitly, Druid ignores this value.|`-1`| | ||
| |`inFunctionThreshold`| At or beyond this threshold number of values, Druid converts SQL `IN` to [`SCALAR_IN_ARRAY`](sql-functions.md#scalar_in_array). A threshold of 0 forces this conversion in all cases. A threshold of `Integer.MAX_VALUE` disables this conversion. The converted function is eligible for fewer planning-time optimizations, which speeds up planning, but may prevent certain planning-time optimizations.| `100`| | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.msq.test; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import org.apache.druid.msq.sql.MSQTaskSqlEngine; | ||
| import org.apache.druid.query.JoinAlgorithm; | ||
| import org.apache.druid.sql.calcite.CalciteTimeConditionQueryTest; | ||
| import org.apache.druid.sql.calcite.QueryTestBuilder; | ||
| import org.apache.druid.sql.calcite.SqlTestFrameworkConfig; | ||
| import org.apache.druid.sql.calcite.planner.PlannerContext; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Runs {@link CalciteTimeConditionQueryTest} with the MSQ engine. | ||
| */ | ||
| @SqlTestFrameworkConfig.ComponentSupplier(StandardMSQComponentSupplier.class) | ||
| public class CalciteTimeConditionQueryMSQTest extends CalciteTimeConditionQueryTest | ||
| { | ||
| @Override | ||
| protected QueryTestBuilder testBuilder() | ||
| { | ||
| return new QueryTestBuilder(new CalciteTestConfig(true)) | ||
| .addCustomRunner( | ||
| new ExtractResultsFactory( | ||
| () -> (MSQTestOverlordServiceClient) ((MSQTaskSqlEngine) queryFramework().engine()).overlordClient() | ||
| ) | ||
| ) | ||
| .skipVectorize(true) | ||
| .verifyNativeQueries(new VerifyMSQSupportedNativeQueriesPredicate()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSortMergeJoin() | ||
| { | ||
| final Map<String, Object> context = ImmutableMap.<String, Object>builder() | ||
| .putAll(makeContext("2000/2001")) | ||
| .put( | ||
| PlannerContext.CTX_SQL_JOIN_ALGORITHM, | ||
| JoinAlgorithm.SORT_MERGE.toString() | ||
| ) | ||
| .build(); | ||
|
|
||
| // Both sides of a sort-merge join are subqueries, so the time condition applies within each subquery. | ||
| testBuilder() | ||
| .sql("SELECT f1.dim1, f2.dim2 FROM foo f1 INNER JOIN foo f2 ON f1.dim1 = f2.dim1") | ||
| .queryContext(context) | ||
| .expectedResults( | ||
| new UnorderedResultsVerifier( | ||
| ImmutableList.of( | ||
| new Object[]{"", "a"}, | ||
| new Object[]{"10.1", null}, | ||
| new Object[]{"2", ""} | ||
| ), | ||
| ResultMatchMode.EQUALS, | ||
| null | ||
| ) | ||
| ) | ||
| .run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.msq.test; | ||
|
|
||
| import org.apache.druid.sql.calcite.CalciteTimeConditionQueryTest; | ||
| import org.apache.druid.sql.calcite.NotYetSupported; | ||
| import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; | ||
| import org.apache.druid.sql.calcite.QueryTestBuilder; | ||
| import org.apache.druid.sql.calcite.SqlTestFrameworkConfig; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| /** | ||
| * Runs {@link CalciteTimeConditionQueryTest} with Dart and the decoupled planner. | ||
| */ | ||
| @SqlTestFrameworkConfig.ComponentSupplier(DartComponentSupplier.class) | ||
| public class DecoupledDartCalciteTimeConditionQueryTest extends CalciteTimeConditionQueryTest | ||
| { | ||
| @RegisterExtension | ||
| NotYetSupportedProcessor notYetSupportedProcessor = new NotYetSupportedProcessor(NotYetSupported.Scope.DECOUPLED_DART); | ||
|
|
||
| @RegisterExtension | ||
| DecoupledDartExtension decoupledExtension = new DecoupledDartExtension(this); | ||
|
|
||
| @Override | ||
| protected QueryTestBuilder testBuilder() | ||
| { | ||
| return decoupledExtension.testBuilder(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this also be defined as a SQL server configuration so it applies to all queries cluster-wide, similar to
druid.sql.planner.requireTimeCondition? Or is that already available throughdruid.query.default.context.sqlTimeCondition?