Hisoka-X commented on code in PR #9299:
URL: https://github.com/apache/seatunnel/pull/9299#discussion_r2258817605


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLFunction.java:
##########
@@ -344,7 +344,7 @@ public Object computeForValue(Expression expression, 
Object[] inputFields) {
                     functionArgs.add(computeForValue(funcArgExpression, 
inputFields));
                 }
             }
-            return executeFunctionExpr(functionName, functionArgs);
+            return executeFunctionExpr(function.getName(), functionArgs, 
expression);

Review Comment:
   ```suggestion
               return executeFunctionExpr(functionName, functionArgs, 
expression);
   ```



##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLType.java:
##########
@@ -493,6 +503,23 @@ private SeaTunnelDataType<?> getFunctionType(Function 
function) {
         }
     }
 
+    private static List<Expression> getExpressions(Function function) {

Review Comment:
   ```suggestion
       private static List<Expression> getParametersExpressions(Function 
function) {
   ```



##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/SystemFunction.java:
##########
@@ -37,24 +37,35 @@
 import java.util.List;
 
 public class SystemFunction {
-    public static Object coalesce(List<Object> args) {
-        Object v = null;
-        for (Object v2 : args) {
-            if (v2 != null) {
-                v = v2;
-                break;
+    /**
+     * Enhanced version of coalesce function that takes a target type 
parameter. This ensures that
+     * the result is always converted to the expected type regardless of which 
argument is non-null.
+     *
+     * @param args Function arguments
+     * @param targetType The target type that the result should be converted to
+     * @return The first non-null value converted to the target type
+     */
+    public static Object coalesce(List<Object> args, SeaTunnelDataType<?> 
targetType) {
+        Object result = coalesce(args);
+        return castAs(result, targetType);
+    }
+
+    private static Object coalesce(List<Object> args) {
+        for (Object arg : args) {
+            if (arg != null) {
+                return arg;
             }
         }
-        return v;
+        return null;
     }
 
-    public static Object ifnull(List<Object> args) {
+    public static Object ifnull(List<Object> args, SeaTunnelDataType<?> 
targetType) {

Review Comment:
   we should update ifnull function docs too.



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

Reply via email to