Standing-Man commented on code in PR #16936:
URL: https://github.com/apache/datafusion/pull/16936#discussion_r2252846649


##########
datafusion/spark/src/function/array/spark_array.rs:
##########
@@ -0,0 +1,275 @@
+// 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.
+
+use std::{any::Any, sync::Arc};
+
+use arrow::array::{
+    make_array, new_null_array, Array, ArrayData, ArrayRef, Capacities, 
GenericListArray,
+    MutableArrayData, NullArray, OffsetSizeTrait,
+};
+use arrow::buffer::OffsetBuffer;
+use arrow::datatypes::{DataType, Field, FieldRef};
+use datafusion_common::utils::SingleRowListArrayBuilder;
+use datafusion_common::{plan_datafusion_err, plan_err, Result};
+use datafusion_expr::type_coercion::binary::comparison_coercion;
+use datafusion_expr::{
+    ColumnarValue, ReturnFieldArgs, ScalarFunctionArgs, ScalarUDFImpl, 
Signature,
+    TypeSignature, Volatility,
+};
+
+use crate::function::functions_nested_utils::make_scalar_function;
+
+const ARRAY_FIELD_DEFAULT_NAME: &str = "element";
+
+#[derive(Debug)]
+pub struct SparkArray {
+    signature: Signature,
+    aliases: Vec<String>,
+}
+
+impl Default for SparkArray {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
+impl SparkArray {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::one_of(
+                vec![TypeSignature::UserDefined, TypeSignature::Nullary],
+                Volatility::Immutable,
+            ),
+            aliases: vec![String::from("spark_make_array")],
+        }
+    }
+}
+
+impl ScalarUDFImpl for SparkArray {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn name(&self) -> &str {
+        "array"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
+        match arg_types.len() {
+            0 => Ok(empty_array_type()),
+            _ => {
+                let mut expr_type = DataType::Null;
+                for arg_type in arg_types {
+                    if !arg_type.equals_datatype(&DataType::Null) {
+                        expr_type = arg_type.clone();
+                        break;
+                    }
+                }
+
+                if expr_type.is_null() {
+                    expr_type = DataType::Int32;
+                }
+
+                Ok(DataType::List(Arc::new(Field::new_list_field(

Review Comment:
   Got it.



-- 
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...@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to