You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/07/08 01:31:59 UTC

[GitHub] [incubator-doris] morningman commented on a change in pull request #6023: Support alter default bucket_num of table

morningman commented on a change in pull request #6023:
URL: https://github.com/apache/incubator-doris/pull/6023#discussion_r665807625



##########
File path: fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
##########
@@ -5577,6 +5579,76 @@ public void replayModifyTableProperty(short opCode, ModifyTablePropertyOperation
         }
     }
 
+    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<Column> 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<Column> newDistriCols = hashDistributionInfo.getDistributionColumns();
+                List<Column> 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);

Review comment:
       Need to check `if (olapTable == null)`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org