Skip to content

Commit

Permalink
[chore](rename) Forbid renaming partition columns due to this is a bu…
Browse files Browse the repository at this point in the history
…ggy feature
  • Loading branch information
TangSiyang2001 committed Feb 7, 2025
1 parent c04c9c0 commit 63e8218
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 7 deletions.
24 changes: 17 additions & 7 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -5150,6 +5150,13 @@ private void renameColumn(Database db, OlapTable table, String colName,
throw new DdlException("Same column name");
}

// @NOTE: Rename partition columns should also rename column names in partition expressions
// but this is not implemented currently. Therefore, forbid renaming partition columns temporarily.
PartitionInfo partitionInfo = table.getPartitionInfo();
if (partitionInfo.getPartitionColumns().stream().anyMatch(c -> c.getName().equalsIgnoreCase(colName))) {
throw new DdlException("Renaming partition columns has problems, forbidden in current Doris version");
}

Map<Long, MaterializedIndexMeta> indexIdToMeta = table.getIndexIdToMeta();
for (Map.Entry<Long, MaterializedIndexMeta> entry : indexIdToMeta.entrySet()) {
// rename column is not implemented for non-light-schema-change table.
Expand Down Expand Up @@ -5209,14 +5216,17 @@ private void renameColumn(Database db, OlapTable table, String colName,
throw new DdlException("Column[" + colName + "] does not exists");
}

// @NOTE: Rename partition columns should also rename column names in partition expressions
// but this is not implemented currently. Therefore, forbid renaming partition columns temporarily.
//
// 2. modify partition key
PartitionInfo partitionInfo = table.getPartitionInfo();
List<Column> partitionColumns = partitionInfo.getPartitionColumns();
for (Column column : partitionColumns) {
if (column.getName().equalsIgnoreCase(colName)) {
column.setName(newColName);
}
}
// PartitionInfo partitionInfo = table.getPartitionInfo();
// List<Column> partitionColumns = partitionInfo.getPartitionColumns();
// for (Column column : partitionColumns) {
// if (column.getName().equalsIgnoreCase(colName)) {
// column.setName(newColName);
// }
//}

// 3. modify index
List<Index> indexes = table.getIndexes();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite("test_rename_partition_column") {
def tblName = "test_rename_partition_column"
sql """DROP TABLE IF EXISTS ${tblName} FORCE; """

sql """
CREATE TABLE `${tblName}`
(
`siteid` INT DEFAULT '10',
`citycode` SMALLINT,
`username` VARCHAR(32) DEFAULT 'test',
`pv` BIGINT SUM DEFAULT '0'
)
AGGREGATE KEY(`siteid`, `citycode`, `username`)
PARTITION BY RANGE(`siteid`)
(
partition `old_p1` values [("1"), ("2")),
partition `old_p2` values [("2"), ("3"))
)
DISTRIBUTED BY HASH(siteid) BUCKETS 1
PROPERTIES (
"replication_num" = "1"
);
"""

test {
sql """ ALTER TABLE ${tblName} RENAME siteid new_siteid """
exception """Renaming partition columns has problems, forbidden in current Doris version"""
}
}

0 comments on commit 63e8218

Please sign in to comment.