hanyuzheng7 commented on code in PR #22717:
URL: https://github.com/apache/flink/pull/22717#discussion_r1223408668


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java:
##########
@@ -1407,6 +1409,44 @@ public OutType arrayUnion(InType array) {
                 unresolvedCall(ARRAY_UNION, toExpr(), 
objectToExpression(array)));
     }
 
+    /**
+     * Returns an array of the elements in the concat of array1 and array2, 
without duplicates.
+     *
+     * <p>If both of the array are null, the function will return null.
+     */
+    public OutType arrayConcat(InType... arrays) {
+        arrays = convertToArrays(arrays);
+        Expression[] args =
+                Stream.concat(
+                                Stream.of(toExpr()),
+                                
Arrays.stream(arrays).map(ApiExpressionUtils::objectToExpression))
+                        .toArray(Expression[]::new);
+        return toApiSpecificExpression(unresolvedCall(ARRAY_CONCAT, args));
+    }
+
+    private InType[] convertToArrays(InType[] arrays) {

Review Comment:
   Yes, we do. Because In Java, the varargs ... treats a single argument as a 
standalone argument rather than an array of arguments. Therefore, If I pass an 
argument [[1,2,3]] to a method that accepts InType... arrays, Java will treat 
it as [1,2,3], not [[1,2,3]].  If I pass array[[1,2,3]] to the Intype... this 
time arrays[0] is not [1,2,3] it will become 1,  and when you run the test 
cases, without this function, array_concat(f0, array[1,2,3]) will become to 
array_concat(f0, 1, 2, 3), but we want to concat f0 and array[1,2,3] but not 
concat f0 with 1, 2, 3



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/BaseExpressions.java:
##########
@@ -1407,6 +1409,44 @@ public OutType arrayUnion(InType array) {
                 unresolvedCall(ARRAY_UNION, toExpr(), 
objectToExpression(array)));
     }
 
+    /**
+     * Returns an array of the elements in the concat of array1 and array2, 
without duplicates.
+     *
+     * <p>If both of the array are null, the function will return null.
+     */
+    public OutType arrayConcat(InType... arrays) {
+        arrays = convertToArrays(arrays);
+        Expression[] args =
+                Stream.concat(
+                                Stream.of(toExpr()),
+                                
Arrays.stream(arrays).map(ApiExpressionUtils::objectToExpression))
+                        .toArray(Expression[]::new);
+        return toApiSpecificExpression(unresolvedCall(ARRAY_CONCAT, args));
+    }
+
+    private InType[] convertToArrays(InType[] arrays) {
+        if (arrays == null || arrays.length < 1) {
+            throw new ValidationException("need at least two arrays");
+        }
+        int numberOfNull = 0;
+        InType notNullArray = null;
+        for (int i = 0; i < arrays.length; ++i) {
+            if (arrays[i] == null) {
+                numberOfNull++;
+            } else {
+                notNullArray = arrays[i];

Review Comment:
   If I want concat(f0, array[null, null, 1]), the InType...  arrays   is null, 
null, 1, in this situation, I want to transfer null, null, 1 to an array[null, 
null, null] the notNullArray is use to check whether input is array or only an 
element



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