Skip to content

Commit

Permalink
fix(binder): report error on update query with subquery on the set cl…
Browse files Browse the repository at this point in the history
…ause (#19305)
  • Loading branch information
chenzl25 authored Nov 13, 2024
1 parent f0ece45 commit c0b5e64
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/frontend/planner_test/tests/testdata/input/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@
update t set a = a + 1;
expected_outputs:
- batch_distributed_plan
- name: update table with subquery in the set clause
sql: |
create table t1 (v1 int primary key, v2 int);
create table t2 (v1 int primary key, v2 int);
update t1 set v1 = (select v1 from t2 where t1.v2 = t2.v2);
expected_outputs:
- binder_error
6 changes: 6 additions & 0 deletions src/frontend/planner_test/tests/testdata/output/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,9 @@
└─BatchUpdate { table: t, exprs: [($0 + 1:Int32), $1, $2] }
└─BatchExchange { order: [], dist: HashShard(t.a, t.b, t._row_id) }
└─BatchScan { table: t, columns: [t.a, t.b, t._row_id], distribution: UpstreamHashShard(t._row_id) }
- name: update table with subquery in the set clause
sql: |
create table t1 (v1 int primary key, v2 int);
create table t2 (v1 int primary key, v2 int);
update t1 set v1 = (select v1 from t2 where t1.v2 = t2.v2);
binder_error: 'Bind error: subquery on the right side of assignment is unsupported'
13 changes: 7 additions & 6 deletions src/frontend/src/binder/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use std::collections::{BTreeMap, HashMap};

use fixedbitset::FixedBitSet;
use itertools::Itertools;
use risingwave_common::bail_not_implemented;
use risingwave_common::catalog::{Schema, TableVersionId};
use risingwave_common::util::iter_util::ZipEqFast;
use risingwave_sqlparser::ast::{Assignment, AssignmentValue, Expr, ObjectName, SelectItem};
Expand Down Expand Up @@ -129,15 +128,17 @@ impl Binder {
for Assignment { id, value } in assignments {
// FIXME: Parsing of `id` is not strict. It will even treat `a.b` as `(a, b)`.
let assignments = match (id.as_slice(), value) {
// _ = (subquery)
(_ids, AssignmentValue::Expr(Expr::Subquery(_))) => {
return Err(ErrorCode::BindError(
"subquery on the right side of assignment is unsupported".to_owned(),
)
.into())
}
// col = expr
([id], value) => {
vec![(id.clone(), value)]
}

// (col1, col2) = (subquery)
(_ids, AssignmentValue::Expr(Expr::Subquery(_))) => {
bail_not_implemented!("subquery on the right side of multi-assignment");
}
// (col1, col2) = (expr1, expr2)
// TODO: support `DEFAULT` in multiple assignments
(ids, AssignmentValue::Expr(Expr::Row(values))) if ids.len() == values.len() => id
Expand Down

0 comments on commit c0b5e64

Please sign in to comment.