From 76e148988ac201829cee796c444aa8c671897e36 Mon Sep 17 00:00:00 2001 From: flynn Date: Mon, 12 Jul 2021 20:28:40 +0800 Subject: [PATCH] Support alter default bucket_num of partitioned olap table (#6023) * Support modify partitioned olap table's bucket num Co-authored-by: EmmyMiao87 <522274284@qq.com> --- .../Data Definition/ALTER TABLE.md | 12 ++- .../Data Definition/ALTER TABLE.md | 10 +++ fe/fe-core/src/main/cup/sql_parser.cup | 4 + .../java/org/apache/doris/alter/Alter.java | 5 ++ .../org/apache/doris/alter/AlterOpType.java | 1 + .../apache/doris/alter/AlterOperations.java | 4 + .../analysis/ModifyDistributionClause.java | 57 +++++++++++++ .../org/apache/doris/catalog/Catalog.java | 79 ++++++++++++++++++- .../doris/catalog/DistributionInfo.java | 5 ++ .../doris/catalog/HashDistributionInfo.java | 5 ++ .../apache/doris/journal/JournalEntity.java | 6 ++ .../org/apache/doris/persist/EditLog.java | 9 +++ ...aultDistributionBucketNumOperationLog.java | 64 +++++++++++++++ .../apache/doris/persist/OperationType.java | 3 + .../org/apache/doris/alter/AlterTest.java | 31 ++++++++ 15 files changed, 292 insertions(+), 3 deletions(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/analysis/ModifyDistributionClause.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/persist/ModifyTableDefaultDistributionBucketNumOperationLog.java diff --git a/docs/en/sql-reference/sql-statements/Data Definition/ALTER TABLE.md b/docs/en/sql-reference/sql-statements/Data Definition/ALTER TABLE.md index 61b1755b0d..044be24af8 100644 --- a/docs/en/sql-reference/sql-statements/Data Definition/ALTER TABLE.md +++ b/docs/en/sql-reference/sql-statements/Data Definition/ALTER TABLE.md @@ -153,7 +153,7 @@ under the License. 3) Only the type of the column can be modified. The other attributes of the column remain as they are (ie other attributes need to be explicitly written in the statement according to the original attribute, see example 8) 4) The partition column cannot be modified 5) The following types of conversions are currently supported (accuracy loss is guaranteed by the user) - TINYINT/SMALLINT/INT/BIGINT/LARGEINT/FLOAT/DOUBLE convert to a wider range of numeric types + TINYINT/SMALLINT/INT/BIGINT/LARGEINT/FLOAT/DOUBLE convert to a wider range of numeric types TINTINT/SMALLINT/INT/BIGINT/LARGEINT/FLOAT/DOUBLE/DECIMAL is converted to VARCHAR VARCHAR supports modification of maximum length Convert VARCHAR/CHAR to TINYINT/SMALLINT/INT/BIGINT/LARGEINT/FLOAT/DOUBLE. @@ -194,7 +194,13 @@ under the License. 2) The sequence_type is used to specify the type of the sequence column, which can be integral and time type 3) Only the orderliness of newly imported data is supported. Historical data cannot be changed   + 9. Modify default buckets number of partition + grammer: + MODIFY DISTRIBUTION DISTRIBUTED BY HASH (k1[,k2 ...]) BUCKETS num + note: + 1)Only support non colocate table with RANGE partition and HASH distribution +   Rename supports modification of the following names: 1. Modify the table name grammar: @@ -369,6 +375,10 @@ under the License. 17. Enable the ability to import in order by the value of the Sequence column ALTER TABLE example_db.my_table ENABLE FEATURE "SEQUENCE_LOAD" WITH PROPERTIES ("function_column.sequence_type" = "Date") + + 18. Modify the default buckets number of example_db.my_table to 50 + + ALTER TABLE example_db.my_table MODIFY DISTRIBUTION DISTRIBUTED BY HASH(k1) BUCKETS 50; [rename] 1. Modify the table named table1 to table2 diff --git a/docs/zh-CN/sql-reference/sql-statements/Data Definition/ALTER TABLE.md b/docs/zh-CN/sql-reference/sql-statements/Data Definition/ALTER TABLE.md index 77bbe4bccf..cd0ddd1935 100644 --- a/docs/zh-CN/sql-reference/sql-statements/Data Definition/ALTER TABLE.md +++ b/docs/zh-CN/sql-reference/sql-statements/Data Definition/ALTER TABLE.md @@ -192,6 +192,12 @@ under the License. 2) sequence_type用来指定sequence列的类型,可以为整型和时间类型 3) 只支持新导入数据的有序性,历史数据无法更改 + 9. 修改表的分区默认分桶数 + 语法: + MODIFY DISTRIBUTION DISTRIBUTED BY HASH (k1[,k2 ...]) BUCKETS num + 注意: + 1)只能用在分区类型为RANGE,采用哈希分桶的非colocate表 + rename 支持对以下名称进行修改: 1. 修改表名 @@ -364,6 +370,10 @@ under the License. ALTER TABLE example_db.my_table ENABLE FEATURE "SEQUENCE_LOAD" WITH PROPERTIES ("function_column.sequence_type" = "Date") + 18. 将表的默认分桶数改为50 + + ALTER TABLE example_db.my_table MODIFY DISTRIBUTION DISTRIBUTED BY HASH(k1) BUCKETS 50; + [rename] 1. 将名为 table1 的表修改为 table2 ALTER TABLE table1 RENAME table2; diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup index d3610db356..8e509aec61 100644 --- a/fe/fe-core/src/main/cup/sql_parser.cup +++ b/fe/fe-core/src/main/cup/sql_parser.cup @@ -1012,6 +1012,10 @@ alter_table_clause ::= {: RESULT = new EnableFeatureClause(featureName, properties); :} + | KW_MODIFY KW_DISTRIBUTION opt_distribution:distribution + {: + RESULT = new ModifyDistributionClause(distribution); + :} ; opt_enable_feature_properties ::= diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java index bfc6df1c3c..a7391a9547 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java @@ -26,6 +26,7 @@ import org.apache.doris.analysis.ColumnRenameClause; import org.apache.doris.analysis.CreateMaterializedViewStmt; import org.apache.doris.analysis.DropMaterializedViewStmt; import org.apache.doris.analysis.DropPartitionClause; +import org.apache.doris.analysis.ModifyDistributionClause; import org.apache.doris.analysis.ModifyPartitionClause; import org.apache.doris.analysis.ModifyTablePropertiesClause; import org.apache.doris.analysis.PartitionRenameClause; @@ -191,6 +192,10 @@ public class Alter { processReplaceTable(db, olapTable, alterClauses); } else if (currentAlterOps.contains(AlterOpType.MODIFY_TABLE_PROPERTY_SYNC)) { needProcessOutsideTableLock = true; + } else if (currentAlterOps.contains(AlterOpType.MODIFY_DISTRIBUTION)) { + Preconditions.checkState(alterClauses.size() == 1); + AlterClause alterClause = alterClauses.get(0); + Catalog.getCurrentCatalog().modifyDefaultDistributionBucketNum(db, olapTable, (ModifyDistributionClause) alterClause); } else { throw new DdlException("Invalid alter operations: " + currentAlterOps); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/AlterOpType.java b/fe/fe-core/src/main/java/org/apache/doris/alter/AlterOpType.java index 8513bd4c4f..8ceb91836d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/AlterOpType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/AlterOpType.java @@ -37,6 +37,7 @@ public enum AlterOpType { ALTER_OTHER, ENABLE_FEATURE, REPLACE_TABLE, + MODIFY_DISTRIBUTION, INVALID_OP; // INVALID_OP must be the last one // true means 2 operations have no conflict. diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/AlterOperations.java b/fe/fe-core/src/main/java/org/apache/doris/alter/AlterOperations.java index ed80392195..dc9d42b81a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/AlterOperations.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/AlterOperations.java @@ -80,6 +80,10 @@ public class AlterOperations { return currentOps.contains(AlterOpType.REPLACE_TABLE); } + public boolean hasModifyBucketNumOp() { + return currentOps.contains(AlterOpType.MODIFY_DISTRIBUTION); + } + public boolean contains(AlterOpType op) { return currentOps.contains(op); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ModifyDistributionClause.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ModifyDistributionClause.java new file mode 100644 index 0000000000..688a87b3f9 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ModifyDistributionClause.java @@ -0,0 +1,57 @@ +// 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. + +package org.apache.doris.analysis; + +import org.apache.doris.alter.AlterOpType; +import org.apache.doris.common.AnalysisException; + +// clause which is used to modify the default bucket number of hash distribution +// MODIFY DISTRIBUTION DISTRIBUTED BY HASH('key') BUCKETS number; +public class ModifyDistributionClause extends AlterTableClause { + + private DistributionDesc distributionDesc; + + public DistributionDesc getDistributionDesc() { + return distributionDesc; + } + + public ModifyDistributionClause(DistributionDesc distributionDesc) { + super(AlterOpType.MODIFY_DISTRIBUTION); + this.distributionDesc = distributionDesc; + this.needTableStable = false; + } + + @Override + public void analyze(Analyzer analyzer) throws AnalysisException { + } + + @Override + public String toSql() { + StringBuilder sb = new StringBuilder(); + sb.append("MODIFY DISTRIBUTION "); + if (distributionDesc != null) { + sb.append(distributionDesc.toSql()); + } + return sb.toString(); + } + + @Override + public String toString() { + return toSql(); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java index 6cd57aefb8..56cc504bdb 100755 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java @@ -82,6 +82,7 @@ import org.apache.doris.analysis.TruncateTableStmt; import org.apache.doris.analysis.UninstallPluginStmt; import org.apache.doris.analysis.UserDesc; import org.apache.doris.analysis.UserIdentity; +import org.apache.doris.analysis.ModifyDistributionClause; import org.apache.doris.backup.BackupHandler; import org.apache.doris.catalog.ColocateTableIndex.GroupId; import org.apache.doris.catalog.Database.DbState; @@ -174,6 +175,7 @@ import org.apache.doris.persist.DropPartitionInfo; import org.apache.doris.persist.EditLog; import org.apache.doris.persist.GlobalVarPersistInfo; import org.apache.doris.persist.ModifyPartitionInfo; +import org.apache.doris.persist.ModifyTableDefaultDistributionBucketNumOperationLog; import org.apache.doris.persist.ModifyTablePropertyOperationLog; import org.apache.doris.persist.OperationType; import org.apache.doris.persist.PartitionPersistInfo; @@ -2196,7 +2198,7 @@ public class Catalog { return checksum; } - public long saveResources(DataOutputStream out, long checksum) throws IOException { + public long saveResources(DataOutputStream out, long checksum) throws IOException { Catalog.getCurrentCatalog().getResourceMgr().write(out); return checksum; } @@ -5580,6 +5582,80 @@ public class Catalog { } } + public void modifyDefaultDistributionBucketNum(Database db, OlapTable olapTable, ModifyDistributionClause modifyDistributionClause) throws DdlException { + olapTable.writeLock(); + + try { + if (olapTable.isColocateTable()) { + throw new DdlException("Cannot change default bucket number of colocate table."); + } + + if (olapTable.getPartitionInfo().getType() != PartitionType.RANGE) { + throw new DdlException("Only support change partitioned table's distribution."); + } + + DistributionInfo defaultDistributionInfo = olapTable.getDefaultDistributionInfo(); + if (defaultDistributionInfo.getType() != DistributionInfoType.HASH) { + throw new DdlException("Cannot change default bucket number of distribution type " + defaultDistributionInfo.getType()); + } + + DistributionDesc distributionDesc = modifyDistributionClause.getDistributionDesc(); + + DistributionInfo distributionInfo = null; + + List baseSchema = olapTable.getBaseSchema(); + + if (distributionDesc != null) { + distributionInfo = distributionDesc.toDistributionInfo(baseSchema); + // for now. we only support modify distribution's bucket num + if (distributionInfo.getType() != DistributionInfoType.HASH) { + throw new DdlException("Cannot change distribution type to " + distributionInfo.getType()); + } + + HashDistributionInfo hashDistributionInfo = (HashDistributionInfo) distributionInfo; + List newDistriCols = hashDistributionInfo.getDistributionColumns(); + List defaultDistriCols = ((HashDistributionInfo) defaultDistributionInfo).getDistributionColumns(); + if (!newDistriCols.equals(defaultDistriCols)) { + throw new DdlException("Cannot assign hash distribution with different distribution cols. " + + "default is: " + defaultDistriCols); + } + + int bucketNum = hashDistributionInfo.getBucketNum(); + if (bucketNum <= 0) { + throw new DdlException("Cannot assign hash distribution buckets less than 1"); + } + + defaultDistributionInfo.setBucketNum(bucketNum); + + ModifyTableDefaultDistributionBucketNumOperationLog info = new ModifyTableDefaultDistributionBucketNumOperationLog(db.getId(), olapTable.getId(), bucketNum); + editLog.logModifyDefaultDistributionBucketNum(info); + LOG.info("modify table[{}] default bucket num to {}", olapTable.getName(), bucketNum); + } + } finally { + olapTable.writeUnlock(); + } + } + + public void replayModifyTableDefaultDistributionBucketNum(short opCode, ModifyTableDefaultDistributionBucketNumOperationLog info) { + long dbId = info.getDbId(); + long tableId = info.getTableId(); + int bucketNum = info.getBucketNum(); + + Database db = getDb(dbId); + OlapTable olapTable = (OlapTable) db.getTable(tableId); + if (olapTable == null) { + LOG.warn("table {} does not exist when replaying modify table default distribution bucket number log. db: {}", tableId, dbId); + return; + } + olapTable.writeLock(); + try { + DistributionInfo defaultDistributionInfo = olapTable.getDefaultDistributionInfo(); + defaultDistributionInfo.setBucketNum(bucketNum); + } finally { + olapTable.writeUnlock(); + } + } + /* * used for handling AlterClusterStmt * (for client is the ALTER CLUSTER command). @@ -7026,4 +7102,3 @@ public class Catalog { } } } - diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/DistributionInfo.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/DistributionInfo.java index 4a22ddd35b..33d883d64a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/DistributionInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/DistributionInfo.java @@ -65,6 +65,11 @@ public abstract class DistributionInfo implements Writable { throw new NotImplementedException("not implemented"); } + public void setBucketNum(int bucketNum) { + // should override in sub class + throw new NotImplementedException("not implemented"); + } + public DistributionDesc toDistributionDesc() { throw new NotImplementedException(); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/HashDistributionInfo.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/HashDistributionInfo.java index 53cc3610b6..9fc175cee7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/HashDistributionInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/HashDistributionInfo.java @@ -59,6 +59,11 @@ public class HashDistributionInfo extends DistributionInfo { return bucketNum; } + @Override + public void setBucketNum(int bucketNum) { + this.bucketNum = bucketNum; + } + public void write(DataOutput out) throws IOException { super.write(out); int columnCount = distributionColumns.size(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/journal/JournalEntity.java b/fe/fe-core/src/main/java/org/apache/doris/journal/JournalEntity.java index 9f65a66686..fcc3070608 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/journal/JournalEntity.java +++ b/fe/fe-core/src/main/java/org/apache/doris/journal/JournalEntity.java @@ -66,6 +66,7 @@ import org.apache.doris.persist.DropResourceOperationLog; import org.apache.doris.persist.GlobalVarPersistInfo; import org.apache.doris.persist.HbPackage; import org.apache.doris.persist.ModifyPartitionInfo; +import org.apache.doris.persist.ModifyTableDefaultDistributionBucketNumOperationLog; import org.apache.doris.persist.ModifyTablePropertyOperationLog; import org.apache.doris.persist.OperationType; import org.apache.doris.persist.PartitionPersistInfo; @@ -562,6 +563,11 @@ public class JournalEntity implements Writable { isRead = true; break; } + case OperationType.OP_MODIFY_DISTRIBUTION_BUCKET_NUM: { + data = ModifyTableDefaultDistributionBucketNumOperationLog.read(in); + isRead = true; + break; + } case OperationType.OP_REPLACE_TEMP_PARTITION: { data = ReplacePartitionOperationLog.read(in); isRead = true; diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java b/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java index 91d71f5227..0bdbbbbee3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java @@ -755,6 +755,11 @@ public class EditLog { catalog.replayModifyTableProperty(opCode, modifyTablePropertyOperationLog); break; } + case OperationType.OP_MODIFY_DISTRIBUTION_BUCKET_NUM: { + ModifyTableDefaultDistributionBucketNumOperationLog modifyTableDefaultDistributionBucketNumOperationLog = (ModifyTableDefaultDistributionBucketNumOperationLog) journal.getData(); + catalog.replayModifyTableDefaultDistributionBucketNum(opCode, modifyTableDefaultDistributionBucketNumOperationLog); + break; + } case OperationType.OP_REPLACE_TEMP_PARTITION: { ReplacePartitionOperationLog replaceTempPartitionLog = (ReplacePartitionOperationLog) journal.getData(); catalog.replayReplaceTempPartition(replaceTempPartitionLog); @@ -1340,6 +1345,10 @@ public class EditLog { logEdit(OperationType.OP_MODIFY_REPLICATION_NUM, info); } + public void logModifyDefaultDistributionBucketNum(ModifyTableDefaultDistributionBucketNumOperationLog info) { + logEdit(OperationType.OP_MODIFY_DISTRIBUTION_BUCKET_NUM, info); + } + public void logModifyInMemory(ModifyTablePropertyOperationLog info) { logEdit(OperationType.OP_MODIFY_IN_MEMORY, info); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/ModifyTableDefaultDistributionBucketNumOperationLog.java b/fe/fe-core/src/main/java/org/apache/doris/persist/ModifyTableDefaultDistributionBucketNumOperationLog.java new file mode 100644 index 0000000000..b788900ee7 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/persist/ModifyTableDefaultDistributionBucketNumOperationLog.java @@ -0,0 +1,64 @@ +// 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. + +package org.apache.doris.persist; + +import com.google.gson.annotations.SerializedName; +import org.apache.doris.common.io.Text; +import org.apache.doris.common.io.Writable; +import org.apache.doris.persist.gson.GsonUtils; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +public class ModifyTableDefaultDistributionBucketNumOperationLog implements Writable { + + @SerializedName(value = "dbId") + private long dbId; + @SerializedName(value = "tableId") + private long tableId; + @SerializedName(value = "bucketNum") + private int bucketNum; + + public ModifyTableDefaultDistributionBucketNumOperationLog(long dbId, long tableId, int bucketNum) { + this.dbId = dbId; + this.tableId = tableId; + this.bucketNum = bucketNum; + } + + public long getDbId() { + return dbId; + } + + public long getTableId() { + return tableId; + } + + public int getBucketNum() { + return bucketNum; + } + + @Override + public void write(DataOutput out) throws IOException { + Text.writeString(out, GsonUtils.GSON.toJson(this)); + } + + public static ModifyTableDefaultDistributionBucketNumOperationLog read(DataInput in) throws IOException { + return GsonUtils.GSON.fromJson(Text.readString(in), ModifyTableDefaultDistributionBucketNumOperationLog.class); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/OperationType.java b/fe/fe-core/src/main/java/org/apache/doris/persist/OperationType.java index 1685505e1f..785cd1e47f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/persist/OperationType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/persist/OperationType.java @@ -182,6 +182,9 @@ public class OperationType { // set table in memory public static final short OP_MODIFY_IN_MEMORY = 267; + // set table default distribution bucket num + public static final short OP_MODIFY_DISTRIBUTION_BUCKET_NUM = 268; + // plugin 270~275 public static final short OP_INSTALL_PLUGIN = 270; diff --git a/fe/fe-core/src/test/java/org/apache/doris/alter/AlterTest.java b/fe/fe-core/src/test/java/org/apache/doris/alter/AlterTest.java index 6aa71484c5..816a76204f 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/alter/AlterTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/alter/AlterTest.java @@ -627,6 +627,37 @@ public class AlterTest { Assert.assertNotNull(replace3.getIndexIdByName("r2")); } + @Test + public void testModifyBucketNum() throws Exception { + String stmt = "CREATE TABLE test.bucket\n" + + "(\n" + + " k1 int, k2 int, k3 int sum\n" + + ")\n" + + "ENGINE = OLAP\n" + + "PARTITION BY RANGE(k1)\n" + + "(\n" + + "PARTITION p1 VALUES LESS THAN (\"100000\"),\n" + + "PARTITION p2 VALUES LESS THAN (\"200000\"),\n" + + "PARTITION p3 VALUES LESS THAN (\"300000\")\n" + + ")\n" + + "DISTRIBUTED BY HASH(k1) BUCKETS 10\n" + + "PROPERTIES(\"replication_num\" = \"1\");"; + + createTable(stmt); + Database db = Catalog.getCurrentCatalog().getDb("default_cluster:test"); + + String modifyBucketNumStmt = "ALTER TABLE test.bucket MODIFY DISTRIBUTION DISTRIBUTED BY HASH(k1) BUCKETS 1;"; + alterTable(modifyBucketNumStmt, false); + OlapTable bucket = (OlapTable) db.getTable("bucket"); + Assert.assertEquals(1, bucket.getDefaultDistributionInfo().getBucketNum()); + + modifyBucketNumStmt = "ALTER TABLE test.bucket MODIFY DISTRIBUTION DISTRIBUTED BY HASH(k1) BUCKETS 30;"; + alterTable(modifyBucketNumStmt, false); + bucket = (OlapTable) db.getTable("bucket"); + Assert.assertEquals(30, bucket.getDefaultDistributionInfo().getBucketNum()); + + } + private boolean checkAllTabletsExists(List tabletIds) { TabletInvertedIndex invertedIndex = Catalog.getCurrentCatalog().getTabletInvertedIndex(); for (long tabletId : tabletIds) {