Skip to content

Commit d855822

Browse files
committed
feat[expr-common]: support REE in coalesce
We were missing a couple of branches to unwrap REE in type_union_resolution_coercion. Signed-off-by: Alfonso Subiotto Marques <alfonso.subiotto@polarsignals.com>
1 parent 3aefba7 commit d855822

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

datafusion/expr-common/src/type_coercion/binary.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,12 @@ enum TypeCategory {
528528
impl From<&DataType> for TypeCategory {
529529
fn from(data_type: &DataType) -> Self {
530530
match data_type {
531-
// Dict is a special type in arrow, we check the value type
531+
// Dict and REE are special types in arrow, we check the value type.
532532
DataType::Dictionary(_, v) => {
533533
let v = v.as_ref();
534534
TypeCategory::from(v)
535535
}
536+
DataType::RunEndEncoded(_, v) => TypeCategory::from(v.data_type()),
536537
_ => {
537538
if data_type.is_numeric() {
538539
return TypeCategory::Numeric;
@@ -709,6 +710,27 @@ fn type_union_resolution_coercion(
709710
None => None,
710711
}
711712
}
713+
(
714+
DataType::RunEndEncoded(lhs_run, lhs_val),
715+
DataType::RunEndEncoded(rhs_run, rhs_val),
716+
) => {
717+
let new_run =
718+
type_union_resolution_coercion(lhs_run.data_type(), rhs_run.data_type())?;
719+
let new_val =
720+
type_union_resolution_coercion(lhs_val.data_type(), rhs_val.data_type())?;
721+
Some(DataType::RunEndEncoded(
722+
Arc::new(lhs_run.as_ref().clone().with_data_type(new_run)),
723+
Arc::new(lhs_val.as_ref().clone().with_data_type(new_val)),
724+
))
725+
}
726+
(DataType::RunEndEncoded(run, val), other)
727+
| (other, DataType::RunEndEncoded(run, val)) => {
728+
let new_val = type_union_resolution_coercion(val.data_type(), other)?;
729+
Some(DataType::RunEndEncoded(
730+
Arc::clone(run),
731+
Arc::new(val.as_ref().clone().with_data_type(new_val)),
732+
))
733+
}
712734
(DataType::Struct(lhs), DataType::Struct(rhs)) => {
713735
if lhs.len() != rhs.len() {
714736
return None;

datafusion/sqllogictest/test_files/coalesce.slt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,19 @@ query T
443443
select coalesce(arrow_cast('', 'Utf8View'), arrow_cast('', 'Dictionary(UInt32, Utf8)'));
444444
----
445445
(empty)
446+
447+
# RunEndEncoded column coalesced with a string literal
448+
statement ok
449+
create table ree_t as
450+
select arrow_cast(c, 'RunEndEncoded("run_ends": non-null Int32, "values": Utf8)') as ree_col
451+
from (values ('hello'), (NULL), ('world')) as t(c);
452+
453+
query ?
454+
select coalesce(ree_col, '__null__') from ree_t;
455+
----
456+
hello
457+
__null__
458+
world
459+
460+
statement ok
461+
drop table ree_t;

0 commit comments

Comments
 (0)