From ba19832befc796f362ee5214c13d6176235988d7 Mon Sep 17 00:00:00 2001 From: Thinh Bui Date: Fri, 23 Aug 2024 16:49:44 -0700 Subject: [PATCH 1/2] fix concat bug --- .../expr-common/src/type_coercion/binary.rs | 3 ++ .../sqllogictest/test_files/type_coercion.slt | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/datafusion/expr-common/src/type_coercion/binary.rs b/datafusion/expr-common/src/type_coercion/binary.rs index 401762ad4d36..0fa87655ffc6 100644 --- a/datafusion/expr-common/src/type_coercion/binary.rs +++ b/datafusion/expr-common/src/type_coercion/binary.rs @@ -936,6 +936,9 @@ fn string_concat_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option { string_concat_internal_coercion(from_type, &LargeUtf8) } + (Dictionary(_, lhs_value_type), Dictionary(_, rhs_value_type)) => { + string_coercion(&lhs_value_type, &rhs_value_type).or(None) + } _ => None, }) } diff --git a/datafusion/sqllogictest/test_files/type_coercion.slt b/datafusion/sqllogictest/test_files/type_coercion.slt index e420c0cc7155..0f9399cede2e 100644 --- a/datafusion/sqllogictest/test_files/type_coercion.slt +++ b/datafusion/sqllogictest/test_files/type_coercion.slt @@ -50,6 +50,35 @@ select interval '1 month' - '2023-05-01'::date; query error DataFusion error: Error during planning: Cannot coerce arithmetic expression Interval\(MonthDayNano\) \- Timestamp\(Nanosecond, None\) to valid types SELECT interval '1 month' - '2023-05-01 12:30:00'::timestamp; +# dictionary(int32, utf8) -> utf8 +query T +select arrow_cast('foo', 'Dictionary(Int32, Utf8)') || arrow_cast('bar', 'Dictionary(Int32, Utf8)'); +---- +foobar + +# dictionary(int32, largeUtf8) -> largeUtf8 +query T +select arrow_cast('foo', 'Dictionary(Int32, LargeUtf8)') || arrow_cast('bar', 'Dictionary(Int32, LargeUtf8)'); +---- +foobar + +#################################### +## Concat column dictionary test ## +#################################### +statement ok +create table t as values (arrow_cast('foo', 'Dictionary(Int32, Utf8)'), arrow_cast('bar', 'Dictionary(Int32, Utf8)')); + +query T +select column1 || column2 from t; +---- +foobar + +statement ok +DROP TABLE t + +####################################### +## Concat column dictionary test end ## +####################################### #################################### ## Test type coercion with UNIONs ## From 946705120c0ae4c274c1419ed676e2c9721e8df9 Mon Sep 17 00:00:00 2001 From: Thinh Bui Date: Fri, 23 Aug 2024 18:54:48 -0700 Subject: [PATCH 2/2] clippy fix --- datafusion/expr-common/src/type_coercion/binary.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/expr-common/src/type_coercion/binary.rs b/datafusion/expr-common/src/type_coercion/binary.rs index 0fa87655ffc6..552bc89b38f4 100644 --- a/datafusion/expr-common/src/type_coercion/binary.rs +++ b/datafusion/expr-common/src/type_coercion/binary.rs @@ -937,7 +937,7 @@ fn string_concat_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option { - string_coercion(&lhs_value_type, &rhs_value_type).or(None) + string_coercion(lhs_value_type, rhs_value_type).or(None) } _ => None, })