Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion datafusion/expr-common/src/type_coercion/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,12 @@ enum TypeCategory {
impl From<&DataType> for TypeCategory {
fn from(data_type: &DataType) -> Self {
match data_type {
// Dict is a special type in arrow, we check the value type
// Dict and REE are special types in arrow, we check the value type.
DataType::Dictionary(_, v) => {
let v = v.as_ref();
TypeCategory::from(v)
}
DataType::RunEndEncoded(_, v) => TypeCategory::from(v.data_type()),
_ => {
if data_type.is_numeric() {
return TypeCategory::Numeric;
Expand Down Expand Up @@ -709,6 +710,27 @@ fn type_union_resolution_coercion(
None => None,
}
}
(
DataType::RunEndEncoded(lhs_run, lhs_val),
DataType::RunEndEncoded(rhs_run, rhs_val),
) => {
let new_run =
type_union_resolution_coercion(lhs_run.data_type(), rhs_run.data_type())?;
let new_val =
type_union_resolution_coercion(lhs_val.data_type(), rhs_val.data_type())?;
Some(DataType::RunEndEncoded(
Arc::new(lhs_run.as_ref().clone().with_data_type(new_run)),
Arc::new(lhs_val.as_ref().clone().with_data_type(new_val)),
))
}
(DataType::RunEndEncoded(run, val), other)
| (other, DataType::RunEndEncoded(run, val)) => {
let new_val = type_union_resolution_coercion(val.data_type(), other)?;
Some(DataType::RunEndEncoded(
Arc::clone(run),
Arc::new(val.as_ref().clone().with_data_type(new_val)),
))
}
(DataType::Struct(lhs), DataType::Struct(rhs)) => {
if lhs.len() != rhs.len() {
return None;
Expand Down
16 changes: 16 additions & 0 deletions datafusion/sqllogictest/test_files/coalesce.slt
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,19 @@ query T
select coalesce(arrow_cast('', 'Utf8View'), arrow_cast('', 'Dictionary(UInt32, Utf8)'));
----
(empty)

# RunEndEncoded column coalesced with a string literal
statement ok
create table ree_t as
select arrow_cast(c, 'RunEndEncoded("run_ends": non-null Int32, "values": Utf8)') as ree_col
from (values ('hello'), (NULL), ('world')) as t(c);

query ?
select coalesce(ree_col, '__null__') from ree_t;
----
hello
__null__
world

statement ok
drop table ree_t;
Loading