-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-11239: [Rust] Fixed equality with offsets and nulls #9211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5716d91
c28e579
98ba168
134a0e3
746fd2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,15 +144,15 @@ pub(super) fn list_equal<T: OffsetSizeTrait>( | |
| ) | ||
| } else { | ||
| // get a ref of the parent null buffer bytes, to use in testing for nullness | ||
| let lhs_null_bytes = rhs_nulls.unwrap().as_slice(); | ||
| let lhs_null_bytes = lhs_nulls.unwrap().as_slice(); | ||
| let rhs_null_bytes = rhs_nulls.unwrap().as_slice(); | ||
| // with nulls, we need to compare item by item whenever it is not null | ||
| (0..len).all(|i| { | ||
| let lhs_pos = lhs_start + i; | ||
| let rhs_pos = rhs_start + i; | ||
|
|
||
| let lhs_is_null = !get_bit(lhs_null_bytes, lhs_pos); | ||
| let rhs_is_null = !get_bit(rhs_null_bytes, rhs_pos); | ||
| let lhs_is_null = !get_bit(lhs_null_bytes, lhs_pos + lhs.offset()); | ||
|
||
| let rhs_is_null = !get_bit(rhs_null_bytes, rhs_pos + rhs.offset()); | ||
|
|
||
| lhs_is_null | ||
| || (lhs_is_null == rhs_is_null) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -329,9 +329,10 @@ mod tests { | |
|
|
||
| let b = BooleanArray::from(vec![false, false, false]).data(); | ||
| test_equal(a.as_ref(), b.as_ref(), false); | ||
| } | ||
|
|
||
| // Test the case where null_count > 0 | ||
|
|
||
| #[test] | ||
| fn test_boolean_equal_null() { | ||
| let a = BooleanArray::from(vec![Some(false), None, None, Some(true)]).data(); | ||
| let b = BooleanArray::from(vec![Some(false), None, None, Some(true)]).data(); | ||
| test_equal(a.as_ref(), b.as_ref(), true); | ||
|
|
@@ -341,23 +342,25 @@ mod tests { | |
|
|
||
| let b = BooleanArray::from(vec![Some(true), None, None, Some(true)]).data(); | ||
| test_equal(a.as_ref(), b.as_ref(), false); | ||
| } | ||
|
|
||
| // Test the case where offset != 0 | ||
|
|
||
| #[test] | ||
| fn test_boolean_equal_offset() { | ||
| let a = | ||
| BooleanArray::from(vec![false, true, false, true, false, false, true]).data(); | ||
| let b = | ||
| BooleanArray::from(vec![false, false, false, true, false, true, true]).data(); | ||
| BooleanArray::from(vec![true, false, false, false, true, false, true, true]) | ||
| .data(); | ||
| assert_eq!(equal(a.as_ref(), b.as_ref()), false); | ||
| assert_eq!(equal(b.as_ref(), a.as_ref()), false); | ||
|
|
||
| let a_slice = a.slice(2, 3); | ||
| let b_slice = b.slice(2, 3); | ||
| let b_slice = b.slice(3, 3); | ||
| assert_eq!(equal(&a_slice, &b_slice), true); | ||
| assert_eq!(equal(&b_slice, &a_slice), true); | ||
|
|
||
| let a_slice = a.slice(3, 4); | ||
| let b_slice = b.slice(3, 4); | ||
| let b_slice = b.slice(4, 4); | ||
| assert_eq!(equal(&a_slice, &b_slice), false); | ||
| assert_eq!(equal(&b_slice, &a_slice), false); | ||
|
|
||
|
|
@@ -437,6 +440,20 @@ mod tests { | |
| (2, 1), | ||
| true, | ||
| ), | ||
| ( | ||
| vec![None, Some(2), None], | ||
| (1, 1), | ||
| vec![None, None, Some(2)], | ||
| (2, 1), | ||
| true, | ||
| ), | ||
| ( | ||
| vec![Some(1), None, Some(2), None, Some(3)], | ||
| (2, 2), | ||
| vec![None, Some(2), None, Some(3)], | ||
| (1, 2), | ||
| true, | ||
| ), | ||
| ]; | ||
|
|
||
| for (lhs, slice_lhs, rhs, slice_rhs, expected) in cases { | ||
|
|
@@ -541,6 +558,26 @@ mod tests { | |
| test_generic_binary_equal::<i64>() | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_string_offset() { | ||
| let a = StringArray::from(vec![Some("a"), None, Some("b")]).data(); | ||
| let a = a.slice(2, 1); | ||
| let b = StringArray::from(vec![Some("b")]).data(); | ||
|
|
||
| test_equal(&a, b.as_ref(), true); | ||
| } | ||
|
|
||
|
||
| #[test] | ||
| fn test_string_offset_larger() { | ||
| let a = | ||
| StringArray::from(vec![Some("a"), None, Some("b"), None, Some("c")]).data(); | ||
| let b = StringArray::from(vec![None, Some("b"), None, Some("c")]).data(); | ||
|
|
||
| test_equal(&a.slice(2, 2), &b.slice(0, 2), false); | ||
| test_equal(&a.slice(2, 2), &b.slice(1, 2), true); | ||
| test_equal(&a.slice(2, 2), &b.slice(2, 2), false); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_null() { | ||
| let a = NullArray::new(2).data(); | ||
|
|
@@ -781,6 +818,7 @@ mod tests { | |
| None, | ||
| ]); | ||
| let b = create_decimal_array(&[ | ||
| None, | ||
| Some(8_887_000_000), | ||
| None, | ||
| None, | ||
|
|
@@ -790,23 +828,23 @@ mod tests { | |
| ]); | ||
|
|
||
| let a_slice = a.slice(0, 3); | ||
| let b_slice = b.slice(0, 3); | ||
| let b_slice = b.slice(1, 3); | ||
| test_equal(&a_slice, &b_slice, true); | ||
|
|
||
| let a_slice = a.slice(0, 5); | ||
| let b_slice = b.slice(0, 5); | ||
| let b_slice = b.slice(1, 5); | ||
| test_equal(&a_slice, &b_slice, false); | ||
|
|
||
| let a_slice = a.slice(4, 1); | ||
| let b_slice = b.slice(4, 1); | ||
| let b_slice = b.slice(5, 1); | ||
| test_equal(&a_slice, &b_slice, true); | ||
|
|
||
| let a_slice = a.slice(3, 3); | ||
| let b_slice = b.slice(3, 3); | ||
| let b_slice = b.slice(4, 3); | ||
| test_equal(&a_slice, &b_slice, false); | ||
|
|
||
| let a_slice = a.slice(1, 3); | ||
| let b_slice = b.slice(1, 3); | ||
| let b_slice = b.slice(2, 3); | ||
| test_equal(&a_slice, &b_slice, false); | ||
|
|
||
| let b = create_decimal_array(&[ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while reviewing, got this one also. xD