Skip to content

Commit

Permalink
Merge branch 'main' of github.com:apache/datafusion into nullif
Browse files Browse the repository at this point in the history
  • Loading branch information
jayzhan211 committed Nov 13, 2024
2 parents 784018f + 430a67c commit ca87f2c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions datafusion/expr/src/expr_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<DataType> {
match self {
Expr::Alias(Alias { expr, name, .. }) => match &**expr {
Expand Down
32 changes: 31 additions & 1 deletion datafusion/sqllogictest/test_files/nullif.slt
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,34 @@ select nullif('2', '3');
# TODO: support numeric string
# This query success in Postgres and DuckDB
query error DataFusion error: Error during planning: Internal error: Failed to match any signature, errors: Error during planning: The signature expected NativeType::String but received NativeType::Int64
select nullif(2, '1');
select nullif(2, '1');

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
20 changes: 20 additions & 0 deletions datafusion/sqllogictest/test_files/string/string_view.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ca87f2c

Please sign in to comment.