xy720 commented on code in PR #64622:
URL: https://github.com/apache/doris/pull/64622#discussion_r3520947708


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/SearchSignatureForRound.java:
##########
@@ -18,26 +18,86 @@
 package org.apache.doris.nereids.trees.expressions.functions;
 
 import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.CascadesContext;
+import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext;
+import org.apache.doris.nereids.rules.expression.rules.FoldConstantRuleOnFE;
+import org.apache.doris.nereids.trees.expressions.Cast;
 import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLikeLiteral;
 import org.apache.doris.nereids.types.DoubleType;
 import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.types.coercion.Int32OrLessType;
+import org.apache.doris.qe.ConnectContext;
 
+import java.math.BigInteger;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
- * if argument 0 is float or double, we should return double signature for 
round like function.
+ * Signature search for round-like functions (round, round_bankers, ceil, 
floor, truncate).
  */
 public interface SearchSignatureForRound extends ExplicitlyCastableSignature {
+
+    int DOUBLE_DECIMAL_RESULT_MAX_SCALE = 15;
+
     @Override
     default FunctionSignature searchSignature(List<FunctionSignature> 
signatures) {
         List<Expression> arguments = getArguments();
         if (arguments.get(0).getDataType().isFloatLikeType()) {
             if (arguments.size() == 1) {
                 return 
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE);

Review Comment:
   Thanks for the thorough read! I think there may be a small misread here — 
the outer condition is still isFloatLikeType(), unchanged. Only the inner 
nested check specifically added a gate to the DECIMAL(30, 15) reroute for 
DOUBLE-only.
   
   So the routing is unchanged for FLOAT:
   - round(FLOAT) — returns `(DOUBLE) → DOUBLE `
   - round(FLOAT, INT) — returns `(DOUBLE, INT) → DOUBLE`
   
   I think it is necessary to narrow the scope to double-only, because casting 
float to DECIMAL(14, 7) can lead to numerical overflow when |f| >= 1e7. This 
overflow range is smaller then 1e15(for double), making it easier for users to 
trigger.
   
   And double is the common case, float usage is comparatively rare. Fixing the 
common case cleanly seemed like a better return on user-surprise budget than 
pulling FLOAT along and pushing its overflow surface into 1e7.
   
    I'll leave the outer condition and the class javadoc as-is unless you spot 
something else.



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