github-actions[bot] commented on code in PR #65267:
URL: https://github.com/apache/doris/pull/65267#discussion_r3529989437


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayRemove.java:
##########
@@ -78,6 +78,11 @@ public void checkLegalityBeforeTypeCoercion() {
                     || ((ArrayType) argType).getItemType().isJsonType())) {
             throw new AnalysisException("array_remove does not support types: 
" + argType.toSql());
         }
+        DataType itemType = getArgument(1).getDataType();
+        if (itemType.isComplexType() || itemType.isVariantType() || 
itemType.isJsonType()) {

Review Comment:
   This rejects more than the unsupported empty-array case. These legality 
checks run before `implicitCastInputTypes()`, but with a typed first argument 
the function signature already resolves the right side to the array item type 
through `FollowToAnyDataType(0)`. Doris also has scalar coercions for these raw 
types, for example `VariantType` to numeric/string targets and primitive 
`JsonType` to character targets in `TypeCoercionUtils.implicitCast()`. As 
written, cases such as `array_remove([1], cast('1' as variant))` or 
`array_position(['{}'], cast('{}' as json))` fail during this pre-coercion 
check even though the right argument would be cast to the supported item type 
before reaching BE. Please keep rejecting the bare-empty-array cases where 
JSON/VARIANT becomes the array element type, but do not reject a raw second 
argument that can be coerced to a concrete supported element type; add tests 
for both paths.



##########
regression-test/suites/query_p0/sql_functions/array_functions/test_array_nested_type_check.groovy:
##########
@@ -0,0 +1,61 @@
+// 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.
+
+suite("test_array_nested_type_check") {
+    sql "set enable_nereids_planner = true"
+    sql "set enable_fallback_to_original_planner = false"
+
+    test {
+        sql "explain verbose select array_union([], [[1]])"
+        exception "array_union does not support types: ARRAY<ARRAY<TINYINT>>"
+    }
+
+    test {
+        sql "select array_union([], [[1]])"
+        exception "array_union does not support types: ARRAY<ARRAY<TINYINT>>"
+    }
+
+    test {
+        sql "select arrays_overlap([], [[1]])"

Review Comment:
   This suite still misses the scalar set-operation sibling `array_intersect`. 
Its FE legality check only rejects `itemType.isComplexType()`, but `JsonType` 
and `VariantType` are primitive in Nereids, so `array_intersect(array(cast('{}' 
as json)), array(cast('{}' as json)))` and the VARIANT form can still analyze. 
The BE path is the same 
`FunctionArrayNary<ArrayMapImpl<MapOperation::INTERSECT>>` shape as the set 
functions, and `ArrayMapImpl` only dispatches `ALL_COLUMNS_SIMPLE`, which 
excludes JSONB/VARIANT and returns `Unexpected columns`. Please add the same 
JSON/VARIANT rejection to `ArrayIntersect` and cover it in this negative suite.



##########
regression-test/suites/query_p0/sql_functions/array_functions/test_array_nested_type_check.groovy:
##########
@@ -0,0 +1,61 @@
+// 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.
+
+suite("test_array_nested_type_check") {
+    sql "set enable_nereids_planner = true"
+    sql "set enable_fallback_to_original_planner = false"
+
+    test {
+        sql "explain verbose select array_union([], [[1]])"
+        exception "array_union does not support types: ARRAY<ARRAY<TINYINT>>"
+    }
+
+    test {
+        sql "select array_union([], [[1]])"
+        exception "array_union does not support types: ARRAY<ARRAY<TINYINT>>"
+    }
+
+    test {
+        sql "select arrays_overlap([], [[1]])"
+        exception "arrays_overlap does not support types: 
ARRAY<ARRAY<TINYINT>>"
+    }
+
+    test {
+        sql "select array_position([], [1])"
+        exception "array_position does not support types: 
ARRAY<ARRAY<TINYINT>>"
+    }
+
+    test {
+        sql "select array_position([], cast('{}' as json))"
+        exception "array_position does not support types: ARRAY<JSON>"
+    }
+
+    test {
+        sql "select array_position([], cast('{}' as variant))"
+        exception "array_position does not support types: ARRAY<variant"
+    }
+
+    test {
+        sql "select array_remove([], [1])"
+        exception "array_remove does not support types: ARRAY<ARRAY<TINYINT>>"
+    }
+
+    test {
+        sql "select countequal([], [1])"
+        exception "countequal does not support types: ARRAY<ARRAY<TINYINT>>"
+    }
+}

Review Comment:
   The aggregate siblings are still open for the same unsupported-element 
class. `group_array_union` and `group_array_intersect` accept `ArrayType.of(new 
AnyDataType(0))` in FE with no legality check, so inputs like 
`group_array_union([[1]])` or arrays of JSON/VARIANT can analyze. BE then 
removes the array nesting in `create_aggregate_function_group_array_impl()` and 
only creates an implementation for `dispatch_switch_scalar` or string types; 
for nested ARRAY/JSONB/VARIANT it logs `got invalid of nested type` and returns 
no implementation. Please reject these unsupported aggregate inputs during 
analysis as well, or add tests showing they already fail cleanly before BE 
execution.



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