From 9e58b49b26388405e7028a8065cf73e55ea681b3 Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Thu, 16 Dec 2021 06:34:20 +0100 Subject: [PATCH] Added support for scalar comparison of dictionary. --- src/compute/comparison/mod.rs | 15 +++++++++++++++ tests/it/compute/comparison.rs | 1 + 2 files changed, 16 insertions(+) diff --git a/src/compute/comparison/mod.rs b/src/compute/comparison/mod.rs index ffd603ccb3a..0abb1901399 100644 --- a/src/compute/comparison/mod.rs +++ b/src/compute/comparison/mod.rs @@ -240,6 +240,17 @@ macro_rules! compare_scalar { let rhs = rhs.as_any().downcast_ref::>().unwrap(); binary::$op::(lhs, rhs.value().unwrap()) } + Dictionary(key_type) => { + match_integer_type!(key_type, |$T| { + let lhs = lhs.as_any().downcast_ref::>().unwrap(); + let values = cmp_scalar(lhs.values(), rhs); + + Box::new(DictionaryArray::::from_data( + lhs.keys().clone(), + values.into(), + )) + }) + } _ => todo!("Comparisons of {:?} are not yet supported", lhs.data_type()), } }}; @@ -337,6 +348,10 @@ pub fn can_gt_eq(data_type: &DataType) -> bool { // The list of operations currently supported. fn can_compare(data_type: &DataType) -> bool { + if let DataType::Dictionary(_, values) = data_type.to_logical_type() { + return can_compare(values.as_ref()); + } + matches!( data_type, DataType::Boolean diff --git a/tests/it/compute/comparison.rs b/tests/it/compute/comparison.rs index 4dbdff5fd24..00c9623a64a 100644 --- a/tests/it/compute/comparison.rs +++ b/tests/it/compute/comparison.rs @@ -37,6 +37,7 @@ fn consistency() { Duration(TimeUnit::Millisecond), Duration(TimeUnit::Microsecond), Duration(TimeUnit::Nanosecond), + Dictionary(IntegerType::Int32, Box::new(LargeBinary)), ]; // array <> array