You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/08/01 12:32:41 UTC
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #6936: feat: reading array elements
alamb commented on code in PR #6936:
URL: https://github.com/apache/arrow-datafusion/pull/6936#discussion_r1280562577
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -363,6 +363,177 @@ pub fn make_array(arrays: &[ArrayRef]) -> Result<ArrayRef> {
}
}
+fn return_empty(return_null: bool, data_type: DataType) -> Arc<dyn Array> {
+ if return_null {
+ new_null_array(&data_type, 1)
+ } else {
+ new_empty_array(&data_type)
+ }
+}
+
+macro_rules! list_slice {
+ ($ARRAY:expr, $I:expr, $J:expr, $RETURN_ELEMENT:expr, $ARRAY_TYPE:ident) => {{
+ let array = $ARRAY.as_any().downcast_ref::<$ARRAY_TYPE>().unwrap();
+ if $I == 0 && $J == 0 || $ARRAY.is_empty() {
+ return return_empty($RETURN_ELEMENT, $ARRAY.data_type().clone());
+ }
+
+ let i = if $I < 0 {
+ if $I.abs() as usize > array.len() {
+ return return_empty(true, $ARRAY.data_type().clone());
+ }
+
+ (array.len() as i64 + $I + 1) as usize
+ } else {
+ if $I == 0 {
+ 1
+ } else {
+ $I as usize
+ }
+ };
+ let j = if $J < 0 {
+ if $J.abs() as usize > array.len() {
+ return return_empty(true, $ARRAY.data_type().clone());
+ }
+
+ if $RETURN_ELEMENT {
+ (array.len() as i64 + $J + 1) as usize
+ } else {
+ (array.len() as i64 + $J) as usize
+ }
+ } else {
+ if $J == 0 {
+ 1
+ } else {
+ if $J as usize > array.len() {
+ array.len()
+ } else {
+ $J as usize
+ }
+ }
+ };
+
+ if i > j || i as usize > $ARRAY.len() {
+ return_empty($RETURN_ELEMENT, $ARRAY.data_type().clone())
+ } else {
+ Arc::new(array.slice((i - 1), (j + 1 - i)))
+ }
+ }};
+}
+
+macro_rules! slice {
Review Comment:
> I don't quite comprehend your comment. If I use take kernel with ListArray, the program returns me the elements of ListArray (i. e. Array instances). So if it's really worth it can you give me more information how should I take data?
I was thinking we call `take()` with the values array (like `take(list_array.values(), indices`)
--
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-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org