yujun777 commented on code in PR #69456:
URL: https://github.com/apache/doris/pull/69456#discussion_r4357870878


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArraySortedMerge.java:
##########
@@ -0,0 +1,142 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.expressions.functions.scalar;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.ArrayItemReference;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import 
org.apache.doris.nereids.trees.expressions.functions.ImplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.ArrayType;
+import org.apache.doris.nereids.types.BooleanType;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.LambdaType;
+import org.apache.doris.nereids.types.coercion.FollowToAnyDataType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * array_sorted_merge(merge_fn, arr1, arr2, is_asc): merge two arrays that are 
already sorted.
+ *
+ * <pre>
+ * array_sorted_merge((a, b) -&gt; ..., arr1, arr2, true)
+ * </pre>
+ *
+ * <p>The inputs must already be sorted by the elements' natural order in the 
direction given by
+ * {@code is_asc}; the function only merges them. The merge lambda receives 
the two current
+ * candidates as {@code (a, b)} and returns the combined element; returning 
NULL means the two
+ * elements must not be combined, so both are kept. Each key occurs at most 
once per input, so a
+ * key appears at most twice across the two arrays and the lambda is called at 
most once per key.
+ *
+ * <p>A NULL input array makes the result NULL, like the other higher-order 
array functions.
+ */
+public class ArraySortedMerge extends ScalarFunction
+        implements ImplicitlyCastableSignature, PropagateNullable {

Review Comment:
   Fixed in 8281c36a07d: the per-row null check of the ascending flag now runs 
before the branch that returns NULL for a NULL input array. The flag is an 
argument contract rather than data, so a backend-evaluated NULL flag now 
reports `array_sorted_merge requires a non-null ascending flag` even when the 
input array row is NULL; the same flag with a non-NULL array already failed.
   
   A NULL input array with a valid flag still returns NULL, and the 
literal-null-flag case is still rejected during analysis. 
`test_array_sorted_merge` adds `CAST(bitmap_min(bitmap_from_string('')) AS 
BOOLEAN)` with a NULL first array, alongside the existing non-NULL-array case.
   



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