Skip to content

Commit

Permalink
[BugFix] fix partial update failure due to column name case (backport #…
Browse files Browse the repository at this point in the history
…53656) (#54462)

Co-authored-by: Yixin Luo <[email protected]>
  • Loading branch information
mergify[bot] and luohaha authored Dec 27, 2024
1 parent d5ff4ab commit 45ea92b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public UpdateStmt(TableName tableName, List<ColumnAssignment> assignments, List<
this.fromRelations = fromRelations;
this.wherePredicate = wherePredicate;
this.commonTableExpressions = commonTableExpressions;
this.assignmentColumns = Sets.newHashSet();
this.assignmentColumns = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
for (ColumnAssignment each : assignments) {
this.assignmentColumns.add(each.getColumn());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public void testUpdate() throws Exception {
testExplain("explain costs update tprimary set v2 = v2 + 1 where v1 = 'aaa'");
}

@Test
public void testColumnPartialUpdate() throws Exception {
String oldVal = connectContext.getSessionVariable().getPartialUpdateMode();
connectContext.getSessionVariable().setPartialUpdateMode("column");
testExplain("explain update tprimary set v2 = v2 + 1 where v1 = 'aaa'");
testExplain("explain update tprimary set v2 = DEFAULT where v1 = 'aaa'");
testExplain("explain update tprimary_auto_increment set v2 = DEFAULT where v1 = '123'");
testExplain("explain verbose update tprimary set v2 = v2 + 1 where v1 = 'aaa'");
testExplain("explain costs update tprimary set v2 = v2 + 1 where v1 = 'aaa'");
connectContext.getSessionVariable().setPartialUpdateMode(oldVal);
}

private void testExplain(String explainStmt) throws Exception {
connectContext.getState().reset();
List<StatementBase> statements =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- name: test_upper_case_partial_update
show backends;
CREATE table tab1 (
k1 INTEGER,
k2 VARCHAR(50),
V1 INTEGER,
v2 INTEGER,
v3 INTEGER,
v4 varchar(50),
v5 varchar(50)
)
ENGINE=OLAP
PRIMARY KEY(`k1`,`k2`)
DISTRIBUTED BY HASH(`k1`) BUCKETS 10
PROPERTIES (
"replication_num" = "1"
);
-- result:
-- !result
insert into tab1 values (100, "k2_100", 100, 100, 100, "v4_100", "v5_100");
-- result:
-- !result
insert into tab1 values (200, "k2_200", 200, 200, 200, "v4_200", "v5_200");
-- result:
-- !result
insert into tab1 values (300, "k3_300", 300, 300, 300, "v4_300", "v5_300");
-- result:
-- !result
select * from tab1;
-- result:
300 k3_300 300 300 300 v4_300 v5_300
100 k2_100 100 100 100 v4_100 v5_100
200 k2_200 200 200 200 v4_200 v5_200
-- !result
set partial_update_mode = 'column';
-- result:
-- !result
update tab1 set V1 = 101 where k1 = 100 and k2 = "k2_100";
-- result:
-- !result
update tab1 set v1 = 202 where k1 = 200 and k2 = "k2_200";
-- result:
-- !result
select * from tab1;
-- result:
300 k3_300 300 300 300 v4_300 v5_300
100 k2_100 101 100 100 v4_100 v5_100
200 k2_200 202 200 200 v4_200 v5_200
-- !result
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- name: test_upper_case_partial_update
show backends;
CREATE table tab1 (
k1 INTEGER,
k2 VARCHAR(50),
V1 INTEGER,
v2 INTEGER,
v3 INTEGER,
v4 varchar(50),
v5 varchar(50)
)
ENGINE=OLAP
PRIMARY KEY(`k1`,`k2`)
DISTRIBUTED BY HASH(`k1`) BUCKETS 10
PROPERTIES (
"replication_num" = "1"
);

insert into tab1 values (100, "k2_100", 100, 100, 100, "v4_100", "v5_100");
insert into tab1 values (200, "k2_200", 200, 200, 200, "v4_200", "v5_200");
insert into tab1 values (300, "k3_300", 300, 300, 300, "v4_300", "v5_300");
select * from tab1;

set partial_update_mode = 'column';
update tab1 set V1 = 101 where k1 = 100 and k2 = "k2_100";
update tab1 set v1 = 202 where k1 = 200 and k2 = "k2_200";
select * from tab1;

0 comments on commit 45ea92b

Please sign in to comment.