joroKr21 commented on code in PR #15149:
URL: https://github.com/apache/datafusion/pull/15149#discussion_r1997523937


##########
datafusion/functions-nested/src/dimension.rs:
##########
@@ -204,59 +194,57 @@ pub fn array_dims_inner(args: &[ArrayRef]) -> 
Result<ArrayRef> {
     let [array] = take_function_args("array_dims", args)?;
 
     let data = match array.data_type() {
-        List(_) => {
-            let array = as_list_array(&array)?;
-            array
-                .iter()
-                .map(compute_array_dims)
-                .collect::<Result<Vec<_>>>()?
-        }
-        LargeList(_) => {
-            let array = as_large_list_array(&array)?;
-            array
-                .iter()
-                .map(compute_array_dims)
-                .collect::<Result<Vec<_>>>()?
-        }
-        array_type => {
-            return exec_err!("array_dims does not support type 
'{array_type:?}'");
+        List(_) => as_list_array(&array)?
+            .iter()
+            .map(compute_array_dims)
+            .collect::<Result<Vec<_>>>()?,
+        LargeList(_) => as_large_list_array(&array)?
+            .iter()
+            .map(compute_array_dims)
+            .collect::<Result<Vec<_>>>()?,
+        arg_type => {
+            return exec_err!(
+                "array_dims does not support an argument of type {arg_type}"
+            );
         }
     };
 
     let result = ListArray::from_iter_primitive::<UInt64Type, _, _>(data);
-
-    Ok(Arc::new(result) as ArrayRef)
+    Ok(Arc::new(result))
 }
 
 /// Array_ndims SQL function
 pub fn array_ndims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
-    let [array_dim] = take_function_args("array_ndims", args)?;
+    let [array] = take_function_args("array_ndims", args)?;
 
     fn general_list_ndims<O: OffsetSizeTrait>(
         array: &GenericListArray<O>,
     ) -> Result<ArrayRef> {
-        let mut data = Vec::new();
-        let ndims = datafusion_common::utils::list_ndims(array.data_type());
-
+        let mut builder = UInt64Builder::with_capacity(array.len());
+        let ndims = list_ndims(array.data_type());
         for arr in array.iter() {
             if arr.is_some() {
-                data.push(Some(ndims))
+                builder.append_value(ndims)

Review Comment:
   I optimized it to use `vec![ndims; array.len()]` and just clone the null 
buffer from the array



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