morrySnow commented on code in PR #54407:
URL: https://github.com/apache/doris/pull/54407#discussion_r2256772265


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignatureHelper.java:
##########
@@ -456,6 +457,56 @@ private static FunctionSignature 
defaultTimePrecisionPromotion(FunctionSignature
         return signature;
     }
 
+    /**
+     * Dynamically compute function signature for variant type arguments.
+     * This method handles cases where the function signature contains variant 
types
+     * and needs to be adjusted based on the actual argument types.
+     *
+     * @param signature Original function signature
+     * @param arguments List of actual arguments passed to the function
+     * @return Updated function signature with resolved variant types
+     */
+    public static FunctionSignature dynamicComputeVariantArgs(
+            FunctionSignature signature, List<Expression> arguments) {
+
+        List<DataType> newArgTypes = 
Lists.newArrayListWithCapacity(arguments.size());
+        boolean findVariantType = false;
+
+        for (int i = 0; i < arguments.size(); i++) {
+            // Get signature type for current argument position
+            DataType sigType;
+            if (i >= signature.argumentsTypes.size()) {
+                sigType = signature.getVarArgType().orElseThrow(
+                        () -> new AnalysisException("function arity not match 
with signature"));
+            } else {
+                sigType = signature.argumentsTypes.get(i);
+            }
+
+            // Get actual type of the argument expression
+            DataType expressionType = arguments.get(i).getDataType();
+
+            // If both signature type and expression type are variant,
+            // use expression type and update return type
+            if (sigType instanceof VariantType && expressionType instanceof 
VariantType) {
+                // return type is variant, update return type to expression 
type
+                if (signature.returnType instanceof VariantType) {
+                    signature = signature.withReturnType(expressionType);
+                }

Review Comment:
   is this right? i think `element_at` for `variant` will return wrong type



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignatureHelper.java:
##########
@@ -456,6 +457,56 @@ private static FunctionSignature 
defaultTimePrecisionPromotion(FunctionSignature
         return signature;
     }
 
+    /**
+     * Dynamically compute function signature for variant type arguments.
+     * This method handles cases where the function signature contains variant 
types
+     * and needs to be adjusted based on the actual argument types.
+     *
+     * @param signature Original function signature
+     * @param arguments List of actual arguments passed to the function
+     * @return Updated function signature with resolved variant types
+     */
+    public static FunctionSignature dynamicComputeVariantArgs(

Review Comment:
   add ut



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