hello-stephen commented on code in PR #71094:
URL: https://github.com/apache/doris/pull/71094#discussion_r4785513193


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/NumericArithmetic.java:
##########
@@ -361,6 +361,26 @@ private static Expression 
castDecimalV3Literal(DecimalV3Literal literal, int pre
                 literal.getValue());
     }
 
+    private static DoubleLiteral roundDouble(DoubleLiteral first, int scale, 
RoundingMode mode) {
+        double value = first.getValue();
+        // A decimal unit at scale 324 is below half the smallest DOUBLE 
spacing.
+        if (scale >= 324 || !Double.isFinite(value) || value == 0) {

Review Comment:
   [P2] Validate scales that become constants after analysis
   
   Consider `SELECT round(CAST('1e100' AS DOUBLE), s) FROM t WHERE s = 32768` 
with an INT column `s` and a matching row. The reduced plan at binding is 
`Project(round(1e100, s)) -> Filter(s = 32768) -> Scan(t)`. The new 
pre-coercion check cannot validate the slot. However, 
`LogicalFilter.computeUniform` exposes `s = 32768`, and 
`ConstantPropagation.visitLogicalProject` / `replaceConstants` substitute that 
literal and call `FoldConstantRule.evaluate`. This early return then replaces 
the ROUND with `1e100`, instead of letting BE reject the scale at 
`FunctionRounding::get_scale_arg`. A session-dependent scale such as 
`if(connection_id() >= -2147483648, 32768, 0)` reaches the same path after 
context-dependent FE folding. Previously the DecimalV3 intermediate for 1e100 
exceeded precision 76, leaving the call for BE to reject. This is different 
from the earlier fractional-literal report: the actual scale is not yet a 
literal when the new analysis check runs. Validate the actual coerced sca
 le before FE folding (including before NULL propagation), retaining the early 
wide-integer check, and add a late-folded-scale regression.



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