jayzhan211 commented on code in PR #9343:
URL: https://github.com/apache/arrow-datafusion/pull/9343#discussion_r1504285654
##########
datafusion/functions-array/src/udf.rs:
##########
@@ -75,8 +115,252 @@ impl ScalarUDFImpl for ArrayToString {
}
fn invoke(&self, args: &[ColumnarValue]) ->
datafusion_common::Result<ColumnarValue> {
- let args = ColumnarValue::values_to_arrays(args)?;
- crate::kernels::array_to_string(&args).map(ColumnarValue::Array)
+ make_scalar_function_with_hints(crate::kernels::array_to_string)(args)
+ }
+
+ fn aliases(&self) -> &[String] {
+ &self.aliases
+ }
+}
+
+#[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
+ }
+}
+
+#[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
+ }
+}
+
+#[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"),
+ ],
+ }
+ }
+
+ /// Returns the dimension [`DataType`] of [`DataType::List`] if
+ /// treated as a N-dimensional array.
+ ///
+ /// ## Examples:
+ ///
+ /// * `Int64` has dimension 1
+ /// * `List(Int64)` has dimension 2
+ /// * `List(List(Int64))` has dimension 3
+ /// * etc.
+ fn return_dimension(&self, input_expr_type: &DataType) -> u64 {
Review Comment:
You can try if it is possible to replace it with `list_ndims`, but it is
fine not to do so in this PR.
--
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]