JackDrogon commented on code in PR #15250:
URL: https://github.com/apache/doris/pull/15250#discussion_r1056015723


##########
fe/fe-core/src/main/java/org/apache/doris/clone/DynamicPartitionScheduler.java:
##########
@@ -140,6 +142,69 @@ private Map<String, String> createDefaultRuntimeInfo() {
         return defaultRuntimeInfo;
     }
 
+    // exponential moving average
+    private static long ema(ArrayList<Long> history, int period) {
+        double alpha = 2.0 / (period + 1);
+        double ema = history.get(0);
+        for (int i = 1; i < history.size(); i++) {
+            ema = alpha * history.get(i) + (1 - alpha) * ema;
+        }
+        return (long) ema;
+    }
+
+    private static long getNextPartitionSize(ArrayList<Long> 
historyPartitionsSize) {
+        if (historyPartitionsSize.size() < 2) {
+            return historyPartitionsSize.get(0);
+        }
+
+        int size = historyPartitionsSize.size() > 7 ? 7 : 
historyPartitionsSize.size();
+
+        boolean isAscending = true;
+        for (int i = 1; i < size; i++) {
+            if (historyPartitionsSize.get(i) < historyPartitionsSize.get(i - 
1)) {
+                isAscending = false;
+                break;
+            }
+        }
+
+        if (isAscending) {
+            ArrayList<Long> historyDeltaSize = Lists.newArrayList();
+            for (int i = 1; i < size; i++) {
+                historyDeltaSize.add(historyPartitionsSize.get(i) - 
historyPartitionsSize.get(i - 1));
+            }
+            return historyPartitionsSize.get(size - 1) + ema(historyDeltaSize, 
7);
+        } else {
+            return ema(historyPartitionsSize, 7);
+        }
+    }
+
+    private static int getBucketsNum(DynamicPartitionProperty property, 
OlapTable table) {
+        if (!table.isAutoBucket()) {
+            return property.getBuckets();
+        }
+
+        // auto bucket
+        List<Partition> partitions = Lists.newArrayList(table.getPartitions());
+        if (partitions.size() == 0) {
+            return property.getBuckets();
+        }
+
+        Collections.sort(partitions, new Comparator<Partition>() {
+            @Override
+            public int compare(Partition p1, Partition p2) {
+                return (int) (p1.getId() - p2.getId());
+            }
+        });
+        ArrayList<Long> parititonsSize = Lists.newArrayList();
+        for (Partition partition : table.getPartitions()) {
+            parititonsSize.add(partition.getDataSize());
+        }
+
+        // * 5 for uncompressed data
+        long uncompressedPartionSize = getNextPartitionSize(parititonsSize) * 
5;

Review Comment:
   AutoBucketUtils.getBucketNum accept an uncompressed partition size,



-- 
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-unsubscr...@doris.apache.org

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


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

Reply via email to