hakanuzum commented on code in PR #62599:
URL: https://github.com/apache/doris/pull/62599#discussion_r3130608822
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommand.java:
##########
@@ -136,10 +141,36 @@ private static Map<TableIf, Set<Expression>>
constructTableWithPredicates(MTMV m
PartitionItem partitionItem =
mv.getPartitionItemOrAnalysisException(partitionName);
items.add(partitionItem);
}
+ // Detect hour-offset partition expression
(date_trunc(date_add/sub(col, N), unit)).
+ // For these expressions, the predicate on the base column must be
built against
+ // date_add/sub(col, N) rather than the raw column, so that the WHERE
clause correctly
+ // maps the MV partition boundary back to the base table range.
+ long hourOffset = 0;
+ try {
+ if (mv.getMvPartitionInfo() != null &&
mv.getMvPartitionInfo().getExpr() != null) {
+
MTMVPartitionExprFactory.getExprService(mv.getMvPartitionInfo().getExpr());
+ Object service =
MTMVPartitionExprFactory.getExprService(mv.getMvPartitionInfo().getExpr());
+ if (service instanceof MTMVPartitionExprDateTruncDateAddSub) {
+ hourOffset = ((MTMVPartitionExprDateTruncDateAddSub)
service).getOffsetHours();
+ }
+ }
+ } catch (AnalysisException ignored) {
+ // fall back to no-offset behaviour
+ }
+ final long finalHourOffset = hourOffset;
ImmutableMap.Builder<TableIf, Set<Expression>> builder = new
ImmutableMap.Builder<>();
- tableWithPartKey.forEach((table, colName) ->
- builder.put(table, constructPredicates(items, colName))
- );
Review Comment:
This scenario assumes cast(col as date) can reach the refresh path. However,
analyze() explicitly rejects any base column that is not DATETIME/DATETIMEV2 at
DDL time — so a DATE column with cast is rejected before the MV is even
created. The constructor does strip CastExpr nodes, but only to unwrap down to
the underlying TimestampArithmeticExpr for validation — the cast shape is never
stored or used in refresh. Therefore this scenario is not reachable within the
current implementation. If cast support is added in the future, the refresh
predicate builder would need to be revisited at that point.
--
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]