Skip to content

Commit

Permalink
Fallback to Utf8View for Dict(_, Utf8View) in `type_union_resolutio…
Browse files Browse the repository at this point in the history
…n_coercion` (#14602)

* utf8view fix

* fmt

* add more view type

* fmt

* add test and remove coercion that has no test

* fix
  • Loading branch information
jayzhan211 authored Feb 13, 2025
1 parent 3e6d70e commit 28856e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 11 additions & 2 deletions datafusion/expr-common/src/type_coercion/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,16 @@ fn type_union_resolution_coercion(
}
(DataType::Dictionary(index_type, value_type), other_type)
| (other_type, DataType::Dictionary(index_type, value_type)) => {
let new_value_type = type_union_resolution_coercion(value_type, other_type);
new_value_type.map(|t| DataType::Dictionary(index_type.clone(), Box::new(t)))
match type_union_resolution_coercion(value_type, other_type) {
// Dict with View type is redundant, use value type instead
// TODO: Add binary view, list view with tests
Some(DataType::Utf8View) => Some(DataType::Utf8View),
Some(new_value_type) => Some(DataType::Dictionary(
index_type.clone(),
Box::new(new_value_type),
)),
None => None,
}
}
(DataType::Struct(lhs), DataType::Struct(rhs)) => {
if lhs.len() != rhs.len() {
Expand Down Expand Up @@ -589,6 +597,7 @@ fn type_union_resolution_coercion(
.or_else(|| temporal_coercion_nonstrict_timezone(lhs_type, rhs_type))
.or_else(|| string_coercion(lhs_type, rhs_type))
.or_else(|| numeric_string_coercion(lhs_type, rhs_type))
.or_else(|| binary_coercion(lhs_type, rhs_type))
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions datafusion/sqllogictest/test_files/coalesce.slt
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,8 @@ Date32

statement ok
drop table test

query T
select coalesce(arrow_cast('', 'Utf8View'), arrow_cast('', 'Dictionary(UInt32, Utf8)'));
----
(empty)

0 comments on commit 28856e1

Please sign in to comment.