yuanhang-dev commented on code in PR #10125:
URL: 
https://github.com/apache/incubator-gluten/pull/10125#discussion_r2218081773


##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/functions/BaseRexCallConverters.java:
##########
@@ -80,11 +91,86 @@ public boolean isSupported(RexCall callNode, 
RexConversionContext context) {
   @Override
   public TypedExpr toTypedExpr(RexCall callNode, RexConversionContext context) 
{
     List<TypedExpr> params = getParams(callNode, context);
-    // If types are different, align them
-    List<TypedExpr> alignedParams = 
TypeUtils.promoteTypeForArithmeticExpressions(params);
+
     Type resultType = getResultType(callNode);
+    if (params.size() == 2) {
+      Type leftType = params.get(0).getReturnType();
+      Type rightType = params.get(1).getReturnType();
+
+      if (leftType instanceof DecimalType || rightType instanceof DecimalType) 
{
+        List<TypedExpr> alignedParams = 
TypeUtils.promoteTypeForArithmeticExpressions(params);
+
+        Type alignedLeftType = alignedParams.get(0).getReturnType();
+        Type alignedRightType = alignedParams.get(1).getReturnType();
+
+        if (alignedLeftType instanceof DecimalType && alignedRightType 
instanceof DecimalType) {
+          Type veloxResultType =
+              calculateDecimalResultType(
+                  (DecimalType) alignedLeftType, (DecimalType) 
alignedRightType, functionName);
+          TypedExpr veloxExpr = new CallTypedExpr(veloxResultType, 
alignedParams, functionName);
+
+          return new CallTypedExpr(resultType, List.of(veloxExpr), "cast");
+        }
+      }
+    }
+
+    List<TypedExpr> alignedParams = 
TypeUtils.promoteTypeForArithmeticExpressions(params);
     return new CallTypedExpr(resultType, alignedParams, functionName);
   }
+
+  private Type calculateDecimalResultType(
+      DecimalType leftType, DecimalType rightType, String operation) {
+    int leftPrecision = leftType.getPrecision();
+    int leftScale = leftType.getScale();
+    int rightPrecision = rightType.getPrecision();
+    int rightScale = rightType.getScale();
+
+    int resultPrecision;
+    int resultScale;
+
+    switch (operation.toLowerCase()) {

Review Comment:
   Fixed. It's not necessary to normalize to lowercase here.



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