diff --git a/fe/fe-core/src/main/java/com/starrocks/common/util/DynamicPartitionUtil.java b/fe/fe-core/src/main/java/com/starrocks/common/util/DynamicPartitionUtil.java index f95f002c8ef93..4a405bc832dc6 100644 --- a/fe/fe-core/src/main/java/com/starrocks/common/util/DynamicPartitionUtil.java +++ b/fe/fe-core/src/main/java/com/starrocks/common/util/DynamicPartitionUtil.java @@ -299,11 +299,6 @@ public static Map analyzeDynamicPartition(Map pr checkBuckets(bucketsValue); properties.remove(DynamicPartitionProperty.BUCKETS); analyzedProperties.put(DynamicPartitionProperty.BUCKETS, bucketsValue); - } else { - String bucketsValue = "0"; - checkBuckets(bucketsValue); - properties.remove(DynamicPartitionProperty.BUCKETS); - analyzedProperties.put(DynamicPartitionProperty.BUCKETS, bucketsValue); } if (properties.containsKey(DynamicPartitionProperty.ENABLE)) { String enableValue = properties.get(DynamicPartitionProperty.ENABLE); @@ -430,10 +425,14 @@ public static void checkAndSetDynamicPartitionProperty(OlapTable olapTable, Map< TableProperty tableProperty = olapTable.getTableProperty(); if (tableProperty != null) { tableProperty.modifyTableProperties(dynamicPartitionProperties); - tableProperty.buildDynamicProperty(); } else { - olapTable.setTableProperty(new TableProperty(dynamicPartitionProperties).buildDynamicProperty()); + tableProperty = new TableProperty(dynamicPartitionProperties); + olapTable.setTableProperty(tableProperty); + } + if (!tableProperty.getProperties().containsKey(DynamicPartitionProperty.BUCKETS)) { + tableProperty.modifyTableProperties(DynamicPartitionProperty.BUCKETS, "0"); } + tableProperty.buildDynamicProperty(); } } diff --git a/fe/fe-core/src/test/java/com/starrocks/analysis/CreateTableAutoTabletTest.java b/fe/fe-core/src/test/java/com/starrocks/analysis/CreateTableAutoTabletTest.java index ec75100c3de0b..f1ccdfb69da9f 100644 --- a/fe/fe-core/src/test/java/com/starrocks/analysis/CreateTableAutoTabletTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/analysis/CreateTableAutoTabletTest.java @@ -162,6 +162,56 @@ public void test1AutoTabletWithDynamicPartition() throws Exception { Assert.assertEquals(bucketNum, 20); } + @Test + public void test1AutoTabletWithModifyDynamicPartitionProperty() throws Exception { + PseudoCluster cluster = PseudoCluster.getInstance(); + cluster.runSql("db_for_auto_tablets", + " CREATE TABLE test_modify_dynamic_partition_property (" + + " k1 date," + + " k2 int(11)," + + " k3 smallint(6)," + + " v1 varchar(2048)," + + " v2 datetime" + + " ) ENGINE=OLAP" + + " DUPLICATE KEY(k1, k2, k3) " + + " PARTITION BY RANGE(k1)" + + " (PARTITION p20230306 VALUES [('2023-03-06'), ('2023-03-07')))" + + " DISTRIBUTED BY HASH(k2) BUCKETS 10" + + " PROPERTIES (" + + " 'replication_num' = '1'," + + " 'dynamic_partition.enable' = 'true'," + + " 'dynamic_partition.time_unit' = 'DAY'," + + " 'dynamic_partition.time_zone' = 'Asia/Shanghai'," + + " 'dynamic_partition.start' = '-1'," + + " 'dynamic_partition.end' = '3'," + + " 'dynamic_partition.buckets' = '3'," + + " 'dynamic_partition.prefix' = 'p');"); + Thread.sleep(1000); // wait for the dynamic partition created + Database db = GlobalStateMgr.getCurrentState().getDb("db_for_auto_tablets"); + if (db == null) { + return; + } + + OlapTable table = (OlapTable) db.getTable("test_modify_dynamic_partition_property"); + if (table == null) { + return; + } + + cluster.runSql("db_for_auto_tablets", "ALTER TABLE test_modify_dynamic_partition_property SET ('dynamic_partition.enable' = 'false')"); + cluster.runSql("db_for_auto_tablets", "ALTER TABLE test_modify_dynamic_partition_property ADD PARTITION p20230306 VALUES [('2023-03-06'), ('2023-03-07'))"); + cluster.runSql("db_for_auto_tablets", "ALTER TABLE test_modify_dynamic_partition_property SET ('dynamic_partition.enable' = 'true')"); + + int bucketNum = 0; + db.readLock(); + try { + Partition partition = table.getPartition("p20230306"); + bucketNum = partition.getDistributionInfo().getBucketNum(); + } finally { + db.readUnlock(); + } + Assert.assertEquals(bucketNum, 20); + } + @Test public void test1AutoTabletWithColocate() throws Exception { PseudoCluster cluster = PseudoCluster.getInstance();