vegarsti commented on code in PR #9347:
URL: https://github.com/apache/arrow-rs/pull/9347#discussion_r2759025843
##########
arrow-ord/src/comparison.rs:
##########
@@ -807,51 +888,103 @@ mod tests {
// contains(null, null) = false
#[test]
fn test_contains() {
- let value_data = Int32Array::from(vec![
- Some(0),
- Some(1),
- Some(2),
- Some(3),
- Some(4),
- Some(5),
- Some(6),
- None,
- Some(7),
- ])
- .into_data();
- let value_offsets = Buffer::from_slice_ref([0i64, 3, 6, 6, 9]);
- let list_data_type =
-
DataType::LargeList(Arc::new(Field::new_list_field(DataType::Int32, true)));
- let list_data = ArrayData::builder(list_data_type)
- .len(4)
- .add_buffer(value_offsets)
- .add_child_data(value_data)
- .null_bit_buffer(Some(Buffer::from([0b00001011])))
- .build()
- .unwrap();
-
- // [[0, 1, 2], [3, 4, 5], null, [6, null, 7]]
- let list_array = LargeListArray::from(list_data);
-
+ // Test data: [[0, 1, 2], [3, 4, 5], null, [6, null, 7]]
let nulls = Int32Array::from(vec![None, None, None, None]);
- let nulls_result = in_list(&nulls, &list_array).unwrap();
- assert_eq!(
- nulls_result
- .as_any()
- .downcast_ref::<BooleanArray>()
- .unwrap(),
- &BooleanArray::from(vec![false, false, false, false]),
- );
-
let values = Int32Array::from(vec![Some(0), Some(0), Some(0),
Some(0)]);
- let values_result = in_list(&values, &list_array).unwrap();
- assert_eq!(
- values_result
- .as_any()
- .downcast_ref::<BooleanArray>()
- .unwrap(),
- &BooleanArray::from(vec![true, false, false, false]),
- );
+ let nulls_expected = BooleanArray::from(vec![false, false, false,
false]);
+ let values_expected = BooleanArray::from(vec![true, false, false,
false]);
+
+ // Test with List
+ {
+ let value_data = Int32Array::from(vec![
+ Some(0),
+ Some(1),
+ Some(2),
+ Some(3),
+ Some(4),
+ Some(5),
+ Some(6),
+ None,
+ Some(7),
+ ])
+ .into_data();
+ let value_offsets = Buffer::from_slice_ref([0i64, 3, 6, 6, 9]);
+ let list_data_type =
+
DataType::LargeList(Arc::new(Field::new_list_field(DataType::Int32, true)));
+ let list_data = ArrayData::builder(list_data_type)
+ .len(4)
+ .add_buffer(value_offsets)
+ .add_child_data(value_data)
+ .null_bit_buffer(Some(Buffer::from([0b00001011])))
+ .build()
+ .unwrap();
+
+ let list_array = LargeListArray::from(list_data);
+
+ let nulls_result = in_list(&nulls, &list_array).unwrap();
+ assert_eq!(
+ nulls_result
+ .as_any()
+ .downcast_ref::<BooleanArray>()
+ .unwrap(),
+ &nulls_expected,
+ );
+
+ let values_result = in_list(&values, &list_array).unwrap();
+ assert_eq!(
+ values_result
+ .as_any()
+ .downcast_ref::<BooleanArray>()
+ .unwrap(),
+ &values_expected,
+ );
+ }
+
+ // Test with ListView (same data, same expected results)
Review Comment:
Nice!
##########
arrow-ord/src/comparison.rs:
##########
@@ -109,14 +109,95 @@ where
Ok(BooleanArray::new(values, None))
}
+/// Checks if a [`GenericListViewArray`] contains a value in the
[`PrimitiveArray`]
+pub fn in_list_view<T, OffsetSize>(
+ left: &PrimitiveArray<T>,
+ right: &GenericListViewArray<OffsetSize>,
+) -> Result<BooleanArray, ArrowError>
+where
+ T: ArrowNumericType,
+ OffsetSize: OffsetSizeTrait,
+{
+ let left_len = left.len();
+ if left_len != right.len() {
+ return Err(ArrowError::ComputeError(
+ "Cannot perform comparison operation on arrays of different
length".to_string(),
+ ));
+ }
+
+ let num_bytes = bit_util::ceil(left_len, 8);
Review Comment:
Why? 🤔
##########
arrow-ord/src/comparison.rs:
##########
@@ -109,14 +109,95 @@ where
Ok(BooleanArray::new(values, None))
}
+/// Checks if a [`GenericListViewArray`] contains a value in the
[`PrimitiveArray`]
Review Comment:
I see that this sentence is the same on the other methods, but I was a bit
thrown by the "a value" here. Checking my understanding here: Does this
function return an array where element i indicates whether element i of the
PrimitiveArray is contained in the GenericListViewArray?
--
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]