From 430a67cdb6664d4f98a7e3b057cdb3024dc44450 Mon Sep 17 00:00:00 2001 From: Bruce Ritchie Date: Tue, 12 Nov 2024 20:03:56 -0500 Subject: [PATCH] Directly support utf8view in nullif. #13379 (#13380) --- datafusion/functions/src/core/nullif.rs | 1 + datafusion/sqllogictest/test_files/nullif.slt | 30 +++++++++++++++++++ .../test_files/string/string_view.slt | 20 +++++++++++++ 3 files changed, 51 insertions(+) diff --git a/datafusion/functions/src/core/nullif.rs b/datafusion/functions/src/core/nullif.rs index f96ee1ea7a12..801a80201946 100644 --- a/datafusion/functions/src/core/nullif.rs +++ b/datafusion/functions/src/core/nullif.rs @@ -47,6 +47,7 @@ static SUPPORTED_NULLIF_TYPES: &[DataType] = &[ DataType::Int64, DataType::Float32, DataType::Float64, + DataType::Utf8View, DataType::Utf8, DataType::LargeUtf8, ]; diff --git a/datafusion/sqllogictest/test_files/nullif.slt b/datafusion/sqllogictest/test_files/nullif.slt index f8240f70e363..a5060077fe77 100644 --- a/datafusion/sqllogictest/test_files/nullif.slt +++ b/datafusion/sqllogictest/test_files/nullif.slt @@ -101,3 +101,33 @@ query I SELECT NULLIF(NULL, NULL); ---- NULL + +query T +SELECT NULLIF(arrow_cast('a', 'Utf8View'), 'a'); +---- +NULL + +query T +SELECT NULLIF('a', arrow_cast('a', 'Utf8View')); +---- +NULL + +query T +SELECT NULLIF(arrow_cast('a', 'Utf8View'), 'b'); +---- +a + +query T +SELECT NULLIF('a', arrow_cast('b', 'Utf8View')); +---- +a + +query T +SELECT NULLIF(null, arrow_cast('a', 'Utf8View')); +---- +NULL + +query T +SELECT NULLIF(arrow_cast('a', 'Utf8View'), null); +---- +a \ No newline at end of file diff --git a/datafusion/sqllogictest/test_files/string/string_view.slt b/datafusion/sqllogictest/test_files/string/string_view.slt index ce8a295373aa..2f4af80a9257 100644 --- a/datafusion/sqllogictest/test_files/string/string_view.slt +++ b/datafusion/sqllogictest/test_files/string/string_view.slt @@ -934,6 +934,26 @@ logical_plan 01)Projection: to_timestamp(test.column1_utf8view, Utf8("a,b,c,d")) AS c 02)--TableScan: test projection=[column1_utf8view] +## Ensure no casts for nullif +query TT +EXPLAIN SELECT + nullif(column1_utf8view, 'a') as c +FROM test; +---- +logical_plan +01)Projection: nullif(test.column1_utf8view, Utf8View("a")) AS c +02)--TableScan: test projection=[column1_utf8view] + +## Ensure no casts for nullif +query TT +EXPLAIN SELECT + nullif(column1_utf8view, column1_utf8view) as c +FROM test; +---- +logical_plan +01)Projection: nullif(test.column1_utf8view, test.column1_utf8view) AS c +02)--TableScan: test projection=[column1_utf8view] + ## Ensure no casts for binary operators # `~` operator (regex match) query TT