github-actions[bot] commented on code in PR #65219:
URL: https://github.com/apache/doris/pull/65219#discussion_r3620577056


##########
fe/fe-core/src/main/java/org/apache/doris/clone/DynamicPartitionScheduler.java:
##########
@@ -201,23 +199,64 @@ private static long getNextPartitionSize(List<Long> 
historyPartitionsSize) {
     }
 
     private static Pair<Integer, Integer> 
getBucketsNum(DynamicPartitionProperty property, OlapTable table,
-            String partitionName, String nowPartitionName, boolean 
executeFirstTime) {
+            String partitionName, String nowPartitionName, boolean 
executeFirstTime, String currentUtcBorder) {
         AutoBucketCalculator.AutoBucketContext context = new 
AutoBucketCalculator.AutoBucketContext(
-                table, partitionName, nowPartitionName, executeFirstTime, 
property.getBuckets());
+                table, partitionName, nowPartitionName, executeFirstTime, 
property.getBuckets(),
+                currentUtcBorder);
 
         AutoBucketCalculator.AutoBucketResult result = 
AutoBucketCalculator.calculateAutoBuckets(context);
         return Pair.of(result.getBuckets(), result.getPreviousBuckets());
     }
 
-    public static List<Partition> getHistoricalPartitions(OlapTable table, 
String nowPartitionName) {
+    /**
+     * Get all partitions except the current one. When currentUtcBorder is 
non-null,
+     * the current partition is identified by matching its range lower bound 
against
+     * currentUtcBorder rather than by name. For TIMESTAMPTZ tables both names 
and
+     * ranges are UTC-based, so the name-based fallback is also correct; the 
range
+     * check provides an additional safety layer.
+     */
+    public static List<Partition> getHistoricalPartitions(OlapTable table, 
String nowPartitionName,
+            String currentUtcBorder) {
         table.readLock();
         try {
             RangePartitionInfo info = (RangePartitionInfo) 
(table.getPartitionInfo());
             List<Map.Entry<Long, PartitionItem>> idToItems = new 
ArrayList<>(info.getIdToItem(false).entrySet());
             idToItems.sort(Comparator.comparing(o -> ((RangePartitionItem) 
o.getValue()).getItems().upperEndpoint()));
             return idToItems.stream()
                     .map(entry -> table.getPartition(entry.getKey()))
-                    .filter(partition -> partition != null && 
!partition.getName().equals(nowPartitionName))
+                    .filter(partition -> {
+                        if (partition == null) {
+                            return false;
+                        }
+                        // When currentUtcBorder is available, exclude the 
current
+                        // partition by comparing range lower bounds, not 
names.
+                        // Use PartitionKey.compareTo (not getStringValue) to
+                        // handle scale differences: a TIMESTAMPTZ(6) lower key
+                        // stores "2026-07-20 00:00:00.000000+00:00" while
+                        // currentUtcBorder is "2026-07-20 00:00:00+00:00" —
+                        // the string representations differ even though they
+                        // represent the same instant.
+                        if (currentUtcBorder != null) {
+                            RangePartitionItem item = (RangePartitionItem) 
info.getItem(partition.getId());
+                            if (item != null) {
+                                PartitionKey lower = 
item.getItems().lowerEndpoint();
+                                try {
+                                    Column partitionColumn = 
info.getPartitionColumns().get(0);
+                                    PartitionValue currentValue = new 
PartitionValue(currentUtcBorder);
+                                    PartitionKey currentKey = 
PartitionKey.createPartitionKey(
+                                            
Collections.singletonList(currentValue),
+                                            
Collections.singletonList(partitionColumn));
+                                    if (lower.compareTo(currentKey) == 0) {
+                                        return false; // current partition
+                                    }
+                                } catch (AnalysisException e) {
+                                    // Fall back to name-based comparison
+                                    return 
!partition.getName().equals(nowPartitionName);
+                                }
+                            }
+                        }
+                        return !partition.getName().equals(nowPartitionName);

Review Comment:
   [P2] Use the range key as the sole identity when it is available
   
   Once `currentUtcBorder` parses successfully, this filter can exclude two 
partitions: it removes the range-matched current partition above, then still 
applies `nowPartitionName` to every other range here. A supported prefix-change 
sequence exposes this: retain the current range under old prefix `q`, add a 
populated nonoverlapping historical partition named with the future 
prefix/current suffix (for example `p20260721`), change the prefix to `p`, and 
schedule a missing future partition. The real current `q...` partition is 
excluded by range and the historical `p...` partition by name, so auto-bucket 
can lose its only populated history and fall back to the default bucket count. 
Please parse the current key once before the stream and, when it is available, 
filter solely by its lower endpoint; use the name only when no range key is 
available. Hoisting the parse also avoids doing the same timestamp parse for 
every existing partition and every missing add candidate while the table read l
 ock is held.



-- 
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