Skip to content

Commit

Permalink
fix: fix update using using constant in predicate from subquery panic (
Browse files Browse the repository at this point in the history
…#14367)

* fix: fix update predicate from subquery panic

* fix: fix update predicate from subquery panic

* fix: fix update predicate from subquery panic
  • Loading branch information
lichuang authored Jan 19, 2024
1 parent 3f532a2 commit 692549d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/query/storages/fuse/src/operations/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,25 @@ impl FuseTable {
let mut remain_reader = None;
let mut pos = 0;
let (projection, input_schema) = if col_indices.is_empty() {
let mut fields = schema.remove_virtual_computed_fields().fields().to_vec();

all_column_indices.iter().for_each(|&index| {
offset_map.insert(index, pos);
pos += 1;
});

(
Projection::Columns(all_column_indices),
Arc::new(schema.remove_virtual_computed_fields()),
)
if query_row_id_col {
// add `_predicate` column into input schema
fields.push(TableField::new(
PREDICATE_COLUMN_NAME,
TableDataType::Boolean,
));
pos += 1;
}

let schema = TableSchema::new(fields);

(Projection::Columns(all_column_indices), Arc::new(schema))
} else {
col_indices.iter().for_each(|&index| {
offset_map.insert(index, pos);
Expand All @@ -113,6 +123,7 @@ impl FuseTable {
.map(|index| schema.fields()[*index].clone())
.collect();

// add `_predicate` column into input schema
fields.push(TableField::new(
PREDICATE_COLUMN_NAME,
TableDataType::Boolean,
Expand Down Expand Up @@ -145,7 +156,6 @@ impl FuseTable {
Arc::new(TableSchema::new(fields)),
)
};

let mut cap = 2;
if !computed_list.is_empty() {
cap += 1;
Expand Down Expand Up @@ -208,6 +218,7 @@ impl FuseTable {
1,
);
}

let remain_reader = Arc::new(remain_reader);
let filter_expr = Arc::new(filter.map(|v| {
v.as_expr(&BUILTIN_FUNCTIONS)
Expand Down
19 changes: 19 additions & 0 deletions tests/sqllogictests/suites/base/03_common/03_0035_update.test
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,24 @@ drop table t1;
statement ok
drop table t2;

statement ok
drop table if exists t;

statement ok
create table t(a int);

statement ok
insert into t values(1),(2),(3);

statement ok
update t set a = 100 where 20 > any(select a from t);

query I
select * from t;
----
100
100
100

statement ok
DROP DATABASE db1

0 comments on commit 692549d

Please sign in to comment.