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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/MTMVPartitionDefinition.java:
##########
@@ -178,8 +191,25 @@ private static List<Pair<Integer, Expr>> 
convertDateTruncToLegacyArguments(List<
     }
 
     private static Pair<Integer, Expr> convertToLegacyRecursion(Expression 
expression) {
-        if (expression instanceof Slot) {
+        if (expression instanceof UnboundSlot) {
+            return Pair.of(1, new SlotRef(null, ((UnboundSlot) 
expression).getName()));
+        } else if (expression instanceof Slot) {
             return Pair.of(1, new SlotRef(null, ((Slot) 
expression).getName()));
+        } else if (expression instanceof HoursAdd) {
+            return Pair.of(1, convertDateAddSubToLegacy((HoursAdd) expression, 
"date_add"));
+        } else if (expression instanceof HoursSub) {
+            return Pair.of(1, convertDateAddSubToLegacy((HoursSub) expression, 
"date_sub"));
+        } else if (expression instanceof UnboundFunction) {
+            String name = ((UnboundFunction) 
expression).getName().toLowerCase();
+            if ("hours_add".equals(name) || "date_add".equals(name)) {
+                return Pair.of(1, convertDateAddSubToLegacy(expression, 
"date_add"));

Review Comment:
   Stripping `Cast` here changes the persisted partition semantics. 
`date_trunc(date_add(cast(k2 as date), INTERVAL 3 HOUR), 'day')` is not 
equivalent to `date_trunc(date_add(k2, INTERVAL 3 HOUR), 'day')`: for `k2 = 
'2025-07-24 23:00:00'`, the first expression stays on `2025-07-24`, while the 
second rolls to `2025-07-25`.
   
   Because `MTMVPartitionInfo.expr` is what we use for SHOW CREATE / replay / 
equality checks, dropping the cast means we can create one partitioning rule 
and persist a different one. The cast needs to be preserved in the stored 
legacy expr instead of being elided.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/MTMVPartitionDefinition.java:
##########
@@ -125,6 +135,9 @@ private void fillPctInfos(NereidsPlanner planner, String 
partitionColName,
             Optional<Expression> partitionExpression = 
tableColumnInfo.getPartitionExpression();

Review Comment:
   `mtmvPartitionInfo.expr` is already set from the user-facing `PARTITION BY` 
clause before we enter `fillPctInfos()`. For alias-form definitions like 
`PARTITION BY (date_trunc(day_alias, 'day')) AS SELECT date_trunc(date_add(k2, 
INTERVAL 3 HOUR), 'day') AS day_alias ...`, that means `expr` is still 
`date_trunc(day_alias, 'day')` here.
   
   This `continue` prevents us from replacing it with the traced base-table 
expression, so all downstream offset-aware logic still sees the plain 
`date_trunc` form. That means the new feature is still broken for the alias 
syntax: `MTMVPartitionExprFactory` falls back to `MTMVPartitionExprDateTrunc`, 
and a base range like `[2025-07-24 21:00:00, 2025-07-25 21:00:00)` no longer 
rolls up to the expected `2025-07-25` MV partition. The partial-refresh / 
union-compensation path also misses the inverse offset for the same reason.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java:
##########
@@ -382,8 +383,11 @@ protected List<Plan> doRewrite(StructInfo queryStructInfo, 
CascadesContext casca
                     return rewriteResults;
                 }
                 if (partitionNeedUnion) {
+                    Optional<Long> inverseOffsetHours =
+                            
UpdateMvByPartitionCommand.getInverseHourOffsetForBaseFilter(mtmv);
                     Pair<Plan, Boolean> planAndNeedAddFilterPair =
-                            StructInfo.addFilterOnTableScan(queryPlan, 
invalidPartitions.value(), cascadesContext);

Review Comment:
   `invalidPartitions.value()` is already in the base-table partition domain. 
`PartitionCompensator` fills it from `partitionMapping.get(mvPartitionName)` 
and from `queryUsedBaseTablePartitionNameSet`, both of which are base partition 
names, not MV partition bounds.
   
   Passing `inverseOffsetHours` into `addFilterOnTableScan()` shifts those base 
partition items a second time. For a raw `date_trunc(date_add(k2, INTERVAL 3 
HOUR), 'day')` MV, a missing MV partition that maps to base range `[2025-07-24 
21:00:00, 2025-07-25 21:00:00)` now produces `k2 >= '2025-07-24 18:00:00' AND 
k2 < '2025-07-25 18:00:00'`, which scans the wrong slice and can introduce 
duplicates / missed rows in the union branch.



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