OIiveirra commented on code in PR #69113:
URL: https://github.com/apache/doris/pull/69113#discussion_r4290663564


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java:
##########
@@ -140,6 +148,35 @@ public class ExpressionUtils {
     // folding the conjunct). We restrict MAX_MARK_SLOT_COUNT to 4 to bound 
this cost.
     private static final int MAX_MARK_SLOT_COUNT = 4;
 
+    /**
+     * Date arithmetic can throw for values outside its valid range. Keep it 
above a lower
+     * condition, join, limit, or CTE consumer so that those operators can 
reject rows first.
+     * A date add/subtract with literal zero is an identity and remains safe 
to push through.
+     */
+    public static boolean requiresDateArithmeticProtection(Expression 
expression, Plan input) {
+        return expression.anyMatch(expr -> isUnsafeDateArithmetic((Expression) 
expr))
+                && input.anyMatch(plan -> plan instanceof Filter || plan 
instanceof Join || plan instanceof Limit
+                        || plan instanceof LogicalCTEConsumer || plan 
instanceof PhysicalCTEConsumer);

Review Comment:
   Addressed in 40040901b3a, with the framework-generated regression output in 
adfc9a97169.
   
   The existing shared protection check now includes the logical/physical 
Except, Intersect and Generate interfaces. Ordinary UNION and the safe 
integer-zero exception remain unchanged.
   
   Added logical and physical pushdown tests, plus 
test_date_arithmetic_rejecting_boundary with a precision-lowering CAST and no 
disabled optimizer rules. The SQL regression covers EXCEPT/INTERSECT removing 
the maximum date, explode discarding an empty-array row, safe zero offsets, and 
an expected error for a row that actually participates in overflowing 
arithmetic.
   
   Local validation passed: 17 focused FE unit tests with integrated 
Checkstyle; FE/BE build; the new suite in stable snapshot-comparison mode; and 
the existing date_function_rewrite, CTE filter pushdown and ORC/Parquet 
date-expression suites. Regression source/artifact/process identity and 
input-stability checks passed. These are targeted local results, not a full CI 
claim.



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