Skip to content

Apache DataFusion SQL Query Engine

Fallback to Utf8View for `Dict(_, Utf8View)` in `type_union_resolution_coercion` (#14602)

Jay Zhan28856e15bd49
diff --git a/datafusion/expr-common/src/type_coercion/binary.rs b/datafusion/expr-common/src/type_coercion/binary.rs
index 3be35490a4..64c26192ae 100644
--- a/datafusion/expr-common/src/type_coercion/binary.rs
+++ b/datafusion/expr-common/src/type_coercion/binary.rs
@@ -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() {
@@ -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))
}
}
}
diff --git a/datafusion/sqllogictest/test_files/coalesce.slt b/datafusion/sqllogictest/test_files/coalesce.slt
index a624d1def9..5f2d2f0d1d 100644
--- a/datafusion/sqllogictest/test_files/coalesce.slt
+++ b/datafusion/sqllogictest/test_files/coalesce.slt
@@ -438,3 +438,8 @@ Date32
statement ok
drop table test
+
+query T
+select coalesce(arrow_cast('', 'Utf8View'), arrow_cast('', 'Dictionary(UInt32, Utf8)'));
+----
+(empty)
\ No newline at end of file