zddr commented on code in PR #36134:
URL: https://github.com/apache/doris/pull/36134#discussion_r1675276270


##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java:
##########
@@ -509,4 +516,52 @@ public static Type 
getPartitionColumnType(MTMVRelatedTableIf relatedTable, Strin
         }
         throw new AnalysisException("can not getPartitionColumnType by:" + 
col);
     }
+
+    public static List<String> getPartitionsByRange(MTMV mtmv, 
MTMVRefreshPartitionRange range)
+            throws AnalysisException {
+        List<String> res = Lists.newArrayList();
+        Collection<Partition> partitions = mtmv.getPartitions();
+        for (Partition partition : partitions) {
+            PartitionItem item = 
mtmv.getPartitionInfo().getItem(partition.getId());
+            if (ifPartitionItemInRange(item, range)) {
+                res.add(partition.getName());
+            }
+        }
+        return res;
+    }
+
+    public static boolean ifPartitionItemInRange(PartitionItem item, 
MTMVRefreshPartitionRange refreshPartitionRange)
+            throws AnalysisException {
+        Range<DateV2Literal> range = refreshPartitionRange.getRange();
+        if (item instanceof ListPartitionItem) {
+            ListPartitionItem listPartitionItem = (ListPartitionItem) item;
+            List<PartitionKey> keys = listPartitionItem.getItems();
+            for (PartitionKey key : keys) {
+                if (range.contains(transferPartitionKeyToDate(key))) {
+                    return true;
+                }
+            }
+        } else if (item instanceof RangePartitionItem) {
+            RangePartitionItem rangePartitionItem = (RangePartitionItem) item;
+            Range<PartitionKey> items = rangePartitionItem.getItems();
+            DateV2Literal lowerDate = 
transferPartitionKeyToDate(items.lowerEndpoint());
+            DateV2Literal upperDate = 
transferPartitionKeyToDate(items.upperEndpoint());
+            Range<DateV2Literal> partitionRange = Range.closedOpen(lowerDate, 
upperDate);
+            return range.isConnected(partitionRange) && 
!range.intersection(partitionRange).isEmpty();
+        }
+        return false;
+    }
+
+    private static DateV2Literal transferPartitionKeyToDate(PartitionKey 
partitionKey) throws AnalysisException {

Review Comment:
   If there is a need, I will implement it in another PR



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