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


##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4:
##########
@@ -171,6 +171,10 @@ partitionSpec
        // | PARTITIONS WITH RECENT
     ;
 
+partitionRange
+    : (PARTITION | PARTITIONS) START start=STRING_LITERAL END 
end=STRING_LITERAL

Review Comment:
   use partition range syntax? `partition (['xxxx', 'yyyy'))`



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/RefreshMTMVInfo.java:
##########
@@ -69,6 +75,15 @@ public void analyze(ConnectContext ctx) {
             if (!CollectionUtils.isEmpty(partitions)) {
                 MTMVPartitionUtil.getPartitionsIdsByNames(mtmv, partitions);
             }
+            if (rangeOptional.isPresent()) {
+                if (mtmv.getMvPartitionInfo().getPartitionType() == 
MTMVPartitionType.SELF_MANAGE) {
+                    throw new AnalysisException(
+                            "The partitioning method: SELF_MANAGE of async 
materialized views "
+                                    + "does not support refreshing by 
partition range");
+                }
+                rangeOptional.get().getStartDate();
+                rangeOptional.get().getEndDate();

Review Comment:
   add comment to explain why call these function without assign result to a var



##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java:
##########
@@ -504,4 +511,45 @@ public static Type 
getPartitionColumnType(MTMVRelatedTableIf relatedTable, Strin
         }
         throw new AnalysisException("can not getPartitionColumnType by:" + 
col);
     }
+
+    public static List<String> getPartitionsByRange(MTMV mtmv, 
MTMVRefreshPartitionRange range) {
+        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;
+    }
+
+    private static boolean ifPartitionItemInRange(PartitionItem item, 
MTMVRefreshPartitionRange range) {
+        if (item instanceof ListPartitionItem) {
+            ListPartitionItem listPartitionItem = (ListPartitionItem) item;
+            List<PartitionKey> keys = listPartitionItem.getItems();
+            for (PartitionKey key : keys) {
+                if (ifPartitionKeyInRange(key, range, false)) {
+                    return true;
+                }
+            }
+        } else if (item instanceof RangePartitionItem) {
+            RangePartitionItem rangePartitionItem = (RangePartitionItem) item;
+            Range<PartitionKey> items = rangePartitionItem.getItems();
+            return ifPartitionKeyInRange(items.lowerEndpoint(), range, false) 
|| ifPartitionKeyInRange(
+                    items.lowerEndpoint(), range, true);
+        }
+        return false;
+    }
+
+    private static boolean ifPartitionKeyInRange(PartitionKey partitionKey, 
MTMVRefreshPartitionRange range,
+            boolean isUpper) {
+        Preconditions.checkState(partitionKey.getKeys().size() == 1,
+                "only support one partition column");
+        String stringValue = partitionKey.getKeys().get(0).getStringValue();
+        DateV2Literal dateV2Literal = new DateV2Literal(stringValue);
+        Long value = dateV2Literal.getValue();
+        return value <= range.getEndDate().getValue() && (isUpper ? value > 
range.getStartDate().getValue()
+                : value >= range.getStartDate().getValue());

Review Comment:
   should we use Half-open, half-closed interval?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -793,8 +794,15 @@ public RefreshMTMVCommand 
visitRefreshMTMV(RefreshMTMVContext ctx) {
                 partitions = 
visitIdentifierList(ctx.partitionSpec().partitions);
             }
         }
+        Optional<MTMVRefreshPartitionRange> range = ctx.partitionRange() == 
null ? Optional.empty()
+                : Optional.of(new 
MTMVRefreshPartitionRange(LogicalPlanBuilderAssistant.escapeBackSlash(

Review Comment:
   visitStringLiteral is better



##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java:
##########
@@ -504,4 +511,45 @@ public static Type 
getPartitionColumnType(MTMVRelatedTableIf relatedTable, Strin
         }
         throw new AnalysisException("can not getPartitionColumnType by:" + 
col);
     }
+
+    public static List<String> getPartitionsByRange(MTMV mtmv, 
MTMVRefreshPartitionRange range) {
+        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;
+    }
+
+    private static boolean ifPartitionItemInRange(PartitionItem item, 
MTMVRefreshPartitionRange range) {
+        if (item instanceof ListPartitionItem) {
+            ListPartitionItem listPartitionItem = (ListPartitionItem) item;
+            List<PartitionKey> keys = listPartitionItem.getItems();
+            for (PartitionKey key : keys) {
+                if (ifPartitionKeyInRange(key, range, false)) {
+                    return true;
+                }
+            }
+        } else if (item instanceof RangePartitionItem) {
+            RangePartitionItem rangePartitionItem = (RangePartitionItem) item;
+            Range<PartitionKey> items = rangePartitionItem.getItems();
+            return ifPartitionKeyInRange(items.lowerEndpoint(), range, false) 
|| ifPartitionKeyInRange(
+                    items.lowerEndpoint(), range, true);
+        }
+        return false;
+    }
+
+    private static boolean ifPartitionKeyInRange(PartitionKey partitionKey, 
MTMVRefreshPartitionRange range,
+            boolean isUpper) {
+        Preconditions.checkState(partitionKey.getKeys().size() == 1,
+                "only support one partition column");
+        String stringValue = partitionKey.getKeys().get(0).getStringValue();
+        DateV2Literal dateV2Literal = new DateV2Literal(stringValue);

Review Comment:
   i think u'd better throw a clarify error message. not use DateV2Literal init 
error mesasge



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