fix: recurse through SubqueryAlias when finding gap fill time range (#8249)

pull/24376/head
Christopher M. Wolff 2023-07-17 12:39:30 -07:00 committed by GitHub
parent e33a078128
commit b916a89159
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 1 deletions

View File

@ -135,3 +135,19 @@ SELECT
from cpu
where time between timestamp '2000-05-05T12:00:00Z' and timestamp '2000-05-05T12:59:00Z'
group by region, minute;
-- With a VALUES clause, which affects how the range is found
-- Fix for https://github.com/influxdata/idpe/issues/17880
SELECT
date_bin_gapfill(INTERVAL '1 minute', time) as _time,
pod,
locf(selector_last(image, time))
FROM
(VALUES ('2023-06-10T12:00:00Z'::timestamp, 'pod1', 'imageA'),
('2023-06-10T12:00:00Z'::timestamp, 'pod2', 'imageA'),
('2023-06-10T12:00:01Z'::timestamp, 'pod1', 'imageB'),
('2023-06-10T12:00:02Z'::timestamp, 'pod1', 'imageB'),
('2023-06-10T12:00:02Z'::timestamp, 'pod2', 'imageB')
) AS data(time, pod, image)
WHERE time >= timestamp '2023-06-10T11:55:00Z' AND time < timestamp '2023-06-10T12:05:00Z'
GROUP BY _time, pod;

View File

@ -223,3 +223,28 @@ Error during planning: gap-filling query is missing lower time bound
| b | 2000-05-05T12:40:00Z | 27.049999999999997 |
| b | 2000-05-05T12:50:00Z | 27.049999999999997 |
+--------+----------------------+--------------------+
-- SQL: SELECT date_bin_gapfill(INTERVAL '1 minute', time) as _time, pod, locf(selector_last(image, time)) FROM (VALUES ('2023-06-10T12:00:00Z'::timestamp, 'pod1', 'imageA'), ('2023-06-10T12:00:00Z'::timestamp, 'pod2', 'imageA'), ('2023-06-10T12:00:01Z'::timestamp, 'pod1', 'imageB'), ('2023-06-10T12:00:02Z'::timestamp, 'pod1', 'imageB'), ('2023-06-10T12:00:02Z'::timestamp, 'pod2', 'imageB') ) AS data(time, pod, image) WHERE time >= timestamp '2023-06-10T11:55:00Z' AND time < timestamp '2023-06-10T12:05:00Z' GROUP BY _time, pod;
+----------------------+------+--------------------------------------------+
| _time | pod | locf(selector_last(image,time)) |
+----------------------+------+--------------------------------------------+
| 2023-06-10T11:55:00Z | pod1 | |
| 2023-06-10T11:56:00Z | pod1 | |
| 2023-06-10T11:57:00Z | pod1 | |
| 2023-06-10T11:58:00Z | pod1 | |
| 2023-06-10T11:59:00Z | pod1 | |
| 2023-06-10T12:00:00Z | pod1 | {value: imageB, time: 2023-06-10T12:00:02} |
| 2023-06-10T12:01:00Z | pod1 | {value: imageB, time: 2023-06-10T12:00:02} |
| 2023-06-10T12:02:00Z | pod1 | {value: imageB, time: 2023-06-10T12:00:02} |
| 2023-06-10T12:03:00Z | pod1 | {value: imageB, time: 2023-06-10T12:00:02} |
| 2023-06-10T12:04:00Z | pod1 | {value: imageB, time: 2023-06-10T12:00:02} |
| 2023-06-10T11:55:00Z | pod2 | |
| 2023-06-10T11:56:00Z | pod2 | |
| 2023-06-10T11:57:00Z | pod2 | |
| 2023-06-10T11:58:00Z | pod2 | |
| 2023-06-10T11:59:00Z | pod2 | |
| 2023-06-10T12:00:00Z | pod2 | {value: imageB, time: 2023-06-10T12:00:02} |
| 2023-06-10T12:01:00Z | pod2 | {value: imageB, time: 2023-06-10T12:00:02} |
| 2023-06-10T12:02:00Z | pod2 | {value: imageB, time: 2023-06-10T12:00:02} |
| 2023-06-10T12:03:00Z | pod2 | {value: imageB, time: 2023-06-10T12:00:02} |
| 2023-06-10T12:04:00Z | pod2 | {value: imageB, time: 2023-06-10T12:00:02} |
+----------------------+------+--------------------------------------------+

View File

@ -65,6 +65,12 @@ impl TreeNodeVisitor for TimeRangeVisitor {
self.range = range;
Ok(VisitRecursion::Continue)
}
LogicalPlan::SubqueryAlias(_) => {
// The nodes below this one refer to the column with a different table name,
// just unset the relation so we match on the column name.
self.col.relation = None;
Ok(VisitRecursion::Continue)
}
// These nodes do not alter their schema, so we can recurse through them
LogicalPlan::Sort(_)
| LogicalPlan::Repartition(_)