Copilot commented on code in PR #56921:
URL: https://github.com/apache/doris/pull/56921#discussion_r2426707529


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionExprUtil.java:
##########
@@ -187,7 +193,43 @@ public static Map<String, AddPartitionClause> 
getAddPartitionClauseFromPartition
             }
 
             Map<String, String> partitionProperties = Maps.newHashMap();
-            DistributionDesc distributionDesc = 
olapTable.getDefaultDistributionInfo().toDistributionDesc();
+            DistributionInfo defaultDistributionInfo = 
olapTable.getDefaultDistributionInfo();
+            DistributionDesc distributionDesc = 
defaultDistributionInfo.toDistributionDesc();
+            if (olapTable.isAutoBucket() && partitionType == 
PartitionType.RANGE) {
+                List<Partition> partitions = 
DynamicPartitionScheduler.getHistoricalPartitions(olapTable, partitionName);
+                List<Long> visibleVersions;
+                try {
+                    visibleVersions = Partition.getVisibleVersions(partitions);
+                } catch (RpcException e) {
+                    LOG.warn("auto bucket get visible version fail, table: 
[{}-{}], partition: {}",
+                            olapTable.getName(), olapTable.getId(), 
partitionName, e);

Review Comment:
   The error message includes a placeholder for exception details but doesn't 
include the exception in the log parameters. Add the exception 'e' as the last 
parameter to properly log the stack trace.



##########
fe/fe-core/src/test/java/org/apache/doris/analysis/PartitionExprUtilTest.java:
##########
@@ -0,0 +1,219 @@
+// 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.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Partition;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.service.ExecuteEnv;
+import org.apache.doris.service.FrontendServiceImpl;
+import org.apache.doris.thrift.TCreatePartitionRequest;
+import org.apache.doris.thrift.TCreatePartitionResult;
+import org.apache.doris.thrift.TNullableStringLiteral;
+import org.apache.doris.thrift.TStatusCode;
+import org.apache.doris.utframe.TestWithFeService;
+
+import mockit.Expectations;
+import mockit.Mocked;
+import org.apache.doris.clone.DynamicPartitionScheduler;
+import org.apache.doris.common.Pair;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PartitionExprUtilTest extends TestWithFeService {
+    private static final Logger LOG = 
LogManager.getLogger(PartitionExprUtilTest.class);
+
+    @Mocked
+    ExecuteEnv exeEnv;
+    @Override
+    protected void runBeforeAll() throws Exception {
+        FeConstants.runningUnitTest = true;
+        FeConstants.default_scheduler_interval_millisecond = 100;
+        Config.dynamic_partition_enable = true;
+        Config.dynamic_partition_check_interval_seconds = 1;
+        createDatabase("test");
+    }
+
+    @Test
+    public void testAutoBucketLargeDataCalculatesBuckets() throws Exception {
+        String createOlapTblStmt = "CREATE TABLE test.auto_bucket_calc_large 
(\n"
+                + "  event_day DATETIME NOT NULL,\n"
+                + "  site_id INT,\n"
+                + "  v INT\n"
+                + ")\n"
+                + "DUPLICATE KEY(event_day, site_id)\n"
+                + "AUTO PARTITION BY range (date_trunc(event_day,'day')) (\n"
+                + "\n"
+                + ")\n"
+                + "DISTRIBUTED BY HASH(event_day) BUCKETS AUTO\n"
+                + "PROPERTIES(\"replication_num\"=\"1\");";
+
+        createTable(createOlapTblStmt);
+        Database db = 
Env.getCurrentInternalCatalog().getDbOrAnalysisException("test");
+        OlapTable table = (OlapTable) 
db.getTableOrAnalysisException("auto_bucket_calc_large");
+
+        FrontendServiceImpl impl = new FrontendServiceImpl(exeEnv);
+
+        // Create 3 historical partitions: 2023-08-01, 02, 03
+        String[] days = {"2023-08-01 00:00:00", "2023-08-02 00:00:00", 
"2023-08-03 00:00:00"};
+        String[] partNames = {"p20230801000000", "p20230802000000", 
"p20230803000000"};
+        for (String day : days) {
+            List<List<TNullableStringLiteral>> partitionValues = new 
ArrayList<>();
+            List<TNullableStringLiteral> values = new ArrayList<>();
+            TNullableStringLiteral start = new TNullableStringLiteral();
+            start.setValue(day);
+            values.add(start);
+            partitionValues.add(values);
+
+            TCreatePartitionRequest request = new TCreatePartitionRequest();
+            request.setDbId(db.getId());
+            request.setTableId(table.getId());
+            request.setPartitionValues(partitionValues);
+            TCreatePartitionResult result = impl.createPartition(request);
+            Assertions.assertEquals(TStatusCode.OK, 
result.getStatus().getStatusCode());
+        }
+
+        // Mark them as having data (visibleVersion >= 2)
+        table.writeLockOrDdlException();
+        try {
+            for (String pn : partNames) {
+                Partition p = table.getPartition(pn);
+                Assertions.assertNotNull(p);
+                p.setVisibleVersionAndTime(2L, System.currentTimeMillis());
+            }
+        } finally {
+            table.writeUnlock();
+        }
+
+        // Mock large compressed data sizes for each historical partition
+        long GB = 1024L * 1024L * 1024L;
+        Partition p1 = table.getPartition(partNames[0]);
+        Partition p2 = table.getPartition(partNames[1]);
+        Partition p3 = table.getPartition(partNames[2]);
+        new Expectations(p1, p2, p3) {{
+            p1.getDataSizeExcludeEmptyReplica(true); result = 200L * GB; 
minTimes = 0; // ~1 TB uncompressed
+            p2.getDataSizeExcludeEmptyReplica(true); result = 300L * GB; 
minTimes = 0; // ~1.5 TB uncompressed
+            p3.getDataSizeExcludeEmptyReplica(true); result = 400L * GB; 
minTimes = 0; // ~2 TB uncompressed

Review Comment:
   The comments indicate uncompressed sizes (~1 TB, ~1.5 TB, ~2 TB) but the 
mocked values are for compressed sizes (200GB, 300GB, 400GB). The comments 
should reflect the actual mocked compressed sizes or clarify the compression 
ratio assumption.
   ```suggestion
               p1.getDataSizeExcludeEmptyReplica(true); result = 200L * GB; 
minTimes = 0; // 200 GB compressed
               p2.getDataSizeExcludeEmptyReplica(true); result = 300L * GB; 
minTimes = 0; // 300 GB compressed
               p3.getDataSizeExcludeEmptyReplica(true); result = 400L * GB; 
minTimes = 0; // 400 GB compressed
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to