Skip to content

Commit 0b74ccb

Browse files
JITENDRAJithendra2608
authored andcommitted
fix: support Dictionary arrays in regex_match_dyn (apache#23709)
1 parent 05b7e11 commit 0b74ccb

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎datafusion/physical-expr/src/expressions/binary/kernels.rs‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use datafusion_common::{exec_err, internal_err, plan_err};
3131

3232
use std::sync::Arc;
3333

34-
/// Downcasts $LEFT and $RIGHT to $ARRAY_TYPE and then calls $KERNEL($LEFT, $RIGHT)
34+
3535
macro_rules! call_kernel {
3636
($LEFT:expr, $RIGHT:expr, $KERNEL:expr, $ARRAY_TYPE:ident) => {{
3737
let left = $LEFT.as_any().downcast_ref::<$ARRAY_TYPE>().unwrap();
@@ -41,8 +41,6 @@ macro_rules! call_kernel {
4141
}};
4242
}
4343

44-
/// Creates a $FUNC(left: ArrayRef, right: ArrayRef) that
45-
/// downcasts left / right to the appropriate integral type and calls the kernel
4644
macro_rules! create_left_integral_dyn_kernel {
4745
($FUNC:ident, $KERNEL:ident) => {
4846
pub(crate) fn $FUNC(left: ArrayRef, right: ArrayRef) -> Result<ArrayRef> {
@@ -87,7 +85,7 @@ create_left_integral_dyn_kernel!(bitwise_and_dyn, bitwise_and);
8785
create_left_integral_dyn_kernel!(bitwise_shift_right_dyn, bitwise_shift_right);
8886
create_left_integral_dyn_kernel!(bitwise_shift_left_dyn, bitwise_shift_left);
8987

90-
/// Downcasts $LEFT as $ARRAY_TYPE and $RIGHT as TYPE and calls $KERNEL($LEFT, $RIGHT)
88+
9189
macro_rules! call_scalar_kernel {
9290
($LEFT:expr, $RIGHT:expr, $KERNEL:ident, $ARRAY_TYPE:ident, $TYPE:ty) => {{
9391
let len = $LEFT.len();
@@ -103,8 +101,6 @@ macro_rules! call_scalar_kernel {
103101
}};
104102
}
105103

106-
/// Creates a $FUNC(left: ArrayRef, right: ScalarValue) that
107-
/// downcasts left / right to the appropriate integral type and calls the kernel
108104
macro_rules! create_left_integral_dyn_scalar_kernel {
109105
($FUNC:ident, $KERNEL:ident) => {
110106
pub(crate) fn $FUNC(
@@ -213,6 +209,15 @@ pub(crate) fn regex_match_dyn(
213209
DataType::LargeUtf8 => {
214210
regexp_is_match_flag!(left, right, LargeStringArray, not_match, flag)
215211
}
212+
DataType::Dictionary(_, _) => {
213+
let dict = left.as_any_dictionary();
214+
let unpacked_left = arrow::compute::kernels::take::take(
215+
dict.values().as_ref(),
216+
dict.keys(),
217+
None,
218+
)?;
219+
regex_match_dyn(&unpacked_left, right, not_match, flag)
220+
}
216221
other => internal_err!(
217222
"Data type {} not supported for regex_match_dyn on string array",
218223
other

‎datafusion/sqllogictest/test_files/regexp/regexp_match.slt‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,22 @@ query B
199199
select null !~* 'abc';
200200
----
201201
NULL
202+
203+
204+
# Test for Issue 23709: regex_match_dyn with Dictionary encoded patterns
205+
statement ok
206+
CREATE TABLE dict_regex_t AS SELECT * FROM (VALUES ('user auth failed')) v(s);
207+
208+
statement ok
209+
CREATE TABLE dict_regex_p AS SELECT * FROM (VALUES ('(auth|login)')) v(pat);
210+
211+
query B
212+
SELECT arrow_cast(dict_regex_t.s, 'Dictionary(Int32, Utf8)') SIMILAR TO dict_regex_p.pat FROM dict_regex_t CROSS JOIN dict_regex_p;
213+
----
214+
true
215+
216+
statement ok
217+
DROP TABLE dict_regex_t;
218+
219+
statement ok
220+
DROP TABLE dict_regex_p;

0 commit comments

Comments
 (0)