Skip to content

Commit

Permalink
[BugFix] Fix optimize table fail with special characters (#51709)
Browse files Browse the repository at this point in the history
Signed-off-by: meegoo <[email protected]>
  • Loading branch information
meegoo authored Oct 12, 2024
1 parent da80492 commit 2a1a68b
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,11 @@ protected void runWaitingTxnJob() throws AlterCancelException {
for (int i = 0; i < tmpPartitionNames.size(); ++i) {
String tmpPartitionName = tmpPartitionNames.get(i);
String partitionName = partitionNames.get(i);
String rewriteSql = "insert into " + dbName + "." + tableName + " TEMPORARY PARTITION ("
+ tmpPartitionName + ") select " + Joiner.on(", ").join(tableColumnNames)
+ " from " + dbName + "." + tableName + " partition (" + partitionName + ")";
String rewriteSql = "insert into " + ParseUtil.backquote(dbName) + "."
+ ParseUtil.backquote(tableName) + " TEMPORARY PARTITION ("
+ ParseUtil.backquote(tmpPartitionName) + ") select " + Joiner.on(", ").join(tableColumnNames)
+ " from " + ParseUtil.backquote(dbName) + "." + ParseUtil.backquote(tableName)
+ " partition (" + ParseUtil.backquote(partitionName) + ")";
String taskName = getName() + "_" + tmpPartitionName;
OptimizeTask rewriteTask = TaskBuilder.buildOptimizeTask(taskName, properties, rewriteSql, dbName);
rewriteTask.setPartitionName(partitionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ protected void runWaitingTxnJob() throws AlterCancelException {
for (int i = 0; i < tmpPartitionNames.size(); ++i) {
String tmpPartitionName = tmpPartitionNames.get(i);
String partitionName = partitionNames.get(i);
String rewriteSql = "insert into " + tableName + " TEMPORARY PARTITION ("
+ tmpPartitionName + ") select " + Joiner.on(", ").join(tableColumnNames)
+ " from " + tableName + " partition (" + partitionName + ")";
String rewriteSql = "insert into " + ParseUtil.backquote(tableName) + " TEMPORARY PARTITION ("
+ ParseUtil.backquote(tmpPartitionName) + ") select " + Joiner.on(", ").join(tableColumnNames)
+ " from " + ParseUtil.backquote(tableName) + " partition (" + ParseUtil.backquote(partitionName) + ")";
String taskName = getName() + "_" + tmpPartitionName;
OptimizeTask rewriteTask = TaskBuilder.buildOptimizeTask(taskName, properties, rewriteSql, dbName);
rewriteTask.setPartitionName(partitionName);
Expand Down
75 changes: 75 additions & 0 deletions test/sql/test_optimize_table/R/test_optimize_table
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ PROPERTIES (





-- name: test_alter_key_buckets
CREATE TABLE demo2_alter_0 (
`user_name` VARCHAR(32) DEFAULT '',
Expand All @@ -119,6 +121,8 @@ None





-- name: test_online_optimize_table
create table t(k int, k1 date) PARTITION BY RANGE(`k1`)
(
Expand Down Expand Up @@ -326,6 +330,8 @@ select count(*) from t;
-- !result




-- name: test_online_optimize_table_pk
create table t(k int) primary key(k) distributed by hash(k) buckets 10;
-- result:
Expand Down Expand Up @@ -546,6 +552,8 @@ select * from t;
20
-- !result



-- name: test_online_optimize_table_stream_load
create database db_${uuid0};
-- result:
Expand Down Expand Up @@ -856,4 +864,71 @@ PROPERTIES (
select count(*) from t;
-- result:
63
-- !result

-- name: test_optimize_table_with_special_characters
create table `t#t`(k int) distributed by hash(k) buckets 10;
-- result:
-- !result
show create table `t#t`;
-- result:
t#t CREATE TABLE `t#t` (
`k` int(11) NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`k`)
DISTRIBUTED BY HASH(`k`) BUCKETS 10
PROPERTIES (
"compression" = "LZ4",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "3"
);
-- !result
alter table `t#t` distributed by hash(k) buckets 20;
-- result:
-- !result
function: wait_optimize_table_finish()
-- result:
None
-- !result
show create table `t#t`;
-- result:
t#t CREATE TABLE `t#t` (
`k` int(11) NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`k`)
DISTRIBUTED BY HASH(`k`) BUCKETS 20
PROPERTIES (
"compression" = "LZ4",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "3"
);
-- !result
admin set frontend config ('enable_online_optimize_table'='false');
-- result:
-- !result
alter table `t#t` distributed by hash(k) buckets 30;
-- result:
-- !result
function: wait_optimize_table_finish()
-- result:
None
-- !result
show create table `t#t`;
-- result:
t#t CREATE TABLE `t#t` (
`k` int(11) NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`k`)
DISTRIBUTED BY HASH(`k`) BUCKETS 30
PROPERTIES (
"compression" = "LZ4",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "3"
);
-- !result
admin set frontend config ('enable_online_optimize_table'='true');
-- result:
-- !result
14 changes: 13 additions & 1 deletion test/sql/test_optimize_table/T/test_optimize_table
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,16 @@ select count(*) from t;
function: wait_optimize_table_finish()
show create table t;
-- show partitions from t;
select count(*) from t;
select count(*) from t;

-- name: test_optimize_table_with_special_characters
create table `t#t`(k int) distributed by hash(k) buckets 10;
show create table `t#t`;
alter table `t#t` distributed by hash(k) buckets 20;
function: wait_optimize_table_finish()
show create table `t#t`;
admin set frontend config ('enable_online_optimize_table'='false');
alter table `t#t` distributed by hash(k) buckets 30;
function: wait_optimize_table_finish()
show create table `t#t`;
admin set frontend config ('enable_online_optimize_table'='true');

0 comments on commit 2a1a68b

Please sign in to comment.