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 ab818fe Add kernel and tests (#1122)
ab818fe is described below
commit ab818feac8ef9a17d7aba312553c09c5d85803af
Author: Matthew Turner <[email protected]>
AuthorDate: Sun Jan 2 08:45:08 2022 -0500
Add kernel and tests (#1122)
Co-authored-by: Andrew Lamb <[email protected]>
---
arrow/src/compute/kernels/comparison.rs | 53 +++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/arrow/src/compute/kernels/comparison.rs
b/arrow/src/compute/kernels/comparison.rs
index 7c84247..3891262 100644
--- a/arrow/src/compute/kernels/comparison.rs
+++ b/arrow/src/compute/kernels/comparison.rs
@@ -1370,6 +1370,29 @@ pub fn gt_eq_dyn_utf8_scalar(left: Arc<dyn Array>,
right: &str) -> Result<Boolea
result
}
+/// Perform `left <= right` operation on an array and a numeric scalar
+/// value. Supports StringArrays, and DictionaryArrays that have string values
+pub fn lt_eq_dyn_utf8_scalar(left: Arc<dyn Array>, right: &str) ->
Result<BooleanArray> {
+ let result = match left.data_type() {
+ DataType::Dictionary(key_type, value_type) => match
value_type.as_ref() {
+ DataType::Utf8 | DataType::LargeUtf8 => {
+ dyn_compare_utf8_scalar!(&left, right, key_type,
lt_eq_utf8_scalar)
+ }
+ _ => Err(ArrowError::ComputeError(
+ "lt_eq_dyn_utf8_scalar only supports Utf8 or LargeUtf8 arrays
or DictionaryArray with Utf8 or LargeUtf8 values".to_string(),
+ )),
+ },
+ DataType::Utf8 | DataType::LargeUtf8 => {
+ let left = as_string_array(&left);
+ lt_eq_utf8_scalar(left, right)
+ }
+ _ => Err(ArrowError::ComputeError(
+ "lt_eq_dyn_utf8_scalar only supports Utf8 or LargeUtf8
arrays".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 eq_dyn_bool_scalar(left: Arc<dyn Array>, right: bool) ->
Result<BooleanArray> {
@@ -3400,6 +3423,36 @@ mod tests {
}
#[test]
+ fn test_lt_eq_dyn_utf8_scalar() {
+ let array = StringArray::from(vec!["abc", "def", "xyz"]);
+ let array = Arc::new(array);
+ let a_eq = lt_eq_dyn_utf8_scalar(array, "def").unwrap();
+ assert_eq!(
+ a_eq,
+ BooleanArray::from(vec![Some(true), Some(true), Some(false)])
+ );
+ }
+ #[test]
+ fn test_lt_eq_dyn_utf8_scalar_with_dict() {
+ let key_builder = PrimitiveBuilder::<Int8Type>::new(3);
+ let value_builder = StringBuilder::new(100);
+ let mut builder = StringDictionaryBuilder::new(key_builder,
value_builder);
+ builder.append("abc").unwrap();
+ builder.append_null().unwrap();
+ builder.append("def").unwrap();
+ builder.append("def").unwrap();
+ builder.append("xyz").unwrap();
+ let array = Arc::new(builder.finish());
+ let a_eq = lt_eq_dyn_utf8_scalar(array, "def").unwrap();
+ assert_eq!(
+ a_eq,
+ BooleanArray::from(
+ vec![Some(true), None, Some(true), Some(true), Some(false)]
+ )
+ );
+ }
+
+ #[test]
fn test_gt_eq_dyn_utf8_scalar() {
let array = StringArray::from(vec!["abc", "def", "xyz"]);
let array = Arc::new(array);