HappenLee commented on code in PR #67822:
URL: https://github.com/apache/doris/pull/67822#discussion_r4059227413


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ArrayFunctionTypeChecker.java:
##########
@@ -0,0 +1,68 @@
+// 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;
+
+import org.apache.doris.nereids.types.ArrayType;
+import org.apache.doris.nereids.types.DataType;
+
+/**
+ * Element type checks that are specific to array function implementations.
+ * These restrictions are checked against the original argument types before 
type coercion.
+ */
+public final class ArrayFunctionTypeChecker {
+
+    private ArrayFunctionTypeChecker() {
+    }
+
+    /** Whether the element type is supported by hash-based array set 
functions. */
+    public static boolean isSupportedByArraySetFunctions(DataType dataType) {
+        return dataType.isNumericType() || dataType.isBooleanType() || 
dataType.isStringLikeType()
+                || dataType.isDateLikeType() || dataType.isIPType() || 
dataType.isNullType();
+    }
+
+    /** Whether the element type is supported by array equality and hash 
functions. */
+    public static boolean isSupportedByArrayEqualityFunctions(DataType 
dataType) {
+        return isSupportedByArraySetFunctions(dataType) || 
dataType.isTimeType();
+    }
+
+    /** Whether array comparison functions can compare this element type. */
+    public static boolean isSupportedByArrayComparisonFunctions(DataType 
dataType) {
+        if (dataType.isArrayType()) {
+            return isSupportedByArrayComparisonFunctions(((ArrayType) 
dataType).getItemType());
+        }
+        return !dataType.isOnlyMetricType();
+    }
+
+    /** Whether the element type is supported by the lambda array_sort 
implementation. */
+    public static boolean isSupportedByArraySortLambdaFunction(DataType 
dataType) {
+        return dataType.isNumericType() || dataType.isBooleanType() || 
dataType.isStringLikeType()
+                || dataType.isVarBinaryType() || dataType.isArrayType() || 
dataType.isIPType()
+                || dataType.isDateLikeType() || dataType.isTimeType();

Review Comment:
   [P2] Preserve NULL element types in lambda array_sort
   
   This new allowlist omits `NullType`, so both of these inputs now fail FE 
analysis with `array_sort does not support types: ARRAY<NULL>`:
   
   ```sql
   SELECT array_sort((x, y) -> 0, []);
   SELECT array_sort((x, y) -> 0, [NULL, NULL]);
   ```
   
   I confirmed both rejections with local FE analysis tests on `7905449d58d`. 
Empty and all-NULL array literals have `ARRAY<NULL>` type, and the new check in 
`ArraySort.checkLegalityBeforeTypeCoercion()` rejects them before signature 
resolution. The previous check allowed these inputs; BE's `DataTypeFactory` 
maps `TYPE_NULL` to `DataTypeUInt8`, which the lambda sorter supports through 
its `TYPE_BOOLEAN` dispatch.
   
   Please include `dataType.isNullType()` in this lambda-specific predicate and 
add positive regression cases for both inputs, expecting `[]` and `[null, 
null]`, respectively. The FE rejection was reproduced locally; the BE mapping 
was verified by code inspection, without running an end-to-end BE test.



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