Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions datafusion/sqllogictest/src/engines/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, you mean on different platform, a same value could be positive and negative?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, maybe it good to leave a comment here.

Copy link
Member Author

@sarutak sarutak Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. a function/operation can return -NaN on x86 while NaN on Arm.

} else if value == f16::INFINITY {
"Infinity".to_string()
} else if value == f16::NEG_INFINITY {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions datafusion/sqllogictest/test_files/math.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
95 changes: 48 additions & 47 deletions datafusion/sqllogictest/test_files/predicates.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified this test which is sign sensitive not to show NaN and -NaN.

----
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)
Expand Down
34 changes: 17 additions & 17 deletions datafusion/sqllogictest/test_files/scalar.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

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