diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java index a90a4efa485733..280ec3e82c3d38 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java @@ -512,18 +512,12 @@ public void rebuildDistributionInfo() { return; } HashDistributionInfo distributionInfo = (HashDistributionInfo) defaultDistributionInfo; - Set originalColumnsNames = - distributionInfo.getDistributionColumns() - .stream() - .map(Column::getName) - .collect(Collectors.toSet()); - - List newDistributionColumns = getBaseSchema() + List newDistributionColumns = distributionInfo.getDistributionColumns() .stream() - .filter(column -> originalColumnsNames.contains(column.getName())) + .map(Column::getName) + .map(this::getBaseColumn) .map(Column::new) .collect(Collectors.toList()); - distributionInfo.setDistributionColumns(newDistributionColumns); getPartitions() .stream() diff --git a/regression-test/data/schema_change_p0/test_random_ordered_bucket_columns.out b/regression-test/data/schema_change_p0/test_random_ordered_bucket_columns.out new file mode 100644 index 00000000000000..e59e71b86c7afe --- /dev/null +++ b/regression-test/data/schema_change_p0/test_random_ordered_bucket_columns.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +2025-07-29 0 1 2 3 + +-- !sql -- +2025-07-29 0 1 2 3 0 + diff --git a/regression-test/suites/schema_change_p0/test_random_ordered_bucket_columns.groovy b/regression-test/suites/schema_change_p0/test_random_ordered_bucket_columns.groovy new file mode 100644 index 00000000000000..a085659588228f --- /dev/null +++ b/regression-test/suites/schema_change_p0/test_random_ordered_bucket_columns.groovy @@ -0,0 +1,61 @@ +// 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_random_ordered_bucket_columns') { + def tblName = "test_random_ordered_bucket_columns" + sql """ DROP TABLE IF EXISTS ${tblName}; """ + sql """ + CREATE TABLE IF NOT EXISTS ${tblName} + ( + k1 DATE, + k2 INT DEFAULT '10', + k3 bigint, + k4 VARCHAR(32) DEFAULT '', + v1 BIGINT DEFAULT '0' + ) + UNIQUE KEY(k1, k2, k3, k4) + DISTRIBUTED BY HASH(k3, k4, k1, k2) BUCKETS 5 + PROPERTIES("replication_num" = "1", "light_schema_change" = "true"); + """ + + // show create table differs in local and cloud mode, this behavior is verified + // qt_sql """ SHOW CREATE TABLE ${tblName} """ + + sql """ INSERT INTO ${tblName} VALUES("2025-07-29", 0, 1, "2", 3) """ + + sql """ INSERT INTO ${tblName} VALUES("2025-07-29", 0, 1, "2", 3) """ + + sql """ SYNC """ + + qt_sql """ SELECT * FROM ${tblName} """ + + sql """ ALTER TABLE ${tblName} ADD COLUMN v2 BIGINT DEFAULT '1' """ + + + // sql """ SYNC """ + + // show create table differs in local and cloud mode, this behavior is verified + // qt_sql """ SHOW CREATE TABLE ${tblName} """ + + 30.times { index -> + sql """ INSERT INTO ${tblName} VALUES("2025-07-29", 0, 1, "2", 3, 0) """ + } + + sql """ SYNC """ + + qt_sql """ SELECT * FROM ${tblName} """ +}