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


##########
datafusion/functions-array/src/udf.rs:
##########
@@ -392,3 +397,259 @@ impl ScalarUDFImpl for ArrayNdims {
         &self.aliases
     }
 }
+
+make_udf_function!(
+    ArrayAppend,
+    array_append,
+    array element,                                         // arg name
+    "appends an element to the end of an array.", // doc
+    array_append_udf                              // internal function name

Review Comment:
   ```suggestion
       array element,
       "appends an element to the end of an array.",
       array_append_udf
   ```



##########
datafusion/functions-array/src/udf.rs:
##########
@@ -392,3 +397,259 @@ impl ScalarUDFImpl for ArrayNdims {
         &self.aliases
     }
 }
+
+make_udf_function!(
+    ArrayAppend,
+    array_append,
+    array element,                                         // arg name
+    "appends an element to the end of an array.", // doc
+    array_append_udf                              // internal function name
+);
+
+#[derive(Debug)]
+pub(super) struct ArrayAppend {
+    signature: Signature,
+    aliases: Vec<String>,
+}
+
+impl ArrayAppend {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::array_and_element(Volatility::Immutable),
+            aliases: vec![
+                String::from("array_append"),
+                String::from("list_append"),
+                String::from("array_push_back"),
+                String::from("list_push_back"),
+            ],
+        }
+    }
+}
+
+impl ScalarUDFImpl for ArrayAppend {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn name(&self) -> &str {
+        "array_append"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, arg_types: &[DataType]) -> 
datafusion_common::Result<DataType> {
+        Ok(arg_types[0].clone())
+    }
+
+    fn invoke(&self, args: &[ColumnarValue]) -> 
datafusion_common::Result<ColumnarValue> {
+        make_scalar_function_with_hints(crate::kernels::array_append)(args)
+    }
+
+    fn aliases(&self) -> &[String] {
+        &self.aliases
+    }
+}
+
+make_udf_function!(
+    ArrayPrepend,
+    array_prepend,
+    element array,                                                // arg name
+    "Prepends an element to the beginning of an array.", // doc
+    array_prepend_udf                                    // internal function 
name
+);
+
+#[derive(Debug)]
+pub(super) struct ArrayPrepend {
+    signature: Signature,
+    aliases: Vec<String>,
+}
+
+impl ArrayPrepend {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::element_and_array(Volatility::Immutable),
+            aliases: vec![
+                String::from("array_prepend"),
+                String::from("list_prepend"),
+                String::from("array_push_front"),
+                String::from("list_push_front"),
+            ],
+        }
+    }
+}
+
+impl ScalarUDFImpl for ArrayPrepend {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn name(&self) -> &str {
+        "array_prepend"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, arg_types: &[DataType]) -> 
datafusion_common::Result<DataType> {
+        Ok(arg_types[1].clone())
+    }
+
+    fn invoke(&self, args: &[ColumnarValue]) -> 
datafusion_common::Result<ColumnarValue> {
+        make_scalar_function_with_hints(crate::kernels::array_prepend)(args)
+    }
+
+    fn aliases(&self) -> &[String] {
+        &self.aliases
+    }
+}
+
+make_udf_function!(
+    ArrayConcat,
+    array_concat,
+    "Concatenates arrays.", // doc
+    array_concat_udf        // internal function name

Review Comment:
   ```suggestion
       "Concatenates arrays.",
       array_concat_udf
   ```



##########
datafusion/functions-array/src/udf.rs:
##########
@@ -392,3 +397,259 @@ impl ScalarUDFImpl for ArrayNdims {
         &self.aliases
     }
 }
+
+make_udf_function!(
+    ArrayAppend,
+    array_append,
+    array element,                                         // arg name
+    "appends an element to the end of an array.", // doc
+    array_append_udf                              // internal function name
+);
+
+#[derive(Debug)]
+pub(super) struct ArrayAppend {
+    signature: Signature,
+    aliases: Vec<String>,
+}
+
+impl ArrayAppend {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::array_and_element(Volatility::Immutable),
+            aliases: vec![
+                String::from("array_append"),
+                String::from("list_append"),
+                String::from("array_push_back"),
+                String::from("list_push_back"),
+            ],
+        }
+    }
+}
+
+impl ScalarUDFImpl for ArrayAppend {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn name(&self) -> &str {
+        "array_append"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, arg_types: &[DataType]) -> 
datafusion_common::Result<DataType> {
+        Ok(arg_types[0].clone())
+    }
+
+    fn invoke(&self, args: &[ColumnarValue]) -> 
datafusion_common::Result<ColumnarValue> {
+        make_scalar_function_with_hints(crate::kernels::array_append)(args)
+    }
+
+    fn aliases(&self) -> &[String] {
+        &self.aliases
+    }
+}
+
+make_udf_function!(
+    ArrayPrepend,
+    array_prepend,
+    element array,                                                // arg name
+    "Prepends an element to the beginning of an array.", // doc
+    array_prepend_udf                                    // internal function 
name

Review Comment:
   ```suggestion
       element array,
       "Prepends an element to the beginning of an array.",
       array_prepend_udf
   ```



##########
datafusion/functions-array/src/udf.rs:
##########
@@ -392,3 +397,259 @@ impl ScalarUDFImpl for ArrayNdims {
         &self.aliases
     }
 }
+
+make_udf_function!(
+    ArrayAppend,
+    array_append,
+    array element,                                         // arg name
+    "appends an element to the end of an array.", // doc
+    array_append_udf                              // internal function name
+);
+
+#[derive(Debug)]
+pub(super) struct ArrayAppend {
+    signature: Signature,
+    aliases: Vec<String>,
+}
+
+impl ArrayAppend {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::array_and_element(Volatility::Immutable),
+            aliases: vec![
+                String::from("array_append"),
+                String::from("list_append"),
+                String::from("array_push_back"),
+                String::from("list_push_back"),
+            ],
+        }
+    }
+}
+
+impl ScalarUDFImpl for ArrayAppend {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn name(&self) -> &str {
+        "array_append"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, arg_types: &[DataType]) -> 
datafusion_common::Result<DataType> {
+        Ok(arg_types[0].clone())
+    }
+
+    fn invoke(&self, args: &[ColumnarValue]) -> 
datafusion_common::Result<ColumnarValue> {
+        make_scalar_function_with_hints(crate::kernels::array_append)(args)
+    }
+
+    fn aliases(&self) -> &[String] {
+        &self.aliases
+    }
+}
+
+make_udf_function!(
+    ArrayPrepend,
+    array_prepend,
+    element array,                                                // arg name
+    "Prepends an element to the beginning of an array.", // doc
+    array_prepend_udf                                    // internal function 
name
+);
+
+#[derive(Debug)]
+pub(super) struct ArrayPrepend {
+    signature: Signature,
+    aliases: Vec<String>,
+}
+
+impl ArrayPrepend {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::element_and_array(Volatility::Immutable),
+            aliases: vec![
+                String::from("array_prepend"),
+                String::from("list_prepend"),
+                String::from("array_push_front"),
+                String::from("list_push_front"),
+            ],
+        }
+    }
+}
+
+impl ScalarUDFImpl for ArrayPrepend {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn name(&self) -> &str {
+        "array_prepend"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, arg_types: &[DataType]) -> 
datafusion_common::Result<DataType> {
+        Ok(arg_types[1].clone())
+    }
+
+    fn invoke(&self, args: &[ColumnarValue]) -> 
datafusion_common::Result<ColumnarValue> {
+        make_scalar_function_with_hints(crate::kernels::array_prepend)(args)
+    }
+
+    fn aliases(&self) -> &[String] {
+        &self.aliases
+    }
+}
+
+make_udf_function!(
+    ArrayConcat,
+    array_concat,
+    "Concatenates arrays.", // doc
+    array_concat_udf        // internal function name
+);
+
+#[derive(Debug)]
+pub(super) struct ArrayConcat {
+    signature: Signature,
+    aliases: Vec<String>,
+}
+
+impl ArrayConcat {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::variadic_any(Volatility::Immutable),
+            aliases: vec![
+                String::from("array_concat"),
+                String::from("array_cat"),
+                String::from("list_concat"),
+                String::from("list_cat"),
+            ],
+        }
+    }
+}
+
+impl ScalarUDFImpl for ArrayConcat {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn name(&self) -> &str {
+        "array_concat"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, arg_types: &[DataType]) -> 
datafusion_common::Result<DataType> {
+        let mut expr_type = DataType::Null;
+        let mut max_dims = 0;
+        for arg_type in arg_types {
+            match arg_type {
+                DataType::List(field) => {
+                    if !field.data_type().equals_datatype(&DataType::Null) {
+                        let dims = list_ndims(arg_type);
+                        expr_type = match max_dims.cmp(&dims) {
+                            Ordering::Greater => expr_type,
+                            Ordering::Equal => get_wider_type(&expr_type, 
arg_type)?,
+                            Ordering::Less => {
+                                max_dims = dims;
+                                arg_type.clone()
+                            }
+                        };
+                    }
+                }
+                _ => {
+                    return plan_err!(
+                        "The array_concat function can only accept list as the 
args."
+                    )
+                }
+            }
+        }
+
+        Ok(expr_type)
+    }
+
+    fn invoke(&self, args: &[ColumnarValue]) -> 
datafusion_common::Result<ColumnarValue> {
+        make_scalar_function_with_hints(crate::kernels::array_concat)(args)
+    }
+
+    fn aliases(&self) -> &[String] {
+        &self.aliases
+    }
+}
+
+make_udf_function!(
+    MakeArray,
+    make_array,
+    "Returns an Arrow array using the specified input expressions.", // doc
+    make_array_udf // internal function name

Review Comment:
   ```suggestion
       "Returns an Arrow array using the specified input expressions.",
       make_array_udf
   ```



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