Skip to content

Commit

Permalink
[BugFix] Fix bug invalid field name (#33059)
Browse files Browse the repository at this point in the history
Signed-off-by: Astralidea <[email protected]>
  • Loading branch information
Astralidea authored Oct 18, 2023
1 parent 20ce8b8 commit 52ecbe0
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ private Set<String> collectModifiedColumnsForRelatedMVs(@NotNull LakeTable tbl)
// modify column
for (Column col : shadowSchema) {
if (col.isNameWithPrefix(SchemaChangeHandler.SHADOW_NAME_PRFIX)) {
modifiedColumns.add(col.getNameWithoutPrefix(SchemaChangeHandler.SHADOW_NAME_PRFIX));
modifiedColumns.add(col.getNameWithoutPrefix(SchemaChangeHandler.SHADOW_NAME_PRFIX, col.getName()));
}
}
} else if (shadowSchema.size() < originSchema.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ private Set<String> collectModifiedColumnsForRelatedMVs(OlapTable tbl) {
// modify column
for (Column col : shadowSchema) {
if (col.isNameWithPrefix(SchemaChangeHandler.SHADOW_NAME_PRFIX)) {
modifiedColumns.add(col.getNameWithoutPrefix(SchemaChangeHandler.SHADOW_NAME_PRFIX));
modifiedColumns.add(col.getNameWithoutPrefix(SchemaChangeHandler.SHADOW_NAME_PRFIX, col.getName()));
}
}
} else if (shadowSchema.size() < originSchema.size()) {
Expand Down
4 changes: 2 additions & 2 deletions fe/fe-core/src/main/java/com/starrocks/catalog/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ public String getName() {
return this.name;
}

public String getNameWithoutPrefix(String prefix) {
if (isNameWithPrefix(prefix)) {
public String getNameWithoutPrefix(String prefix, String name) {
if (name.startsWith(prefix)) {
return name.substring(prefix.length());
}
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ protected void toThrift(TPlanNode msg) {
if (indexMeta != null) {
for (Column col : olapTable.getSchemaByIndexId(selectedIndexId)) {
TColumn tColumn = col.toThrift();
tColumn.setColumn_name(col.getNameWithoutPrefix(SchemaChangeHandler.SHADOW_NAME_PRFIX));
tColumn.setColumn_name(col.getNameWithoutPrefix(SchemaChangeHandler.SHADOW_NAME_PRFIX, tColumn.column_name));
col.setIndexFlag(tColumn, olapTable.getIndexes(), bfColumns);
columnsDesc.add(tColumn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public static TOlapTableSchemaParam createSchema(long dbId, OlapTable table, Tup
columns.addAll(indexMeta.getSchema().stream().map(Column::getPhysicalName).collect(Collectors.toList()));
for (Column column : indexMeta.getSchema()) {
TColumn tColumn = column.toThrift();
tColumn.setColumn_name(column.getNameWithoutPrefix(SchemaChangeHandler.SHADOW_NAME_PRFIX));
tColumn.setColumn_name(column.getNameWithoutPrefix(SchemaChangeHandler.SHADOW_NAME_PRFIX, tColumn.column_name));
column.setIndexFlag(tColumn, table.getIndexes(), table.getBfColumns());
columnsDesc.add(tColumn);
}
Expand Down
14 changes: 14 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/server/LocalMetastore.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -3790,6 +3791,19 @@ public void renameColumn(Database db, Table table, ColumnRenameClause renameClau
column.renameColumn(newColName);
nameToColumn.put(newColName, column);

Set<String> bfColumns = olapTable.getBfColumns();
if (bfColumns != null) {
Iterator<String> iterator = bfColumns.iterator();
while (iterator.hasNext()) {
String bfColumn = iterator.next();
if (bfColumn.equalsIgnoreCase(colName)) {
iterator.remove();
bfColumns.add(newColName);
break;
}
}
}

DistributionInfo distributionInfo = olapTable.getDefaultDistributionInfo();
if (distributionInfo.getType() == DistributionInfo.DistributionInfoType.HASH) {
HashDistributionInfo hashDistributionInfo = (HashDistributionInfo) distributionInfo;
Expand Down
80 changes: 80 additions & 0 deletions test/sql/test_column_rename/R/test_column_rename2
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
-- name: test_column_rename2
CREATE TABLE `site_access` (
`event_day` date NULL COMMENT "",
`site_id` int(11) NULL DEFAULT "10" COMMENT "",
`city_code` varchar(100) NULL COMMENT "",
`user_name` varchar(32) NULL DEFAULT "" COMMENT "",
`pv` bigint(20) NULL DEFAULT "0" COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`event_day`, `site_id`, `city_code`, `user_name`)
PARTITION BY RANGE(`event_day`)
(PARTITION p20231018 VALUES [("2023-10-18"), ("2023-10-19")),
PARTITION p20231019 VALUES [("2023-10-19"), ("2023-10-20")),
PARTITION p20231020 VALUES [("2023-10-20"), ("2023-10-21")),
PARTITION p20231021 VALUES [("2023-10-21"), ("2023-10-22")))
DISTRIBUTED BY HASH(`event_day`, `site_id`)
PROPERTIES (
"replication_num" = "1"
);
-- result:
-- !result
INSERT INTO `site_access` (`event_day`, `site_id`, `city_code`, `user_name`, `pv`)
VALUES ('2023-10-18', 10, 'SH', 'username_example', 100);
-- result:
-- !result
alter table site_access rename column event_day to day;
-- result:
-- !result
alter table site_access rename column user_name to user;
-- result:
-- !result
select * from site_access;
-- result:
2023-10-18 10 SH username_example 100
-- !result
CREATE TABLE bf_table
(
k1 BIGINT,
k2 LARGEINT,
v1 VARCHAR(2048) REPLACE,
v2 SMALLINT DEFAULT "10"
)
ENGINE = olap
PRIMARY KEY(k1, k2)
DISTRIBUTED BY HASH (k1, k2)
PROPERTIES("bloom_filter_columns" = "k1,k2");
-- result:
-- !result
INSERT INTO `bf_table` (`k1`, `k2`, `v1`, `v2`)
VALUES (1, 1000000000000000, 'example_string', 20);
-- result:
-- !result
desc bf_table;
-- result:
k1 bigint NO true None BLOOM_FILTER
k2 largeint NO true None BLOOM_FILTER
v1 varchar(2048) YES false None
v2 smallint YES false 10
-- !result
alter table bf_table rename column k1 to k3;
-- result:
-- !result
select * from bf_table;
-- result:
1 1000000000000000 example_string 20
-- !result
INSERT INTO `bf_table` (`k3`, `k2`, `v1`, `v2`)
VALUES (1, 1000000000000000, 'example_string', 20);
-- result:
-- !result
desc bf_table;
-- result:
k3 bigint NO true None BLOOM_FILTER
k2 largeint NO true None BLOOM_FILTER
v1 varchar(2048) YES false None
v2 smallint YES false 10
-- !result
select * from bf_table;
-- result:
1 1000000000000000 example_string 20
-- !result
43 changes: 43 additions & 0 deletions test/sql/test_column_rename/T/test_column_rename2
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- name: test_column_rename2
CREATE TABLE `site_access` (
`event_day` date NULL COMMENT "",
`site_id` int(11) NULL DEFAULT "10" COMMENT "",
`city_code` varchar(100) NULL COMMENT "",
`user_name` varchar(32) NULL DEFAULT "" COMMENT "",
`pv` bigint(20) NULL DEFAULT "0" COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`event_day`, `site_id`, `city_code`, `user_name`)
PARTITION BY RANGE(`event_day`)
(PARTITION p20231018 VALUES [("2023-10-18"), ("2023-10-19")),
PARTITION p20231019 VALUES [("2023-10-19"), ("2023-10-20")),
PARTITION p20231020 VALUES [("2023-10-20"), ("2023-10-21")),
PARTITION p20231021 VALUES [("2023-10-21"), ("2023-10-22")))
DISTRIBUTED BY HASH(`event_day`, `site_id`)
PROPERTIES (
"replication_num" = "1"
);
INSERT INTO `site_access` (`event_day`, `site_id`, `city_code`, `user_name`, `pv`)
VALUES ('2023-10-18', 10, 'SH', 'username_example', 100);
alter table site_access rename column event_day to day;
alter table site_access rename column user_name to user;
select * from site_access;
CREATE TABLE bf_table
(
k1 BIGINT,
k2 LARGEINT,
v1 VARCHAR(2048) REPLACE,
v2 SMALLINT DEFAULT "10"
)
ENGINE = olap
PRIMARY KEY(k1, k2)
DISTRIBUTED BY HASH (k1, k2)
PROPERTIES("bloom_filter_columns" = "k1,k2");
INSERT INTO `bf_table` (`k1`, `k2`, `v1`, `v2`)
VALUES (1, 1000000000000000, 'example_string', 20);
desc bf_table;
alter table bf_table rename column k1 to k3;
select * from bf_table;
INSERT INTO `bf_table` (`k3`, `k2`, `v1`, `v2`)
VALUES (1, 1000000000000000, 'example_string', 20);
desc bf_table;
select * from bf_table;

0 comments on commit 52ecbe0

Please sign in to comment.