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


##########
docs/source/user-guide/expressions.md:
##########
@@ -238,7 +238,7 @@ select log(-1), log(0), sqrt(-1);
 | array_intersect(array1, array2)                | Returns an array of the 
elements in the intersection of array1 and array2. `array_intersect([1, 2, 3, 
4], [5, 6, 3, 4]) -> [3, 4]`                                                    
                                  |
 | array_union(array1, array2)                    | Returns an array of the 
elements in the union of array1 and array2 without duplicates. `array_union([1, 
2, 3, 4], [5, 6, 3, 4]) -> [1, 2, 3, 4, 5, 6]`                                  
                                |
 | array_except(array1, array2)                   | Returns an array of the 
elements that appear in the first array but not in the second. 
`array_except([1, 2, 3, 4], [5, 6, 3, 4]) -> [3, 4]`                            
                                                 |
-| array_resize(array, size, value)               | Resizes the list to contain 
size elements. Initializes new elements with value or empty if value is not 
set. `array_resize([1, 2, 3], 5, 0) -> [1, 2, 3, 4, 5, 6]`                      
                                |
+| array_resize(array, size, value)               | Resizes the list to contain 
size elements. Initializes new elements with value or empty if value is not 
set. `array_resize([1, 2, 3], 5, 0) -> [1, 2, 3, 0, 0]`                         
                                |

Review Comment:
   👍 



##########
datafusion/functions-array/src/udf.rs:
##########
@@ -426,6 +426,70 @@ impl ScalarUDFImpl for ArraySort {
     }
 }
 
+make_udf_function!(
+    ArrayResize,
+    array_resize,
+    array size value,
+    "returns an array with the specified size filled with the given value.",
+    array_resize_udf
+);
+
+#[derive(Debug)]
+pub(super) struct ArrayResize {
+    signature: Signature,
+    aliases: Vec<String>,
+}
+
+impl ArrayResize {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::variadic_any(Volatility::Immutable),
+            aliases: vec!["array_resize".to_string(), 
"list_resize".to_string()],
+        }
+    }
+}
+
+impl ScalarUDFImpl for ArrayResize {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+    fn name(&self) -> &str {
+        "array_resize"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
+        use DataType::*;
+        match &arg_types[0] {
+            List(field) | FixedSizeList(field, _) => 
Ok(List(Arc::new(Field::new(
+                "item",
+                field.data_type().clone(),
+                true,
+            )))),
+            LargeList(field) => Ok(LargeList(Arc::new(Field::new(
+                "item",
+                field.data_type().clone(),
+                true,
+            )))),
+            _ => exec_err!(

Review Comment:
   
   nit
   ```suggestion
               List(field) | FixedSizeList(field, _) => Ok(List(field.clone())),
               LargeList(field) => Ok(LargeList(field.clone())),
   ```



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