-
Notifications
You must be signed in to change notification settings - Fork 853
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
Add dyn boolean kernels #1131
Add dyn boolean kernels #1131
Changes from 2 commits
824d1b0
c857dcb
c80e2e8
9a4f295
de43f64
f9bb9db
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 | ||||
---|---|---|---|---|---|---|
|
@@ -1454,6 +1454,81 @@ pub fn eq_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> Result<BooleanAr | |||||
result | ||||||
} | ||||||
|
||||||
/// Perform `left < right` operation on an array and a numeric scalar | ||||||
/// value. Supports BooleanArrays, and DictionaryArrays that have string values | ||||||
pub fn lt_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> Result<BooleanArray> { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should update this to
Suggested change
Rather than taking an owned I am happy to make the change as a follow on PR as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this PR is for bool i think best to update the signatures in a follow on PR. to confirm though, this would be for all dyn scalar kernels right? scalar, utf8, and bool? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes However, I made the change for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure sounds good There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated API in e97f588 |
||||||
let result = match left.data_type() { | ||||||
DataType::Boolean => { | ||||||
let left = as_boolean_array(&left); | ||||||
lt_bool_scalar(left, right) | ||||||
} | ||||||
_ => Err(ArrowError::ComputeError( | ||||||
"Kernel only supports BooleanArray".to_string(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to add the operation name in the error message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments for the below functions |
||||||
)), | ||||||
}; | ||||||
result | ||||||
} | ||||||
|
||||||
/// Perform `left > right` operation on an array and a numeric scalar | ||||||
/// value. Supports BooleanArrays, and DictionaryArrays that have string values | ||||||
pub fn gt_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> Result<BooleanArray> { | ||||||
let result = match left.data_type() { | ||||||
DataType::Boolean => { | ||||||
let left = as_boolean_array(&left); | ||||||
gt_bool_scalar(left, right) | ||||||
} | ||||||
_ => Err(ArrowError::ComputeError( | ||||||
"Kernel only supports BooleanArray".to_string(), | ||||||
)), | ||||||
}; | ||||||
result | ||||||
} | ||||||
|
||||||
/// Perform `left <= right` operation on an array and a numeric scalar | ||||||
/// value. Supports BooleanArrays, and DictionaryArrays that have string values | ||||||
pub fn lt_eq_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> Result<BooleanArray> { | ||||||
let result = match left.data_type() { | ||||||
DataType::Boolean => { | ||||||
let left = as_boolean_array(&left); | ||||||
lt_eq_bool_scalar(left, right) | ||||||
} | ||||||
_ => Err(ArrowError::ComputeError( | ||||||
"Kernel only supports BooleanArray".to_string(), | ||||||
)), | ||||||
}; | ||||||
result | ||||||
} | ||||||
|
||||||
/// Perform `left >= right` operation on an array and a numeric scalar | ||||||
/// value. Supports BooleanArrays, and DictionaryArrays that have string values | ||||||
pub fn gt_eq_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> Result<BooleanArray> { | ||||||
let result = match left.data_type() { | ||||||
DataType::Boolean => { | ||||||
let left = as_boolean_array(&left); | ||||||
gt_eq_bool_scalar(left, right) | ||||||
} | ||||||
_ => Err(ArrowError::ComputeError( | ||||||
"Kernel only supports BooleanArray".to_string(), | ||||||
)), | ||||||
}; | ||||||
result | ||||||
} | ||||||
|
||||||
/// Perform `left != right` operation on an array and a numeric scalar | ||||||
/// value. Supports BooleanArrays, and DictionaryArrays that have string values | ||||||
pub fn neq_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) -> Result<BooleanArray> { | ||||||
let result = match left.data_type() { | ||||||
DataType::Boolean => { | ||||||
let left = as_boolean_array(&left); | ||||||
neq_bool_scalar(left, right) | ||||||
} | ||||||
_ => Err(ArrowError::ComputeError( | ||||||
"Kernel only supports BooleanArray".to_string(), | ||||||
)), | ||||||
}; | ||||||
result | ||||||
} | ||||||
|
||||||
/// unpacks the results of comparing left.values (as a boolean) | ||||||
/// | ||||||
/// TODO add example | ||||||
|
@@ -3599,4 +3674,59 @@ mod tests { | |||||
BooleanArray::from(vec![Some(false), Some(true), Some(false)]) | ||||||
); | ||||||
} | ||||||
|
||||||
#[test] | ||||||
fn test_lt_dyn_bool_scalar() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure - but can you expand on why? is there a specific concern on this test with nulls? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
let array = BooleanArray::from(vec![true, false, true]); | ||||||
let array = Arc::new(array); | ||||||
let a_eq = lt_dyn_bool_scalar(array, false).unwrap(); | ||||||
assert_eq!( | ||||||
a_eq, | ||||||
BooleanArray::from(vec![Some(false), Some(false), Some(false)]) | ||||||
); | ||||||
} | ||||||
|
||||||
#[test] | ||||||
fn test_gt_dyn_bool_scalar() { | ||||||
let array = BooleanArray::from(vec![true, false, true]); | ||||||
let array = Arc::new(array); | ||||||
let a_eq = gt_dyn_bool_scalar(array, false).unwrap(); | ||||||
assert_eq!( | ||||||
a_eq, | ||||||
BooleanArray::from(vec![Some(true), Some(false), Some(true)]) | ||||||
); | ||||||
} | ||||||
|
||||||
#[test] | ||||||
fn test_lt_eq_dyn_bool_scalar() { | ||||||
let array = BooleanArray::from(vec![true, false, true]); | ||||||
let array = Arc::new(array); | ||||||
let a_eq = lt_eq_dyn_bool_scalar(array, false).unwrap(); | ||||||
assert_eq!( | ||||||
a_eq, | ||||||
BooleanArray::from(vec![Some(false), Some(true), Some(false)]) | ||||||
); | ||||||
} | ||||||
|
||||||
#[test] | ||||||
fn test_gt_eq_dyn_bool_scalar() { | ||||||
let array = BooleanArray::from(vec![true, false, true]); | ||||||
let array = Arc::new(array); | ||||||
let a_eq = gt_eq_dyn_bool_scalar(array, false).unwrap(); | ||||||
assert_eq!( | ||||||
a_eq, | ||||||
BooleanArray::from(vec![Some(true), Some(true), Some(true)]) | ||||||
); | ||||||
} | ||||||
|
||||||
#[test] | ||||||
fn test_neq_dyn_bool_scalar() { | ||||||
let array = BooleanArray::from(vec![true, false, true]); | ||||||
let array = Arc::new(array); | ||||||
let a_eq = neq_dyn_bool_scalar(array, false).unwrap(); | ||||||
assert_eq!( | ||||||
a_eq, | ||||||
BooleanArray::from(vec![Some(true), Some(false), Some(true)]) | ||||||
); | ||||||
} | ||||||
} |
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.
I don't think these kernels actually support
DictionaryArray
do they? I also don't think that it is needed -- maybe we can just update the docstrings?