Skip to content

Commit 52fb1a0

Browse files
authored
Support spaceship operator (<=>) support (alias for IS NOT DISTINCT FROM (#14187)
* Mapped the Spaceship operator with IsNotDistinctFrom * Added tests for Spaceship Operator <=> * Added sanity test for Spaceship Operator <=>
1 parent 80edb3a commit 52fb1a0

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

datafusion/sql/src/expr/binary_op.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
5353
BinaryOperator::StringConcat => Ok(Operator::StringConcat),
5454
BinaryOperator::ArrowAt => Ok(Operator::ArrowAt),
5555
BinaryOperator::AtArrow => Ok(Operator::AtArrow),
56+
BinaryOperator::Spaceship => Ok(Operator::IsNotDistinctFrom),
5657
_ => not_impl_err!("Unsupported SQL binary operator {op:?}"),
5758
}
5859
}

datafusion/sqllogictest/test_files/expr.slt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,62 @@ select NULL < column1 from (VALUES (true), (false)) as t;
15651565
NULL
15661566
NULL
15671567

1568+
#### comparisons_with_spaceship_operator
1569+
1570+
# Basic comparisons
1571+
query B
1572+
select 1 <=> 1;
1573+
----
1574+
true
1575+
1576+
query B
1577+
select 1 <=> 2;
1578+
----
1579+
false
1580+
1581+
# NULL handling
1582+
query B
1583+
select NULL <=> NULL;
1584+
----
1585+
true
1586+
1587+
query B
1588+
select 1 <=> NULL;
1589+
----
1590+
false
1591+
1592+
query B
1593+
select NULL <=> 1;
1594+
----
1595+
false
1596+
1597+
# Table comparisons
1598+
query B
1599+
select column1 <=> column2 from (VALUES (1, 1), (2, 3), (NULL, NULL)) as t;
1600+
----
1601+
true
1602+
false
1603+
true
1604+
1605+
# Sanity test - comparing <=> with equivalent expression
1606+
query B
1607+
SELECT
1608+
(column1 <=> column2) =
1609+
(IFNULL(column1, false) = IFNULL(column2, false)) AS comparison_result
1610+
FROM (VALUES
1611+
(1, 1), -- equal values
1612+
(1, 2), -- different values
1613+
(NULL, NULL), -- both NULL
1614+
(1, NULL), -- first not NULL, second NULL
1615+
(NULL, 1) -- first NULL, second not NULL
1616+
) AS t(column1, column2);
1617+
----
1618+
true
1619+
true
1620+
true
1621+
true
1622+
true
1623+
15681624
#### binary_mathematical_operator_with_null_lt
15691625

15701626
# 1. Integer and NULL

0 commit comments

Comments
 (0)