Skip to content

Commit

Permalink
update error messages
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Chien <[email protected]>
  • Loading branch information
stdrc committed Jul 19, 2024
1 parent 2a52433 commit 288a532
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
- name: Temporal filter with equal condition
sql: |-
create table t1 (ts timestamp with time zone);
select * from t1 where date_trunc('week', now()) = date_trunc('week',ts);
select * from t1 where date_trunc('week', now()) = date_trunc('week',ts);
expected_outputs:
- stream_plan
- stream_dist_plan
Expand Down Expand Up @@ -129,3 +129,9 @@
select * from t where ts + interval '1 hour' > date_trunc('day', ('2024-07-18 00:00:00+00:00'::timestamptz - ('2024-07-18 00:00:00+00:00'::timestamptz - now())));
expected_outputs:
- stream_plan
- name: Non-monotonic now expression
sql: |
create table t (ts timestamp with time zone, a int);
select * from t where a > extract(hour from now());
expected_outputs:
- stream_error
2 changes: 1 addition & 1 deletion src/frontend/planner_test/tests/testdata/output/expr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@
sql: |
create table t (v1 timestamp with time zone, v2 timestamp with time zone);
select * from t where v1 >= now() or v2 >= now();
stream_error: Conditions containing now must be of the form `input_expr cmp now() [+- const_expr]` or `now() [+- const_expr] cmp input_expr`, where `input_expr` references a column and contains no `now()`.
stream_error: Conditions containing now must be in the form of `input_expr cmp now_expr` or `now_expr cmp input_expr`, where `input_expr` references a column and contains no `now()`, and `now_expr` is a non-decreasing expression contains `now()`.
- name: now inside HAVING clause
sql: |
create table t (v1 timestamp with time zone, v2 int);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
- name: Temporal filter with equal condition
sql: |-
create table t1 (ts timestamp with time zone);
select * from t1 where date_trunc('week', now()) = date_trunc('week',ts);
select * from t1 where date_trunc('week', now()) = date_trunc('week',ts);
stream_plan: |-
StreamMaterialize { columns: [ts, t1._row_id(hidden), $expr1(hidden)], stream_key: [t1._row_id, $expr1], pk_columns: [t1._row_id, $expr1], pk_conflict: NoCheck }
└─StreamExchange { dist: HashShard(t1._row_id, $expr1) }
Expand Down Expand Up @@ -486,3 +486,8 @@
└─StreamExchange { dist: Broadcast }
└─StreamProject { exprs: [DateTrunc('day':Varchar, SubtractWithTimeZone('2024-07-18 00:00:00+00:00':Timestamptz, ('2024-07-18 00:00:00+00:00':Timestamptz - now), 'UTC':Varchar), 'UTC':Varchar) as $expr2] }
└─StreamNow { output: [now] }
- name: Non-monotonic now expression
sql: |
create table t (ts timestamp with time zone, a int);
select * from t where a > extract(hour from now());
stream_error: Conditions containing now must be in the form of `input_expr cmp now_expr` or `now_expr cmp input_expr`, where `input_expr` references a column and contains no `now()`, and `now_expr` is a non-decreasing expression contains `now()`.
21 changes: 4 additions & 17 deletions src/frontend/src/optimizer/plan_node/logical_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,11 @@ impl ToStream for LogicalFilter {
let new_input = self.input().to_stream(ctx)?;

let predicate = self.predicate();
let has_now = predicate
.conjunctions
.iter()
.any(|cond| cond.count_nows() > 0);
if has_now {
if predicate
.conjunctions
.iter()
.any(|expr| expr.count_nows() > 0 && expr.as_now_comparison_cond().is_none())
{
bail!(
"Conditions containing now must be of the form `input_expr cmp now() [+- const_expr]` or \
`now() [+- const_expr] cmp input_expr`, where `input_expr` references a column \
and contains no `now()`."
);
}
if predicate.conjunctions.iter().any(|cond| cond.has_now()) {
bail!(
"All `now()` exprs were valid, but the condition must have at least one now expr as a lower bound."
"Conditions containing now must be in the form of `input_expr cmp now_expr` or \
`now_expr cmp input_expr`, where `input_expr` references a column and contains \
no `now()`, and `now_expr` is a non-decreasing expression contains `now()`."
);
}
let mut new_logical = self.core.clone();
Expand Down

0 comments on commit 288a532

Please sign in to comment.