You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2021/07/20 18:01:51 UTC
[arrow-rs] branch master updated: Fix array equal check (#571)
This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new bd9f67a Fix array equal check (#571)
bd9f67a is described below
commit bd9f67aeca45513fcc15d0378bf8e6637acfcefc
Author: Ruihang Xia <wa...@gmail.com>
AuthorDate: Wed Jul 21 02:01:44 2021 +0800
Fix array equal check (#571)
* pin this bug down & fix
Signed-off-by: Ruihang Xia <wa...@gmail.com>
* tidy
Signed-off-by: Ruihang Xia <wa...@gmail.com>
* add some test cases
Signed-off-by: Ruihang Xia <wa...@gmail.com>
---
arrow/src/array/array_list.rs | 72 +++++++++++++++++++++++++++++++++++++++
arrow/src/array/equal/utils.rs | 2 +-
arrow/src/compute/kernels/sort.rs | 2 +-
3 files changed, 74 insertions(+), 2 deletions(-)
diff --git a/arrow/src/array/array_list.rs b/arrow/src/array/array_list.rs
index 0efb65c..990ec8a 100644
--- a/arrow/src/array/array_list.rs
+++ b/arrow/src/array/array_list.rs
@@ -1090,4 +1090,76 @@ mod tests {
.build();
ListArray::from(list_data);
}
+
+ #[test]
+ fn list_array_equality() {
+ // test scaffold
+ fn do_comparison(
+ lhs_data: Vec<Option<Vec<Option<i32>>>>,
+ rhs_data: Vec<Option<Vec<Option<i32>>>>,
+ should_equal: bool,
+ ) {
+ let lhs = ListArray::from_iter_primitive::<Int32Type, _, _>(lhs_data.clone());
+ let rhs = ListArray::from_iter_primitive::<Int32Type, _, _>(rhs_data.clone());
+ assert_eq!(lhs == rhs, should_equal);
+
+ let lhs = LargeListArray::from_iter_primitive::<Int32Type, _, _>(lhs_data);
+ let rhs = LargeListArray::from_iter_primitive::<Int32Type, _, _>(rhs_data);
+ assert_eq!(lhs == rhs, should_equal);
+ }
+
+ do_comparison(
+ vec![
+ Some(vec![Some(0), Some(1), Some(2)]),
+ None,
+ Some(vec![Some(3), None, Some(5)]),
+ Some(vec![Some(6), Some(7)]),
+ ],
+ vec![
+ Some(vec![Some(0), Some(1), Some(2)]),
+ None,
+ Some(vec![Some(3), None, Some(5)]),
+ Some(vec![Some(6), Some(7)]),
+ ],
+ true,
+ );
+
+ do_comparison(
+ vec![
+ None,
+ None,
+ Some(vec![Some(3), None, Some(5)]),
+ Some(vec![Some(6), Some(7)]),
+ ],
+ vec![
+ Some(vec![Some(0), Some(1), Some(2)]),
+ None,
+ Some(vec![Some(3), None, Some(5)]),
+ Some(vec![Some(6), Some(7)]),
+ ],
+ false,
+ );
+
+ do_comparison(
+ vec![
+ None,
+ None,
+ Some(vec![Some(3), None, Some(5)]),
+ Some(vec![Some(6), Some(7)]),
+ ],
+ vec![
+ None,
+ None,
+ Some(vec![Some(3), None, Some(5)]),
+ Some(vec![Some(0), Some(0)]),
+ ],
+ false,
+ );
+
+ do_comparison(
+ vec![None, None, Some(vec![Some(1)])],
+ vec![None, None, Some(vec![Some(2)])],
+ false,
+ );
+ }
}
diff --git a/arrow/src/array/equal/utils.rs b/arrow/src/array/equal/utils.rs
index d0108d2..2a1ce88 100644
--- a/arrow/src/array/equal/utils.rs
+++ b/arrow/src/array/equal/utils.rs
@@ -187,7 +187,7 @@ fn logical_list_bitmap<OffsetSize: OffsetSizeTrait>(
offsets
.windows(2)
.enumerate()
- .take(offset_len - offset_start)
+ .take(parent_data.len())
.for_each(|(index, window)| {
let start = window[0].to_usize().unwrap();
let end = window[1].to_usize().unwrap();
diff --git a/arrow/src/compute/kernels/sort.rs b/arrow/src/compute/kernels/sort.rs
index 54529fa..ee723da 100644
--- a/arrow/src/compute/kernels/sort.rs
+++ b/arrow/src/compute/kernels/sort.rs
@@ -2347,7 +2347,7 @@ mod tests {
nulls_first: true,
}),
Some(3),
- vec![None, None, Some(vec![Some(2)])],
+ vec![None, None, Some(vec![Some(1)])],
None,
);