Skip to content

Commit

Permalink
[BugFix] Change non-pk sort key type maybe failed (#44961)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangqiang <[email protected]>
  • Loading branch information
sevev authored Apr 29, 2024
1 parent c94a2ca commit 7944461
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ private SchemaChangeData finalAnalyze(Database db, OlapTable olapTable,
for (Integer colIdx : originSortKeyIdxes) {
String columnName = index.getSchema().get(colIdx).getName();
Optional<Column> oneCol =
alterSchema.stream().filter(c -> c.getName().equalsIgnoreCase(columnName)).findFirst();
alterSchema.stream().filter(c -> c.nameEquals(columnName, true)).findFirst();
if (oneCol.isEmpty()) {
LOG.warn("Sort Key Column[" + columnName + "] not exists in new schema");
throw new DdlException("Sort Key Column[" + columnName + "] not exists in new schema");
Expand Down
66 changes: 50 additions & 16 deletions test/sql/test_sort_key/R/test_sort_key_agg_tbl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CREATE TABLE `agg_test` (
)
AGGREGATE KEY(k1, k2)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY (k2)
PROPERTIES (
"replication_num" = "1",
Expand All @@ -34,7 +34,7 @@ CREATE TABLE `agg_test` (
)
AGGREGATE KEY(k1, k2)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY (k2,v2)
PROPERTIES (
"replication_num" = "1",
Expand All @@ -53,7 +53,7 @@ CREATE TABLE `agg_test` (
)
AGGREGATE KEY(k1, k2)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY (k2,k1,k1)
PROPERTIES (
"replication_num" = "1",
Expand All @@ -73,7 +73,7 @@ CREATE TABLE `agg_test` (
)
AGGREGATE KEY(k1, k2)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY (k2,k1)
PROPERTIES (
"replication_num" = "1",
Expand Down Expand Up @@ -146,7 +146,47 @@ agg_test CREATE TABLE `agg_test` (
) ENGINE=OLAP
AGGREGATE KEY(`k1`, `k2`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY(`k1`, `k2`)
PROPERTIES (
"compression" = "LZ4",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "1"
);
-- !result
select * from agg_test;
-- result:
1 2 2 10 9
1 3 2 10 9
2 1 2 8 8
2 2 2 9 7
2 3 2 9 7
3 1 2 8 8
-- !result
alter table agg_test modify column k1 bigint key;
-- result:
E: (1064, 'Can not modify distribution column[k1]. index[agg_test]')
-- !result
alter table agg_test modify column k2 bigint key;
-- result:
-- !result
function: wait_alter_table_finish()
-- result:
None
-- !result
show create table agg_test;
-- result:
agg_test CREATE TABLE `agg_test` (
`k1` int(11) NOT NULL COMMENT "",
`k2` bigint(20) NULL COMMENT "",
`v1` bigint(20) REPLACE NULL COMMENT "",
`v2` bigint(20) REPLACE NULL COMMENT "",
`v3` bigint(20) REPLACE NULL COMMENT ""
) ENGINE=OLAP
AGGREGATE KEY(`k1`, `k2`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY(`k1`, `k2`)
PROPERTIES (
"compression" = "LZ4",
Expand Down Expand Up @@ -174,15 +214,15 @@ None
show create table agg_test;
-- result:
agg_test CREATE TABLE `agg_test` (
`k2` int(11) NOT NULL COMMENT "",
`k2` bigint(20) NULL COMMENT "",
`k1` int(11) NOT NULL COMMENT "",
`v2` bigint(20) REPLACE NULL COMMENT "",
`v1` bigint(20) REPLACE NULL COMMENT "",
`v3` bigint(20) REPLACE NULL COMMENT ""
) ENGINE=OLAP
AGGREGATE KEY(`k2`, `k1`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY(`k1`, `k2`)
PROPERTIES (
"compression" = "LZ4",
Expand All @@ -193,12 +233,6 @@ PROPERTIES (
-- !result
select * from agg_test;
-- result:
1 2 8 2 8
1 3 8 2 8
2 1 10 2 9
2 2 9 2 7
3 1 10 2 9
3 2 9 2 7
-- !result
drop table agg_test;
-- result:
Expand All @@ -222,7 +256,7 @@ CREATE TABLE `agg_test` (
)
AGGREGATE KEY(k1, k2)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY (k2,k1)
PROPERTIES (
"replication_num" = "1",
Expand Down Expand Up @@ -290,7 +324,7 @@ agg_test CREATE TABLE `agg_test` (
) ENGINE=OLAP
AGGREGATE KEY(`k1`, `k2`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY(`k1`, `k2`)
PROPERTIES (
"compression" = "LZ4",
Expand Down Expand Up @@ -326,7 +360,7 @@ agg_test CREATE TABLE `agg_test` (
) ENGINE=OLAP
AGGREGATE KEY(`k2`, `k1`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY(`k1`, `k2`)
PROPERTIES (
"compression" = "LZ4",
Expand Down
60 changes: 48 additions & 12 deletions test/sql/test_sort_key/R/test_sort_key_dup_tbl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use sort_key_test_dup;
CREATE TABLE `dup_test` (
`k1` int(11) NOT NULL COMMENT "",
`k2` int(11) NOT NULL COMMENT "",
`v1` bigint REPLACE NULL COMMENT "",
`v2` bigint REPLACE NULL COMMENT "",
`v3` bigint REPLACE NULL COMMENT ""
`v1` int NULL COMMENT "",
`v2` bigint NULL COMMENT "",
`v3` bigint NULL COMMENT ""
)
DUPLICATE KEY(k1, k2)
COMMENT "OLAP"
Expand All @@ -28,9 +28,9 @@ E: (1064, 'Duplicate sort key column k2 is not allowed.')
CREATE TABLE `dup_test` (
`k1` int(11) NOT NULL COMMENT "",
`k2` int(11) NOT NULL COMMENT "",
`v1` bigint REPLACE NULL COMMENT "",
`v2` bigint REPLACE NULL COMMENT "",
`v3` bigint REPLACE NULL COMMENT ""
`v1` int NULL COMMENT "",
`v2` bigint NULL COMMENT "",
`v3` bigint NULL COMMENT ""
)
DUPLICATE KEY(k1, k2)
COMMENT "OLAP"
Expand Down Expand Up @@ -89,6 +89,42 @@ None
-- !result
show create table dup_test;
-- result:
dup_test CREATE TABLE `dup_test` (
`k1` int(11) NOT NULL COMMENT "",
`k2` int(11) NOT NULL COMMENT "",
`v1` int(11) NULL COMMENT "",
`v2` bigint(20) NULL COMMENT "",
`v3` bigint(20) NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`k1`, `k2`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
ORDER BY(`k2`, `v1`)
PROPERTIES (
"compression" = "LZ4",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "1"
);
-- !result
select * from dup_test;
-- result:
2 1 2 8 8
3 1 2 8 8
1 2 2 10 9
2 2 2 9 7
1 3 2 10 9
2 3 2 9 7
-- !result
alter table dup_test modify column v1 bigint;
-- result:
-- !result
function: wait_alter_table_finish()
-- result:
None
-- !result
show create table dup_test;
-- result:
dup_test CREATE TABLE `dup_test` (
`k1` int(11) NOT NULL COMMENT "",
`k2` int(11) NOT NULL COMMENT "",
Expand Down Expand Up @@ -165,9 +201,9 @@ use sort_key_dup_tbl_with_rollup;
CREATE TABLE `dup_test` (
`k1` int(11) NOT NULL COMMENT "",
`k2` int(11) NOT NULL COMMENT "",
`v1` bigint REPLACE NULL COMMENT "",
`v2` bigint REPLACE NULL COMMENT "",
`v3` bigint REPLACE NULL COMMENT ""
`v1` int NULL COMMENT "",
`v2` bigint NULL COMMENT "",
`v3` bigint NULL COMMENT ""
)
DUPLICATE KEY(k1, k2)
COMMENT "OLAP"
Expand Down Expand Up @@ -200,11 +236,11 @@ insert into dup_test values (1,2,2,10,9),(2,3,2,9,7),(2,1,2,8,8);
-- !result
select * from dup_test;
-- result:
2 1 2 8 8
3 1 2 8 8
1 2 2 10 9
2 2 2 9 7
1 3 2 10 9
2 1 2 8 8
1 2 2 10 9
2 3 2 9 7
-- !result
function: manual_compact("sort_key_dup_tbl_with_rollup", "dup_test")
Expand Down Expand Up @@ -232,7 +268,7 @@ show create table dup_test;
dup_test CREATE TABLE `dup_test` (
`k1` int(11) NOT NULL COMMENT "",
`k2` int(11) NOT NULL COMMENT "",
`v1` bigint(20) NULL COMMENT "",
`v1` int(11) NULL COMMENT "",
`v2` bigint(20) NULL COMMENT "",
`v3` bigint(20) NULL COMMENT ""
) ENGINE=OLAP
Expand Down
66 changes: 50 additions & 16 deletions test/sql/test_sort_key/R/test_sort_key_uni_tbl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CREATE TABLE `uni_test` (
)
UNIQUE KEY(k1, k2)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY (k2)
PROPERTIES (
"replication_num" = "1",
Expand All @@ -33,7 +33,7 @@ CREATE TABLE `uni_test` (
)
UNIQUE KEY(k1, k2)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY (k2,v2)
PROPERTIES (
"replication_num" = "1",
Expand All @@ -51,7 +51,7 @@ CREATE TABLE `uni_test` (
)
UNIQUE KEY(k1, k2)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY (k2,k1,k2)
PROPERTIES (
"replication_num" = "1",
Expand All @@ -70,7 +70,7 @@ CREATE TABLE `uni_test` (
)
UNIQUE KEY(k1, k2)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY (k2,k1)
PROPERTIES (
"replication_num" = "1",
Expand Down Expand Up @@ -142,7 +142,47 @@ uni_test CREATE TABLE `uni_test` (
) ENGINE=OLAP
UNIQUE KEY(`k1`, `k2`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY(`k1`, `k2`)
PROPERTIES (
"compression" = "LZ4",
"fast_schema_evolution" = "true",
"replicated_storage" = "true",
"replication_num" = "1"
);
-- !result
select * from uni_test;
-- result:
1 2 2 10 9
1 3 2 10 9
2 1 2 8 8
2 2 2 9 7
2 3 2 9 7
3 1 2 8 8
-- !result
alter table uni_test modify column k1 bigint key;
-- result:
E: (1064, 'Can not modify distribution column[k1]. index[uni_test]')
-- !result
alter table uni_test modify column k2 bigint key;
-- result:
-- !result
function: wait_alter_table_finish()
-- result:
None
-- !result
show create table uni_test;
-- result:
uni_test CREATE TABLE `uni_test` (
`k1` int(11) NOT NULL COMMENT "",
`k2` bigint(20) NULL COMMENT "",
`v1` bigint(20) NULL COMMENT "",
`v2` bigint(20) NULL COMMENT "",
`v3` bigint(20) NULL COMMENT ""
) ENGINE=OLAP
UNIQUE KEY(`k1`, `k2`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY(`k1`, `k2`)
PROPERTIES (
"compression" = "LZ4",
Expand Down Expand Up @@ -170,15 +210,15 @@ None
show create table uni_test;
-- result:
uni_test CREATE TABLE `uni_test` (
`k2` int(11) NOT NULL COMMENT "",
`k2` bigint(20) NULL COMMENT "",
`k1` int(11) NOT NULL COMMENT "",
`v2` bigint(20) NULL COMMENT "",
`v1` bigint(20) NULL COMMENT "",
`v3` bigint(20) NULL COMMENT ""
) ENGINE=OLAP
UNIQUE KEY(`k2`, `k1`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY(`k1`, `k2`)
PROPERTIES (
"compression" = "LZ4",
Expand All @@ -189,12 +229,6 @@ PROPERTIES (
-- !result
select * from uni_test;
-- result:
1 2 8 2 8
1 3 8 2 8
2 1 10 2 9
2 2 9 2 7
3 1 10 2 9
3 2 9 2 7
-- !result
drop table uni_test;
-- result:
Expand All @@ -218,7 +252,7 @@ CREATE TABLE `uni_test` (
)
UNIQUE KEY(k1, k2)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY (k2,k1)
PROPERTIES (
"replication_num" = "1",
Expand Down Expand Up @@ -285,7 +319,7 @@ uni_test CREATE TABLE `uni_test` (
) ENGINE=OLAP
UNIQUE KEY(`k1`, `k2`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY(`k1`, `k2`)
PROPERTIES (
"compression" = "LZ4",
Expand Down Expand Up @@ -321,7 +355,7 @@ uni_test CREATE TABLE `uni_test` (
) ENGINE=OLAP
UNIQUE KEY(`k2`, `k1`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`k1`, `k2`) BUCKETS 1
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
ORDER BY(`k1`, `k2`)
PROPERTIES (
"compression" = "LZ4",
Expand Down
Loading

0 comments on commit 7944461

Please sign in to comment.