From ccf6258a1e02eb01af436f78c7f6430be19fa59c Mon Sep 17 00:00:00 2001 From: Jay Zhan Date: Thu, 14 Nov 2024 07:31:49 +0800 Subject: [PATCH] Add Utf8View to `TypeCategory::Unknown` (#13350) * add utf8view Signed-off-by: jayzhan211 * add test Signed-off-by: jayzhan211 * fix comment Signed-off-by: Jay Zhan --------- Signed-off-by: jayzhan211 Signed-off-by: Jay Zhan --- datafusion/expr-common/src/type_coercion/binary.rs | 8 +++++--- datafusion/sqllogictest/test_files/coalesce.slt | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/datafusion/expr-common/src/type_coercion/binary.rs b/datafusion/expr-common/src/type_coercion/binary.rs index 31fe6a59baee..c32b4951db44 100644 --- a/datafusion/expr-common/src/type_coercion/binary.rs +++ b/datafusion/expr-common/src/type_coercion/binary.rs @@ -330,11 +330,13 @@ impl From<&DataType> for TypeCategory { return TypeCategory::Array; } - // String literal is possible to cast to many other types like numeric or datetime, - // therefore, it is categorized as a unknown type + // It is categorized as unknown type because the type will be resolved later on if matches!( data_type, - DataType::Utf8 | DataType::LargeUtf8 | DataType::Null + DataType::Utf8 + | DataType::LargeUtf8 + | DataType::Utf8View + | DataType::Null ) { return TypeCategory::Unknown; } diff --git a/datafusion/sqllogictest/test_files/coalesce.slt b/datafusion/sqllogictest/test_files/coalesce.slt index 97e77d0feb3d..06460a005c20 100644 --- a/datafusion/sqllogictest/test_files/coalesce.slt +++ b/datafusion/sqllogictest/test_files/coalesce.slt @@ -242,6 +242,14 @@ none_set statement ok drop table test1 +# coalesce with utf8view +query TTT +select coalesce(arrow_cast(null, 'Utf8View'), arrow_cast('t', 'Utf8')), + arrow_typeof(coalesce(arrow_cast(null, 'Utf8View'), arrow_cast('t', 'Utf8'))), + arrow_typeof(coalesce(arrow_cast(null, 'Utf8'), arrow_cast('t', 'Utf8View'))); +---- +t Utf8View Utf8View + # test dict coercion with value statement ok create table t(c varchar) as values ('a'), (null);