-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): Reorder cmp expressions and require
now()
lower bou…
…nd for `TemporalFilter` (#7497) Reorder cmp expressions and require now lower bound for `TemporalFilter` Approved-By: soundOfDestiny Co-Authored-By: jon-chuang <[email protected]> Co-Authored-By: Liang Zhao <[email protected]>
- Loading branch information
1 parent
2e28fd3
commit da83a65
Showing
4 changed files
with
89 additions
and
49 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
58 changes: 58 additions & 0 deletions
58
src/frontend/planner_test/tests/testdata/temporal_filter.yaml
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,58 @@ | ||
# This file is automatically generated. See `src/frontend/planner_test/README.md` for more information. | ||
- name: Temporal filter works on complex columns on LHS | ||
sql: | | ||
create table t1 (ts timestamp with time zone); | ||
select * from t1 where ts + interval '1 hour' > now(); | ||
stream_plan: | | ||
StreamMaterialize { columns: [ts, t1._row_id(hidden)], pk_columns: [t1._row_id] } | ||
└─StreamProject { exprs: [t1.ts, t1._row_id] } | ||
└─StreamDynamicFilter { predicate: ((t1.ts + '01:00:00':Interval) > now), output: [t1.ts, (t1.ts + '01:00:00':Interval), t1._row_id] } | ||
├─StreamProject { exprs: [t1.ts, (t1.ts + '01:00:00':Interval), t1._row_id] } | ||
| └─StreamTableScan { table: t1, columns: [t1.ts, t1._row_id], pk: [t1._row_id], dist: UpstreamHashShard(t1._row_id) } | ||
└─StreamExchange { dist: Broadcast } | ||
└─StreamNow { output: [now] } | ||
- name: Temporal filter works on complex columns on LHS (part 2) | ||
sql: | | ||
create table t1 (ts timestamp with time zone, time_to_live interval); | ||
select * from t1 where ts + time_to_live * 1.5 > now(); | ||
stream_plan: | | ||
StreamMaterialize { columns: [ts, time_to_live, t1._row_id(hidden)], pk_columns: [t1._row_id] } | ||
└─StreamProject { exprs: [t1.ts, t1.time_to_live, t1._row_id] } | ||
└─StreamDynamicFilter { predicate: ((t1.ts + (t1.time_to_live * 1.5:Decimal)) > now), output: [t1.ts, t1.time_to_live, (t1.ts + (t1.time_to_live * 1.5:Decimal)), t1._row_id] } | ||
├─StreamProject { exprs: [t1.ts, t1.time_to_live, (t1.ts + (t1.time_to_live * 1.5:Decimal)), t1._row_id] } | ||
| └─StreamTableScan { table: t1, columns: [t1.ts, t1.time_to_live, t1._row_id], pk: [t1._row_id], dist: UpstreamHashShard(t1._row_id) } | ||
└─StreamExchange { dist: Broadcast } | ||
└─StreamNow { output: [now] } | ||
- name: Temporal filter works on complex columns on LHS (part 2, flipped) | ||
sql: | | ||
create table t1 (ts timestamp with time zone, additional_time_to_live interval); | ||
select * from t1 where now() - interval '15 minutes' < ts + additional_time_to_live * 1.5; | ||
stream_plan: | | ||
StreamMaterialize { columns: [ts, additional_time_to_live, t1._row_id(hidden)], pk_columns: [t1._row_id] } | ||
└─StreamProject { exprs: [t1.ts, t1.additional_time_to_live, t1._row_id] } | ||
└─StreamDynamicFilter { predicate: ((t1.ts + (t1.additional_time_to_live * 1.5:Decimal)) > (now - '00:15:00':Interval)), output: [t1.ts, t1.additional_time_to_live, (t1.ts + (t1.additional_time_to_live * 1.5:Decimal)), t1._row_id] } | ||
├─StreamProject { exprs: [t1.ts, t1.additional_time_to_live, (t1.ts + (t1.additional_time_to_live * 1.5:Decimal)), t1._row_id] } | ||
| └─StreamTableScan { table: t1, columns: [t1.ts, t1.additional_time_to_live, t1._row_id], pk: [t1._row_id], dist: UpstreamHashShard(t1._row_id) } | ||
└─StreamExchange { dist: Broadcast } | ||
└─StreamProject { exprs: [(now - '00:15:00':Interval)], watermark_columns: [(now - '00:15:00':Interval)] } | ||
└─StreamNow { output: [now] } | ||
- name: Temporal filter fails without `now()` in lower bound | ||
sql: |- | ||
create table t1 (ts timestamp with time zone); | ||
select * from t1 where now() - interval '15 minutes' > ts; | ||
stream_error: 'internal error: All `now()` exprs were valid, but the condition must have at least one now expr as a lower bound.' | ||
- name: Temporal filter reorders now expressions correctly | ||
sql: | | ||
create table t1 (ts timestamp with time zone); | ||
select * from t1 where ts < now() - interval '1 hour' and ts >= now() - interval '2 hour'; | ||
stream_plan: | | ||
StreamMaterialize { columns: [ts, t1._row_id(hidden)], pk_columns: [t1._row_id] } | ||
└─StreamDynamicFilter { predicate: (t1.ts < (now - '01:00:00':Interval)), output: [t1.ts, t1._row_id] } | ||
├─StreamDynamicFilter { predicate: (t1.ts >= (now - '02:00:00':Interval)), output: [t1.ts, t1._row_id] } | ||
| ├─StreamTableScan { table: t1, columns: [t1.ts, t1._row_id], pk: [t1._row_id], dist: UpstreamHashShard(t1._row_id) } | ||
| └─StreamExchange { dist: Broadcast } | ||
| └─StreamProject { exprs: [(now - '02:00:00':Interval)], watermark_columns: [(now - '02:00:00':Interval)] } | ||
| └─StreamNow { output: [now] } | ||
└─StreamExchange { dist: Broadcast } | ||
└─StreamProject { exprs: [(now - '01:00:00':Interval)], watermark_columns: [(now - '01:00:00':Interval)] } | ||
└─StreamNow { output: [now] } |
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