Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 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 @@ -4729,7 +4729,7 @@ public void modifyTableColocate(Database db, OlapTable table, String assignedGro
GroupId groupId = null;
if (!Strings.isNullOrEmpty(assignedGroup)) {
String fullAssignedGroupName = GroupId.getFullGroupName(db.getId(), assignedGroup);
//When the new name is the same as the old name, we return it to prevent npe
// When the new name is the same as the old name, we return it to prevent npe
if (!Strings.isNullOrEmpty(oldGroup)) {
String oldFullGroupName = GroupId.getFullGroupName(db.getId(), oldGroup);
if (oldFullGroupName.equals(fullAssignedGroupName)) {
Expand Down Expand Up @@ -5346,7 +5346,8 @@ public void modifyDefaultDistributionBucketNum(Database db, OlapTable olapTable,
throw new DdlException("Cannot change default bucket number of colocate table.");
}

if (olapTable.getPartitionInfo().getType() != PartitionType.RANGE) {
if (olapTable.getPartitionInfo().getType() != PartitionType.RANGE
&& olapTable.getPartitionInfo().getType() != PartitionType.LIST) {
throw new DdlException("Only support change partitioned table's distribution.");
}

Expand Down
6 changes: 6 additions & 0 deletions regression-test/data/alter_p1/test_alter_modify_bucket.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
1 1 2024-08-20 21 21:00:00 2024-08-20 1724158800000
2 2 2024-08-20 22 22:00:00 2024-08-20 1724162400000
3 3 2024-08-20 23 23:00:00 2024-08-20 1724166000000

86 changes: 86 additions & 0 deletions regression-test/suites/alter_p1/test_alter_modify_bucket.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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_alter_modify_bucket') {
def tbl = 'test_alter_modify_bucket_tbl'
sql "DROP TABLE IF EXISTS ${tbl} FORCE"
sql """
CREATE TABLE ${tbl} (
`id1` VARCHAR(255) NULL COMMENT 'id1',
`id2` VARCHAR(255) NULL COMMENT 'id2',
`dt` VARCHAR(255) NOT NULL COMMENT '日期分区',
`hr` VARCHAR(255) NOT NULL COMMENT '小时分区',
`event_time` VARCHAR(255) NULL COMMENT '事件时间',
`event_date` VARCHAR(255) NULL COMMENT '事件日期',
`event_ts` VARCHAR(256) NULL COMMENT '事件发生时间戳(毫秒)'
) ENGINE=OLAP
UNIQUE KEY(`id1`,`id2`,`dt`,`hr`)
COMMENT 'xxx'
PARTITION BY LIST(`dt`, `hr`) (
PARTITION p2024082021 VALUES IN (("2024-08-20", "21"))
)
DISTRIBUTED BY HASH(`id1`,`id2`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);
"""

// check existed partition buckets
List<List<Object>> res = sql """
SHOW PARTITIONS FROM ${tbl}
"""
assertEquals(res[0][8],"1")

// add new partition and insert values
sql """
ALTER TABLE ${tbl} ADD PARTITION IF NOT EXISTS p2024082022 VALUES IN (("2024-08-20", "22"))
"""
sql """
INSERT INTO ${tbl} VALUES("1","1","2024-08-20","21","21:00:00","2024-08-20","1724158800000")
"""
sql """
INSERT INTO ${tbl} VALUES("2","2","2024-08-20","22","22:00:00","2024-08-20","1724162400000")
"""

// modify table default buckets
sql """
ALTER TABLE ${tbl} MODIFY DISTRIBUTION DISTRIBUTED BY HASH(`id1`,`id2`) BUCKETS 2
"""

// add new partition after modify tablet default buckets and insert values
sql """
ALTER TABLE ${tbl} ADD PARTITION IF NOT EXISTS p2024082023 VALUES IN (("2024-08-20", "23"))
"""
sql """
INSERT INTO ${tbl} VALUES("3","3","2024-08-20","23","23:00:00","2024-08-20","1724166000000")
"""

// check all insert values
qt_select """
SELECT * FROM ${tbl} ORDER BY id1,id2
"""

// check all partition buckets
List<List<Object>> res1 = sql """
SHOW PARTITIONS FROM ${tbl} ORDER BY `PartitionName`
"""
assertEquals(res1[0][8],"1")
assertEquals(res1[1][8],"1")
assertEquals(res1[2][8],"2")

sql "DROP TABLE IF EXISTS ${tbl} FORCE"
}