This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch branch-45
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/branch-45 by this push:
     new 755b26abcf Support `Utf8View` to `numeric` coercion (#14377) (#14455)
755b26abcf is described below

commit 755b26abcfa06bf019172ff8df46f2e1b0d473bd
Author: Andrew Lamb <[email protected]>
AuthorDate: Mon Feb 3 16:06:33 2025 -0500

    Support `Utf8View` to `numeric` coercion (#14377) (#14455)
    
    * Test for string / numeric coercion
    
    * fix tests
    
    * Update tests
    
    * Add tests to stringview
    
    * add numeric coercion
---
 datafusion/expr-common/src/type_coercion/binary.rs |  2 +
 .../test_files/string/dictionary_utf8.slt          | 12 ++++++
 .../test_files/string/init_data.slt.part           | 11 +++++
 .../test_files/string/large_string.slt             | 12 ++++++
 .../sqllogictest/test_files/string/string.slt      | 10 +++++
 .../test_files/string/string_query.slt.part        | 47 ++++++++++++++++++++++
 .../sqllogictest/test_files/string/string_view.slt | 11 +++++
 7 files changed, 105 insertions(+)

diff --git a/datafusion/expr-common/src/type_coercion/binary.rs 
b/datafusion/expr-common/src/type_coercion/binary.rs
index 571c171194..4811b05090 100644
--- a/datafusion/expr-common/src/type_coercion/binary.rs
+++ b/datafusion/expr-common/src/type_coercion/binary.rs
@@ -684,8 +684,10 @@ fn string_numeric_coercion(lhs_type: &DataType, rhs_type: 
&DataType) -> Option<D
     match (lhs_type, rhs_type) {
         (Utf8, _) if rhs_type.is_numeric() => Some(Utf8),
         (LargeUtf8, _) if rhs_type.is_numeric() => Some(LargeUtf8),
+        (Utf8View, _) if rhs_type.is_numeric() => Some(Utf8View),
         (_, Utf8) if lhs_type.is_numeric() => Some(Utf8),
         (_, LargeUtf8) if lhs_type.is_numeric() => Some(LargeUtf8),
+        (_, Utf8View) if lhs_type.is_numeric() => Some(Utf8View),
         _ => None,
     }
 }
diff --git a/datafusion/sqllogictest/test_files/string/dictionary_utf8.slt 
b/datafusion/sqllogictest/test_files/string/dictionary_utf8.slt
index 01071f03dc..2f12e9c7a3 100644
--- a/datafusion/sqllogictest/test_files/string/dictionary_utf8.slt
+++ b/datafusion/sqllogictest/test_files/string/dictionary_utf8.slt
@@ -34,6 +34,15 @@ statement ok
 create table test_substr as
 select arrow_cast(col1, 'Dictionary(Int32, Utf8)') as c1 from test_substr_base;
 
+statement ok
+create table test_datetime as
+select
+  arrow_cast(column1, 'Dictionary(Int32, Utf8)') as ts,
+  arrow_cast(column2, 'Dictionary(Int32, Utf8)') as d,
+  arrow_cast(column3, 'Dictionary(Int32, Utf8)') as t
+from test_datetime_base;
+
+
 statement ok
 drop table test_source
 
@@ -56,3 +65,6 @@ drop table test_basic_operator;
 
 statement ok
 drop table test_substr_base;
+
+statement ok
+drop table test_datetime_base;
\ No newline at end of file
diff --git a/datafusion/sqllogictest/test_files/string/init_data.slt.part 
b/datafusion/sqllogictest/test_files/string/init_data.slt.part
index 06b65ff8e7..7799dd605b 100644
--- a/datafusion/sqllogictest/test_files/string/init_data.slt.part
+++ b/datafusion/sqllogictest/test_files/string/init_data.slt.part
@@ -37,3 +37,14 @@ statement ok
 create table test_substr_base (
     col1 VARCHAR
 ) as values ('foo'), ('hello๐ŸŒไธ–็•Œ'), ('๐Ÿ’ฉ'), ('ThisIsAVeryLongASCIIString'), 
(''), (NULL);
+
+
+# --------------------------------------
+# Setup test tables with date/time values to test coercion
+# --------------------------------------
+statement ok
+create table test_datetime_base as values
+  ('2024-08-09T12:13:14', '2024-08-09', '12:13:14'),
+  ('2024-08-09T12:13:15', '2024-09-09', '12:14:14'),
+  (NULL, NULL, NULL)
+;
diff --git a/datafusion/sqllogictest/test_files/string/large_string.slt 
b/datafusion/sqllogictest/test_files/string/large_string.slt
index 84f1e8382e..93ec796ec6 100644
--- a/datafusion/sqllogictest/test_files/string/large_string.slt
+++ b/datafusion/sqllogictest/test_files/string/large_string.slt
@@ -34,6 +34,15 @@ statement ok
 create table test_substr as
 select arrow_cast(col1, 'LargeUtf8') as c1 from test_substr_base;
 
+statement ok
+create table test_datetime as
+select
+  arrow_cast(column1, 'LargeUtf8') as ts,
+  arrow_cast(column2, 'LargeUtf8') as d,
+  arrow_cast(column3, 'LargeUtf8') as t
+from test_datetime_base;
+
+
 # select
 query TTTT
 SELECT ascii_1, ascii_2, unicode_1, unicode_2 FROM test_basic_operator
@@ -64,3 +73,6 @@ drop table test_basic_operator;
 
 statement ok
 drop table test_substr_base;
+
+statement ok
+drop table test_datetime_base;
\ No newline at end of file
diff --git a/datafusion/sqllogictest/test_files/string/string.slt 
b/datafusion/sqllogictest/test_files/string/string.slt
index 55f0c034f5..d724e672e0 100644
--- a/datafusion/sqllogictest/test_files/string/string.slt
+++ b/datafusion/sqllogictest/test_files/string/string.slt
@@ -34,6 +34,13 @@ statement ok
 create table test_substr as
 select arrow_cast(col1, 'Utf8') as c1 from test_substr_base;
 
+statement ok
+create table test_datetime as
+select
+  arrow_cast(column1, 'Utf8') as ts,
+  arrow_cast(column2, 'Utf8') as d,
+  arrow_cast(column3, 'Utf8') as t
+from test_datetime_base;
 
 
 #
@@ -186,3 +193,6 @@ drop table test_basic_operator;
 
 statement ok
 drop table test_substr;
+
+statement ok
+drop table test_datetime;
diff --git a/datafusion/sqllogictest/test_files/string/string_query.slt.part 
b/datafusion/sqllogictest/test_files/string/string_query.slt.part
index 2414e5864c..a2806859b5 100644
--- a/datafusion/sqllogictest/test_files/string/string_query.slt.part
+++ b/datafusion/sqllogictest/test_files/string/string_query.slt.part
@@ -19,6 +19,10 @@
 # with standard values, but different types in string columns
 # (String, StringView, etc.)
 
+# --------------------------------------
+# Show the input data
+# --------------------------------------
+
 # select
 query TTTT
 SELECT ascii_1, ascii_2, unicode_1, unicode_2 FROM test_basic_operator
@@ -35,6 +39,49 @@ _ \_ (empty) (empty)
 NULL % NULL NULL
 NULL R NULL ๐Ÿ”ฅ
 
+# --------------------------------------
+# test type coercion (compare to int)
+# queries should not error
+# --------------------------------------
+
+query BB
+select ascii_1 = 1 as col1, 1 = ascii_1 as col2 from test_basic_operator;
+----
+false false
+false false
+false false
+false false
+false false
+false false
+false false
+false false
+false false
+NULL NULL
+NULL NULL
+
+query BB
+select ascii_1 <> 1 as col1, 1 <> ascii_1 as col2 from test_basic_operator;
+----
+true true
+true true
+true true
+true true
+true true
+true true
+true true
+true true
+true true
+NULL NULL
+NULL NULL
+
+# Coercion to date/time
+query BBB
+select ts = '2024-08-09T12:13:14'::timestamp, d = '2024-08-08'::date, t = 
'12:13:14'::time from test_datetime;
+----
+true false true
+false false false
+NULL NULL NULL
+
 # --------------------------------------
 # column comparison as filters
 # --------------------------------------
diff --git a/datafusion/sqllogictest/test_files/string/string_view.slt 
b/datafusion/sqllogictest/test_files/string/string_view.slt
index 435b4bc3c5..bef0011a20 100644
--- a/datafusion/sqllogictest/test_files/string/string_view.slt
+++ b/datafusion/sqllogictest/test_files/string/string_view.slt
@@ -34,6 +34,14 @@ statement ok
 create table test_substr as
 select arrow_cast(col1, 'Utf8View') as c1 from test_substr_base;
 
+statement ok
+create table test_datetime as
+select
+  arrow_cast(column1, 'Utf8View') as ts,
+  arrow_cast(column2, 'Utf8View') as d,
+  arrow_cast(column3, 'Utf8View') as t
+from test_datetime_base;
+
 statement ok
 drop table test_source
 
@@ -51,6 +59,9 @@ drop table test_basic_operator;
 statement ok
 drop table test_substr_base;
 
+statement ok
+drop table test_datetime_base;
+
 
 # --------------------------------------
 # String_view specific tests


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to