Skip to content

Commit

Permalink
[fix](fe) Key column varchar length change should't light schema change
Browse files Browse the repository at this point in the history
  • Loading branch information
SWJTU-ZhangLei committed Dec 11, 2023
1 parent 1bbc54d commit 3402dbc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,13 @@ private boolean processModifyColumn(ModifyColumnClause alterClause, OlapTable ol
if (columnPos == null && col.getDataType() == PrimitiveType.VARCHAR
&& modColumn.getDataType() == PrimitiveType.VARCHAR) {
col.checkSchemaChangeAllowed(modColumn);
lightSchemaChange = olapTable.getEnableLightSchemaChange();
// If col and modColumn is not key, it allow light schema change,
// of course, olapTable has been enable light schema change
if (modColumn.isKey() || col.isKey()) {
lightSchemaChange = false;
} else {
lightSchemaChange = olapTable.getEnableLightSchemaChange();
}
}
if (col.isClusterKey()) {
throw new DdlException("Can not modify cluster key column: " + col.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ public void addPartition(Database db, String tableName, AddPartitionClause addPa
if (!hashDistributionInfo.sameDistributionColumns((HashDistributionInfo) defaultDistributionInfo)) {
throw new DdlException("Cannot assign hash distribution with different distribution cols. "
+ "new is: " + hashDistributionInfo.getDistributionColumns() + " default is: "
+ ((HashDistributionInfo) distributionInfo).getDistributionColumns());
+ ((HashDistributionInfo) defaultDistributionInfo).getDistributionColumns());
}
} else if (distributionInfo.getType() == DistributionInfoType.RANDOM) {
RandomDistributionInfo randomDistributionInfo = (RandomDistributionInfo) distributionInfo;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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_varchar_schema_change_with_distribution") {
def tableName = "test_varchar_schema_change_with_distribution"
sql """ DROP TABLE IF EXISTS ${tableName} FORCE;"""

sql """
CREATE TABLE ${tableName}
(
dt datetime NOT NULL COMMENT '分区日期',
citycode SMALLINT,
watts_range VARCHAR(20),
pv BIGINT SUM DEFAULT '0'
)
AGGREGATE KEY(dt, citycode, watts_range)
PARTITION BY RANGE(dt)()
DISTRIBUTED BY HASH(dt, watts_range) BUCKETS 1
PROPERTIES (
"dynamic_partition.enable"="true",
"dynamic_partition.end"="3",
"dynamic_partition.buckets"="1",
"dynamic_partition.start"="-3",
"dynamic_partition.prefix"="p",
"dynamic_partition.time_unit"="HOUR",
"dynamic_partition.create_history_partition"="true",
"dynamic_partition.replication_allocation" = "tag.location.default: 1"
);
"""

test {
sql """ alter table ${tableName} modify column watts_range varchar(30) """
exception "Can not modify distribution column"
}

sql """ DROP TABLE IF EXISTS ${tableName} FORCE;"""

}

0 comments on commit 3402dbc

Please sign in to comment.