Skip to content

Commit 37dbdaf

Browse files
authored
feat[expr-common]: support REE in coalesce (#21919)
We were missing a couple of branches to unwrap REE in type_union_resolution_coercion. ## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #21918 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> Fix an unexpected error ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Type coercion match arms for REE ## Are these changes tested? Yes, via sql logic tests <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> Queries that errored now complete successfully Signed-off-by: Alfonso Subiotto Marques <alfonso.subiotto@polarsignals.com>
1 parent e514a01 commit 37dbdaf

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)