alamb commented on code in PR #8170:
URL: https://github.com/apache/arrow-datafusion/pull/8170#discussion_r1393410774
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -131,6 +131,78 @@ macro_rules! array {
}};
}
+/// Computes a BooleanArray indicating equality or inequality between elements
in a list array and a specified element array.
Review Comment:
❤️
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -131,6 +131,78 @@ macro_rules! array {
}};
}
+/// Computes a BooleanArray indicating equality or inequality between elements
in a list array and a specified element array.
+///
+/// # Arguments
+///
+/// * `list_array_row` - A reference to a trait object implementing the Arrow
`Array` trait. It represents the list array for which the equality or
inequality will be compared.
+///
+/// * `element_array` - A reference to a trait object implementing the Arrow
`Array` trait. It represents the array with which each element in the
`list_array_row` will be compared.
+///
+/// * `row_index` - The index of the row in the `element_array` and
`list_array` to use for the comparison.
+///
+/// * `eq` - A boolean flag. If `true`, the function computes equality; if
`false`, it computes inequality.
+///
+/// # Returns
+///
+/// Returns a `Result<BooleanArray>` representing the comparison results. The
result may contain an error if there are issues with the computation.
+///
+/// # Example
+///
+/// ```text
+/// compare_element_to_list(
+/// [1, 2, 3], [1, 2, 3], 0, true => [true, false, false]
+/// [1, 2, 3, 3, 2, 1], [1, 2, 3], 1, true => [false, true, false, false,
true, false]
+///
+/// [[1, 2, 3], [2, 3, 4], [3, 4, 5]], [[1, 2, 3], [2, 3, 4], [3, 4, 5]],
0, true => [true, false, false]
+/// [[1, 2, 3], [2, 3, 4], [2, 3, 4]], [[1, 2, 3], [2, 3, 4], [3, 4, 5]],
1, false => [true, false, false]
+/// )
+/// ```
+fn compare_element_to_list(
+ list_array_row: &dyn Array,
+ element_array: &dyn Array,
+ row_index: usize,
+ eq: bool,
+) -> Result<BooleanArray> {
+ let indices = UInt32Array::from(vec![row_index as u32]);
+ let element_array_row = arrow::compute::take(element_array, &indices,
None)?;
Review Comment:
This will always be a single row Array as indices have a single value 🤔 I
wonder if you could call
I think you could instead call `list_array_row.values().slice()` and find
the relevant row to compare against those values 🤔
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -131,6 +131,78 @@ macro_rules! array {
}};
}
+/// Computes a BooleanArray indicating equality or inequality between elements
in a list array and a specified element array.
+///
+/// # Arguments
+///
+/// * `list_array_row` - A reference to a trait object implementing the Arrow
`Array` trait. It represents the list array for which the equality or
inequality will be compared.
+///
+/// * `element_array` - A reference to a trait object implementing the Arrow
`Array` trait. It represents the array with which each element in the
`list_array_row` will be compared.
+///
+/// * `row_index` - The index of the row in the `element_array` and
`list_array` to use for the comparison.
+///
+/// * `eq` - A boolean flag. If `true`, the function computes equality; if
`false`, it computes inequality.
+///
+/// # Returns
+///
+/// Returns a `Result<BooleanArray>` representing the comparison results. The
result may contain an error if there are issues with the computation.
+///
+/// # Example
+///
+/// ```text
+/// compare_element_to_list(
+/// [1, 2, 3], [1, 2, 3], 0, true => [true, false, false]
+/// [1, 2, 3, 3, 2, 1], [1, 2, 3], 1, true => [false, true, false, false,
true, false]
+///
+/// [[1, 2, 3], [2, 3, 4], [3, 4, 5]], [[1, 2, 3], [2, 3, 4], [3, 4, 5]],
0, true => [true, false, false]
+/// [[1, 2, 3], [2, 3, 4], [2, 3, 4]], [[1, 2, 3], [2, 3, 4], [3, 4, 5]],
1, false => [true, false, false]
+/// )
+/// ```
+fn compare_element_to_list(
+ list_array_row: &dyn Array,
+ element_array: &dyn Array,
+ row_index: usize,
+ eq: bool,
+) -> Result<BooleanArray> {
+ let indices = UInt32Array::from(vec![row_index as u32]);
+ let element_array_row = arrow::compute::take(element_array, &indices,
None)?;
Review Comment:
This will always be a single row Array as indices have a single value 🤔 I
wonder if you could call
I think you could instead call `list_array_row.values().slice()` and find
the relevant row to compare against those values 🤔
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -131,6 +131,78 @@ macro_rules! array {
}};
}
+/// Computes a BooleanArray indicating equality or inequality between elements
in a list array and a specified element array.
Review Comment:
❤️
--
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]