Weijun-H commented on code in PR #9108:
URL: https://github.com/apache/arrow-datafusion/pull/9108#discussion_r1493916770


##########
datafusion/expr/src/signature.rs:
##########
@@ -123,29 +128,171 @@ pub enum TypeSignature {
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
 pub enum ArrayFunctionSignature {
     /// Specialized Signature for ArrayAppend and similar functions
-    /// The first argument should be List/LargeList, and the second argument 
should be non-list or list.
+    /// If `allow_null` is true, the function also accepts a single argument 
of type Null.
+    /// The first argument should be List/LargeList/FixedSizedList, and the 
second argument should be non-list or list.
     /// The second argument's list dimension should be one dimension less than 
the first argument's list dimension.
     /// List dimension of the List/LargeList is equivalent to the number of 
List.
     /// List dimension of the non-list is 0.
-    ArrayAndElement,
+    ArrayAndElement(bool),
     /// Specialized Signature for ArrayPrepend and similar functions
+    /// If `allow_null` is true, the function also accepts a single argument 
of type Null.
     /// The first argument should be non-list or list, and the second argument 
should be List/LargeList.
     /// The first argument's list dimension should be one dimension less than 
the second argument's list dimension.
-    ElementAndArray,
-    ArrayAndIndex,
+    ElementAndArray(bool),
+    /// Specialized Signature for ArrayEqual and similar functions
+    /// If `allow_null` is true, the function also accepts a single argument 
of type Null.
+    /// The first argument should be List/LargeList/FixedSizedList, and the 
second argument should be Int64.
+    ArrayAndIndex(bool),
+    /// Specialized Signature for ArrayEmpty and similar functions
+    /// The function takes a single argument that must be a 
List/LargeList/FixedSizeList
+    /// or something that can be coerced to one of those types.
+    /// If `allow_null` is true, the function also accepts a single argument 
of type Null.
+    Array(bool),
+}
+
+impl ArrayFunctionSignature {
+    /// Arguments to ArrayFunctionSignature
+    /// `current_types` - The data types of the arguments
+    /// `allow_null_coercion` - Whether null type coercion is allowed
+    /// Returns the valid types for the function signature
+    pub fn get_type_signature(
+        &self,
+        current_types: &[DataType],
+    ) -> Result<Vec<Vec<DataType>>> {
+        fn array_append_or_prepend_valid_types(
+            current_types: &[DataType],
+            is_append: bool,
+            allow_null_coercion: bool,
+        ) -> Result<Vec<Vec<DataType>>> {
+            if current_types.len() != 2 {
+                return Ok(vec![vec![]]);
+            }
+
+            let (array_type, elem_type) = if is_append {
+                (&current_types[0], &current_types[1])
+            } else {
+                (&current_types[1], &current_types[0])
+            };
+
+            // We follow Postgres on `array_append(Null, T)`, which is not 
valid.
+            if array_type.eq(&DataType::Null) && !allow_null_coercion {

Review Comment:
   `array_has` , `array_positions`, `array_remove` and `array_remove_all`should 
use it.
   ```
   D SELECT list_contains(null, 1);
   ┌────────────────────────┐
   │ list_contains(NULL, 1) │
   │         int32          │
   ├────────────────────────┤
   │                        │
   └────────────────────────┘
   
   D SELECT list_position(null, 1);
   ┌────────────────────────┐
   │ list_position(NULL, 1) │
   │         int32          │
   ├────────────────────────┤
   │                        │
   └────────────────────────┘
   
   ```
   
   ```
   **Schema (PostgreSQL v15)**
   
   ---
   
   **Query #1**
   
       SELECT array_remove(NULL, 2);
   
   | array_remove |
   | ------------ |
   |              |
   
   ```



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to