This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 7c6d731281 Make sqllogictest platform-independent for the sign of NaN 
(#7462)
7c6d731281 is described below

commit 7c6d73128184c79464703c7dff9dfd06b3704be1
Author: Kousuke Saruta <[email protected]>
AuthorDate: Fri Sep 8 02:13:51 2023 +0900

    Make sqllogictest platform-independent for the sign of NaN (#7462)
    
    * Revert "Make sqllogictest distinguish NaN from -NaN (#7403)"
    
    This reverts commit fd7e612d5f2827cef8aa3d6470d8e2e197fed23f.
    
    * Make sqllogictests platform-independent for the sign of NaNs
    
    * Add comment
    
    * Ensure -NaN is parsed as -NaN
---
 datafusion/sqllogictest/src/engines/conversion.rs | 24 +++---
 datafusion/sqllogictest/test_files/math.slt       |  6 +-
 datafusion/sqllogictest/test_files/predicates.slt | 95 ++++++++++++-----------
 datafusion/sqllogictest/test_files/scalar.slt     | 34 ++++----
 datafusion/sqllogictest/test_files/select.slt     |  6 +-
 5 files changed, 80 insertions(+), 85 deletions(-)

diff --git a/datafusion/sqllogictest/src/engines/conversion.rs 
b/datafusion/sqllogictest/src/engines/conversion.rs
index 2f6fa6263a..909539b313 100644
--- a/datafusion/sqllogictest/src/engines/conversion.rs
+++ b/datafusion/sqllogictest/src/engines/conversion.rs
@@ -41,11 +41,9 @@ pub(crate) fn varchar_to_str(value: &str) -> String {
 
 pub(crate) fn f16_to_str(value: f16) -> String {
     if value.is_nan() {
-        if value.is_sign_positive() {
-            "NaN".to_string()
-        } else {
-            "-NaN".to_string()
-        }
+        // The sign of NaN can be different depending on platform.
+        // So the string representation of NaN ignores the sign.
+        "NaN".to_string()
     } else if value == f16::INFINITY {
         "Infinity".to_string()
     } else if value == f16::NEG_INFINITY {
@@ -57,11 +55,9 @@ pub(crate) fn f16_to_str(value: f16) -> String {
 
 pub(crate) fn f32_to_str(value: f32) -> String {
     if value.is_nan() {
-        if value.is_sign_positive() {
-            "NaN".to_string()
-        } else {
-            "-NaN".to_string()
-        }
+        // The sign of NaN can be different depending on platform.
+        // So the string representation of NaN ignores the sign.
+        "NaN".to_string()
     } else if value == f32::INFINITY {
         "Infinity".to_string()
     } else if value == f32::NEG_INFINITY {
@@ -73,11 +69,9 @@ pub(crate) fn f32_to_str(value: f32) -> String {
 
 pub(crate) fn f64_to_str(value: f64) -> String {
     if value.is_nan() {
-        if value.is_sign_positive() {
-            "NaN".to_string()
-        } else {
-            "-NaN".to_string()
-        }
+        // The sign of NaN can be different depending on platform.
+        // So the string representation of NaN ignores the sign.
+        "NaN".to_string()
     } else if value == f64::INFINITY {
         "Infinity".to_string()
     } else if value == f64::NEG_INFINITY {
diff --git a/datafusion/sqllogictest/test_files/math.slt 
b/datafusion/sqllogictest/test_files/math.slt
index 5ad9e94756..cd55e018e9 100644
--- a/datafusion/sqllogictest/test_files/math.slt
+++ b/datafusion/sqllogictest/test_files/math.slt
@@ -95,10 +95,10 @@ SELECT atan2(2.0, 1.0), atan2(-2.0, 1.0), atan2(2.0, -1.0), 
atan2(-2.0, -1.0), a
 1.107148717794 -1.107148717794 2.034443935796 -2.034443935796 NULL NULL NULL
 
 # nanvl
-query RRB
-SELECT nanvl(asin(10), 1.0), nanvl(1.0, 2.0), isnan(nanvl(asin(10), asin(10)))
+query RRR
+SELECT nanvl(asin(10), 1.0), nanvl(1.0, 2.0), nanvl(asin(10), asin(10))
 ----
-1 1 true
+1 1 NaN
 
 # isnan
 query BBBB
diff --git a/datafusion/sqllogictest/test_files/predicates.slt 
b/datafusion/sqllogictest/test_files/predicates.slt
index fd92f92607..937b4c2ecc 100644
--- a/datafusion/sqllogictest/test_files/predicates.slt
+++ b/datafusion/sqllogictest/test_files/predicates.slt
@@ -255,81 +255,82 @@ fazzz
 
 statement ok
 CREATE TABLE IF NOT EXISTS test_float AS VALUES
- (1.2, 2.3, 1.2, -3.5, 1.1),
- (2.1, 'NaN'::double, -1.7, -8.2, NULL),
- (NULL, NULL, '-NaN'::double, -5.4, 1.5),
- ('NaN'::double, 'NaN'::double, 1.1, '-NaN'::double, NULL),
- ('-NaN'::double, 6.2, 'NaN'::double, -3.3, 5.6)
+ ('a', 1.2, 2.3, 1.2, -3.5, 1.1),
+ ('b', 2.1, 'NaN'::double, -1.7, -8.2, NULL),
+ ('c', NULL, NULL, '-NaN'::double, -5.4, 1.5),
+ ('d', 'NaN'::double, 'NaN'::double, 1.1, '-NaN'::double, NULL),
+ ('e', '-NaN'::double, 6.2, 'NaN'::double, -3.3, 5.6)
  ;
 
 # IN expr for float
-query R
-SELECT column1 FROM test_float WHERE column1 IN (0.0, -1.2)
+query T
+SELECT column1 FROM test_float WHERE column2 IN (0.0, -1.2)
 ----
 
-query R
-SELECT column1 FROM test_float WHERE column1 IN (0.0, 1.2)
+query T
+SELECT column1 FROM test_float WHERE column2 IN (0.0, 1.2)
 ----
-1.2
+a
 
-query R
-SELECT column1 FROM test_float WHERE column1 IN (2.1, 1.2)
+query T
+SELECT column1 FROM test_float WHERE column2 IN (2.1, 1.2)
 ----
-1.2
-2.1
+a
+b
 
-query R
-SELECT column1 FROM test_float WHERE column1 IN (0.0, 1.2, NULL)
+query T
+SELECT column1 FROM test_float WHERE column2 IN (0.0, 1.2, NULL)
 ----
-1.2
+a
 
-query R
-SELECT column1 FROM test_float WHERE column1 IN (0.0, -1.2, NULL)
+query T
+SELECT column1 FROM test_float WHERE column2 IN (0.0, -1.2, NULL)
 ----
 
-query R
-SELECT column1 FROM test_float WHERE column1 IN (0.0, 1.2, 'NaN'::double, 
'-NaN'::double)
+query T
+SELECT column1 FROM test_float WHERE column2 IN (0.0, 1.2, 'NaN'::double, 
'-NaN'::double)
 ----
-1.2
-NaN
--NaN
+a
+d
+e
 
-query RRRRR
-SELECT * FROM test_float WHERE column1 IN (column2, column3, column4, column5)
+query T
+SELECT column1 FROM test_float WHERE column2 IN (column3, column4, column5, 
column6)
 ----
-1.2 2.3 1.2 -3.5 1.1
-NaN NaN 1.1 -NaN NULL
+a
+d
 
-query RRRRR
-SELECT * FROM test_float WHERE column1 IN (column2, column3, column4, column5, 
2.1, NULL, '-NaN'::double)
+query T
+SELECT column1 FROM test_float WHERE column2 IN (column3, column4, column5, 
column6, 2.1, NULL, '-NaN'::double)
 ----
-1.2 2.3 1.2 -3.5 1.1
-2.1 NaN -1.7 -8.2 NULL
-NaN NaN 1.1 -NaN NULL
--NaN 6.2 NaN -3.3 5.6
+a
+b
+d
+e
 
-query RRRRR
-SELECT * FROM test_float WHERE column1 NOT IN (column2, column3, column4, 
column5)
+query T
+SELECT column1 FROM test_float WHERE column2 NOT IN (column3, column4, 
column5, column6)
 ----
--NaN 6.2 NaN -3.3 5.6
+e
 
-query RRRRR
-SELECT * FROM test_float WHERE column1 NOT IN (column2, column3, column4, 
column5, 2.1, NULL, '-NaN'::double)
+query T
+SELECT column1 FROM test_float WHERE column2 NOT IN (column3, column4, 
column5, column6, 2.1, NULL, '-NaN'::double)
 ----
 
-query R
-SELECT column1 FROM test_float WHERE NULL IN (column1, column1 + 1, column1 + 
2, column1 + 3)
+
+query T
+SELECT column1 FROM test_float WHERE NULL IN (column2, column2 + 1, column2 + 
2, column2 + 3)
 ----
 
-query R
-SELECT column1 FROM test_float WHERE 'NaN'::double IN (column1, column1 + 1, 
column1 + 2, column1 + 3)
+query T
+SELECT column1 FROM test_float WHERE 'NaN'::double IN (column2, column2 + 1, 
column2 + 2, column2 + 3)
 ----
-NaN
+d
 
-query R
-SELECT column1 FROM test_float WHERE '-NaN'::double IN (column1, column1 + 1, 
column1 + 2, column1 + 3)
+query T
+SELECT column1 FROM test_float WHERE '-NaN'::double IN (column2, column2 + 1, 
column2 + 2, column2 + 3)
 ----
--NaN
+e
 
 query II
 SELECT c3, c7 FROM aggregate_test_100 WHERE c3 IN (c7 / 10, c7 / 20, c7 / 30, 
c7 / 40, 68, 103)
diff --git a/datafusion/sqllogictest/test_files/scalar.slt 
b/datafusion/sqllogictest/test_files/scalar.slt
index 9d5eb54816..7c1add8891 100644
--- a/datafusion/sqllogictest/test_files/scalar.slt
+++ b/datafusion/sqllogictest/test_files/scalar.slt
@@ -543,10 +543,10 @@ select ln(0);
 query RRR rowsort
 select round(ln(a), 5), round(ln(b), 5), round(ln(c), 5) from signed_integers;
 ----
--NaN 4.60517 -NaN
--NaN 9.21034 -NaN
-0.69315 -NaN 4.81218
+0.69315 NaN 4.81218
 1.38629 NULL NULL
+NaN 4.60517 NaN
+NaN 9.21034 NaN
 
 ## log
 
@@ -595,10 +595,10 @@ Infinity 2 2
 query RRR rowsort
 select log(a, 64) a, log(b), log(10, b) from signed_integers;
 ----
--NaN 2 2
--NaN 4 4
 3 NULL NULL
-6 -NaN -NaN
+6 NaN NaN
+NaN 2 2
+NaN 4 4
 
 ## log10
 
@@ -625,10 +625,10 @@ select log10(0);
 query RRR rowsort
 select round(log(a), 5), round(log(b), 5), round(log(c), 5) from 
signed_integers;
 ----
--NaN 2 -NaN
--NaN 4 -NaN
-0.30103 -NaN 2.08991
+0.30103 NaN 2.08991
 0.60206 NULL NULL
+NaN 2 NaN
+NaN 4 NaN
 
 ## log2
 
@@ -655,10 +655,10 @@ select log2(0);
 query RRR rowsort
 select round(log2(a), 5), round(log2(b), 5), round(log2(c), 5) from 
signed_integers;
 ----
--NaN 13.28771 -NaN
--NaN 6.64386 -NaN
-1 -NaN 6.94251
+1 NaN 6.94251
 2 NULL NULL
+NaN 13.28771 NaN
+NaN 6.64386 NaN
 
 ## nanvl
 
@@ -779,10 +779,10 @@ NULL
 query RRR rowsort
 select round(power(a, b), 5), round(power(c, d), 5), round(power(e, f), 5) 
from small_floats;
 ----
--NaN -NaN 2.32282
-1.1487 0 -NaN
+1.1487 0 NaN
 1.17462 1 0.31623
 NULL NULL NULL
+NaN NaN 2.32282
 
 ## radians
 
@@ -918,10 +918,10 @@ NULL
 query RRR rowsort
 select round(sqrt(a), 5), round(sqrt(b), 5), round(sqrt(c), 5) from 
signed_integers;
 ----
--NaN 10 -NaN
--NaN 100 -NaN
-1.41421 -NaN 11.09054
+1.41421 NaN 11.09054
 2 NULL NULL
+NaN 10 NaN
+NaN 100 NaN
 
 ## tan
 
diff --git a/datafusion/sqllogictest/test_files/select.slt 
b/datafusion/sqllogictest/test_files/select.slt
index 96c2370c58..a7ed2bf5c7 100644
--- a/datafusion/sqllogictest/test_files/select.slt
+++ b/datafusion/sqllogictest/test_files/select.slt
@@ -225,10 +225,10 @@ select
 false true false true true false false true false true true false true true 
false false true
 
 # select NaNs
-query RRRR
-select 'NaN'::double a, '-NaN'::double b, 'NaN'::float c, '-NaN'::float d
+query BBBB
+select (isnan('NaN'::double) AND 'NaN'::double > 0) a, (isnan('-NaN'::double) 
AND '-NaN'::double < 0) b, (isnan('NaN'::float) AND 'NaN'::float > 0) c, 
(isnan('-NaN'::float) AND '-NaN'::float < 0) d
 ----
-NaN -NaN NaN -NaN
+true true true true
 
 # select limit clause
 query I

Reply via email to