From 2a2de82f6789d2f6eee669c762c4a13704a52b12 Mon Sep 17 00:00:00 2001 From: Peter Toth Date: Wed, 13 Nov 2024 01:55:28 +0100 Subject: [PATCH 1/2] annotate get_type with recursive (#13376) --- datafusion/expr/src/expr_schema.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/datafusion/expr/src/expr_schema.rs b/datafusion/expr/src/expr_schema.rs index f0a6ed89e6e9..2225f457f626 100644 --- a/datafusion/expr/src/expr_schema.rs +++ b/datafusion/expr/src/expr_schema.rs @@ -32,6 +32,7 @@ use datafusion_common::{ TableReference, }; use datafusion_functions_window_common::field::WindowUDFFieldArgs; +use recursive::recursive; use std::collections::HashMap; use std::sync::Arc; @@ -99,6 +100,7 @@ impl ExprSchemable for Expr { /// expression refers to a column that does not exist in the /// schema, or when the expression is incorrectly typed /// (e.g. `[utf8] + [bool]`). + #[recursive] fn get_type(&self, schema: &dyn ExprSchema) -> Result { match self { Expr::Alias(Alias { expr, name, .. }) => match &**expr { From 430a67cdb6664d4f98a7e3b057cdb3024dc44450 Mon Sep 17 00:00:00 2001 From: Bruce Ritchie Date: Tue, 12 Nov 2024 20:03:56 -0500 Subject: [PATCH 2/2] 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