forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQL: Use regular filters for time filtering in subqueries. (apache#17173
) * SQL: Use regular filters for time filtering in subqueries. Using the "intervals" feature on subqueries, or any non-table, should be avoided because it isn't a meaningful optimization in those cases, and it's simpler for runtime implementations if they can assume all filters are located in the regular filter object. Two changes: 1) Fix the logic in DruidQuery.canUseIntervalFiltering. It was intended to return false for QueryDataSource, but actually returned true. 2) Add a validation to ScanQueryFrameProcessor to ensure that when running on an input channel (which would include any subquery), the query has "intervals" set to ONLY_ETERNITY. Prior to this patch, the new test case in testTimeFilterOnSubquery would throw a "Can only handle a single interval" error in the native engine, and "QueryNotSupported" in the MSQ engine. * Mark new case as having extra columns in decoupled mode. * Adjust test.
- Loading branch information
Showing
6 changed files
with
255 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...alcite.DecoupledPlanningCalciteQueryTest/testTimeFilterOnSubquery@NullHandling=default.iq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# testTimeFilterOnSubquery@NullHandling=default case-crc:73448efc | ||
# quidem testcase reason: EQUIV_PLAN_EXTRA_COLUMNS | ||
!set debug true | ||
!set defaultTimeout 300000 | ||
!set maxScatterGatherBytes 9223372036854775807 | ||
!set plannerStrategy DECOUPLED | ||
!set sqlCurrentTimestamp 2000-01-01T00:00:00Z | ||
!set sqlQueryId dummy | ||
!set outputformat mysql | ||
!use druidtest:/// | ||
SELECT __time, m1 FROM (SELECT * FROM "foo" LIMIT 100) | ||
WHERE TIME_IN_INTERVAL(__time, '2000/P1D') OR TIME_IN_INTERVAL(__time, '2001/P1D'); | ||
+-------------------------+-----+ | ||
| __time | m1 | | ||
+-------------------------+-----+ | ||
| 2000-01-01 00:00:00.000 | 1.0 | | ||
| 2001-01-01 00:00:00.000 | 4.0 | | ||
+-------------------------+-----+ | ||
(2 rows) | ||
|
||
!ok | ||
LogicalProject(__time=[$0], m1=[$5]) | ||
LogicalFilter(condition=[SEARCH($0, Sarg[[2000-01-01 00:00:00:TIMESTAMP(3)..2000-01-02 00:00:00:TIMESTAMP(3)), [2001-01-01 00:00:00:TIMESTAMP(3)..2001-01-02 00:00:00:TIMESTAMP(3))]:TIMESTAMP(3))]) | ||
LogicalSort(fetch=[100]) | ||
LogicalTableScan(table=[[druid, foo]]) | ||
|
||
!logicalPlan | ||
DruidProject(__time=[$0], m1=[$5], druid=[logical]) | ||
DruidFilter(condition=[SEARCH($0, Sarg[[2000-01-01 00:00:00:TIMESTAMP(3)..2000-01-02 00:00:00:TIMESTAMP(3)), [2001-01-01 00:00:00:TIMESTAMP(3)..2001-01-02 00:00:00:TIMESTAMP(3))]:TIMESTAMP(3))]) | ||
DruidSort(fetch=[100], druid=[logical]) | ||
DruidTableScan(table=[[druid, foo]], druid=[logical]) | ||
|
||
!druidPlan | ||
{ | ||
"queryType" : "scan", | ||
"dataSource" : { | ||
"type" : "query", | ||
"query" : { | ||
"queryType" : "scan", | ||
"dataSource" : { | ||
"type" : "table", | ||
"name" : "foo" | ||
}, | ||
"intervals" : { | ||
"type" : "intervals", | ||
"intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] | ||
}, | ||
"resultFormat" : "compactedList", | ||
"limit" : 100, | ||
"columns" : [ "__time", "cnt", "dim1", "dim2", "dim3", "m1", "m2", "unique_dim1" ], | ||
"columnTypes" : [ "LONG", "LONG", "STRING", "STRING", "STRING", "FLOAT", "DOUBLE", "COMPLEX<hyperUnique>" ], | ||
"granularity" : { | ||
"type" : "all" | ||
}, | ||
"legacy" : false | ||
} | ||
}, | ||
"intervals" : { | ||
"type" : "intervals", | ||
"intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] | ||
}, | ||
"resultFormat" : "compactedList", | ||
"filter" : { | ||
"type" : "or", | ||
"fields" : [ { | ||
"type" : "bound", | ||
"dimension" : "__time", | ||
"lower" : "946684800000", | ||
"upper" : "946771200000", | ||
"upperStrict" : true, | ||
"ordering" : { | ||
"type" : "numeric" | ||
} | ||
}, { | ||
"type" : "bound", | ||
"dimension" : "__time", | ||
"lower" : "978307200000", | ||
"upper" : "978393600000", | ||
"upperStrict" : true, | ||
"ordering" : { | ||
"type" : "numeric" | ||
} | ||
} ] | ||
}, | ||
"columns" : [ "__time", "m1" ], | ||
"columnTypes" : [ "LONG", "FLOAT" ], | ||
"granularity" : { | ||
"type" : "all" | ||
}, | ||
"legacy" : false | ||
} | ||
!nativePlan |
88 changes: 88 additions & 0 deletions
88
...ql.calcite.DecoupledPlanningCalciteQueryTest/testTimeFilterOnSubquery@NullHandling=sql.iq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# testTimeFilterOnSubquery@NullHandling=sql case-crc:73448efc | ||
# quidem testcase reason: EQUIV_PLAN_EXTRA_COLUMNS | ||
!set debug true | ||
!set defaultTimeout 300000 | ||
!set maxScatterGatherBytes 9223372036854775807 | ||
!set plannerStrategy DECOUPLED | ||
!set sqlCurrentTimestamp 2000-01-01T00:00:00Z | ||
!set sqlQueryId dummy | ||
!set outputformat mysql | ||
!use druidtest:/// | ||
SELECT __time, m1 FROM (SELECT * FROM "foo" LIMIT 100) | ||
WHERE TIME_IN_INTERVAL(__time, '2000/P1D') OR TIME_IN_INTERVAL(__time, '2001/P1D'); | ||
+-------------------------+-----+ | ||
| __time | m1 | | ||
+-------------------------+-----+ | ||
| 2000-01-01 00:00:00.000 | 1.0 | | ||
| 2001-01-01 00:00:00.000 | 4.0 | | ||
+-------------------------+-----+ | ||
(2 rows) | ||
|
||
!ok | ||
LogicalProject(__time=[$0], m1=[$5]) | ||
LogicalFilter(condition=[SEARCH($0, Sarg[[2000-01-01 00:00:00:TIMESTAMP(3)..2000-01-02 00:00:00:TIMESTAMP(3)), [2001-01-01 00:00:00:TIMESTAMP(3)..2001-01-02 00:00:00:TIMESTAMP(3))]:TIMESTAMP(3))]) | ||
LogicalSort(fetch=[100]) | ||
LogicalTableScan(table=[[druid, foo]]) | ||
|
||
!logicalPlan | ||
DruidProject(__time=[$0], m1=[$5], druid=[logical]) | ||
DruidFilter(condition=[SEARCH($0, Sarg[[2000-01-01 00:00:00:TIMESTAMP(3)..2000-01-02 00:00:00:TIMESTAMP(3)), [2001-01-01 00:00:00:TIMESTAMP(3)..2001-01-02 00:00:00:TIMESTAMP(3))]:TIMESTAMP(3))]) | ||
DruidSort(fetch=[100], druid=[logical]) | ||
DruidTableScan(table=[[druid, foo]], druid=[logical]) | ||
|
||
!druidPlan | ||
{ | ||
"queryType" : "scan", | ||
"dataSource" : { | ||
"type" : "query", | ||
"query" : { | ||
"queryType" : "scan", | ||
"dataSource" : { | ||
"type" : "table", | ||
"name" : "foo" | ||
}, | ||
"intervals" : { | ||
"type" : "intervals", | ||
"intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] | ||
}, | ||
"resultFormat" : "compactedList", | ||
"limit" : 100, | ||
"columns" : [ "__time", "cnt", "dim1", "dim2", "dim3", "m1", "m2", "unique_dim1" ], | ||
"columnTypes" : [ "LONG", "LONG", "STRING", "STRING", "STRING", "FLOAT", "DOUBLE", "COMPLEX<hyperUnique>" ], | ||
"granularity" : { | ||
"type" : "all" | ||
}, | ||
"legacy" : false | ||
} | ||
}, | ||
"intervals" : { | ||
"type" : "intervals", | ||
"intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ] | ||
}, | ||
"resultFormat" : "compactedList", | ||
"filter" : { | ||
"type" : "or", | ||
"fields" : [ { | ||
"type" : "range", | ||
"column" : "__time", | ||
"matchValueType" : "LONG", | ||
"lower" : 946684800000, | ||
"upper" : 946771200000, | ||
"upperOpen" : true | ||
}, { | ||
"type" : "range", | ||
"column" : "__time", | ||
"matchValueType" : "LONG", | ||
"lower" : 978307200000, | ||
"upper" : 978393600000, | ||
"upperOpen" : true | ||
} ] | ||
}, | ||
"columns" : [ "__time", "m1" ], | ||
"columnTypes" : [ "LONG", "FLOAT" ], | ||
"granularity" : { | ||
"type" : "all" | ||
}, | ||
"legacy" : false | ||
} | ||
!nativePlan |