diff --git a/datafusion/sql/src/expr/binary_op.rs b/datafusion/sql/src/expr/binary_op.rs index eaf28adf4ea8..729304066d20 100644 --- a/datafusion/sql/src/expr/binary_op.rs +++ b/datafusion/sql/src/expr/binary_op.rs @@ -53,6 +53,7 @@ impl SqlToRel<'_, S> { BinaryOperator::StringConcat => Ok(Operator::StringConcat), BinaryOperator::ArrowAt => Ok(Operator::ArrowAt), BinaryOperator::AtArrow => Ok(Operator::AtArrow), + BinaryOperator::Spaceship => Ok(Operator::IsNotDistinctFrom), _ => not_impl_err!("Unsupported SQL binary operator {op:?}"), } } diff --git a/datafusion/sqllogictest/test_files/expr.slt b/datafusion/sqllogictest/test_files/expr.slt index 06e2f4154ddd..e3ea9cd38a3b 100644 --- a/datafusion/sqllogictest/test_files/expr.slt +++ b/datafusion/sqllogictest/test_files/expr.slt @@ -1565,6 +1565,62 @@ select NULL < column1 from (VALUES (true), (false)) as t; NULL NULL +#### comparisons_with_spaceship_operator + +# Basic comparisons +query B +select 1 <=> 1; +---- +true + +query B +select 1 <=> 2; +---- +false + +# NULL handling +query B +select NULL <=> NULL; +---- +true + +query B +select 1 <=> NULL; +---- +false + +query B +select NULL <=> 1; +---- +false + +# Table comparisons +query B +select column1 <=> column2 from (VALUES (1, 1), (2, 3), (NULL, NULL)) as t; +---- +true +false +true + +# Sanity test - comparing <=> with equivalent expression +query B +SELECT + (column1 <=> column2) = + (IFNULL(column1, false) = IFNULL(column2, false)) AS comparison_result +FROM (VALUES + (1, 1), -- equal values + (1, 2), -- different values + (NULL, NULL), -- both NULL + (1, NULL), -- first not NULL, second NULL + (NULL, 1) -- first NULL, second not NULL +) AS t(column1, column2); +---- +true +true +true +true +true + #### binary_mathematical_operator_with_null_lt # 1. Integer and NULL