diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java index d6ab6a972e1d39b..88f6b7718c81c42 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java @@ -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()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index 3a080d2b28d1e88..d4943e6cb80adc1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -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; diff --git a/regression-test/suites/schema_change_p0/test_varchar_schema_change_with_distribution.groovy b/regression-test/suites/schema_change_p0/test_varchar_schema_change_with_distribution.groovy new file mode 100644 index 000000000000000..5068f0aec438b0b --- /dev/null +++ b/regression-test/suites/schema_change_p0/test_varchar_schema_change_with_distribution.groovy @@ -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;""" + +} \ No newline at end of file