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


##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -369,56 +369,62 @@ pub fn make_array(arrays: &[ArrayRef]) -> 
Result<ArrayRef> {
     }
 }
 
-/// array_element SQL function
-///
-/// There are two arguments for array_element, the first one is the array, the 
second one is the 1-indexed index.
-/// `array_element(array, index)`
-///
-/// For example:
-/// > array_element(\[1, 2, 3], 2) -> 2
-pub fn array_element(args: &[ArrayRef]) -> Result<ArrayRef> {
-    let list_array = as_list_array(&args[0])?;
-    let indexes = as_int64_array(&args[1])?;
-
-    let values = list_array.values();
+fn general_array_element<O: OffsetSizeTrait>(
+    array: &GenericListArray<O>,
+    indexes: &Int64Array,
+) -> Result<ArrayRef>
+where
+    i64: TryInto<O>,
+{
+    let values = array.values();
     let original_data = values.to_data();
     let capacity = Capacities::Array(original_data.len());
 
     // use_nulls: true, we don't construct List for array_element, so we need 
explicit nulls.
     let mut mutable =
         MutableArrayData::with_capacities(vec![&original_data], true, 
capacity);
 
-    fn adjusted_array_index(index: i64, len: usize) -> Option<i64> {
+    fn adjusted_array_index<O: OffsetSizeTrait>(index: i64, len: O) -> 
Result<Option<O>>
+    where
+        i64: TryInto<O>,
+    {
+        let index: O = index.try_into().map_err(|_| {
+            DataFusionError::Execution(format!(

Review Comment:
   We cannot use marco here because of `map_err`



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