Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sqllogictest platform-independent for the sign of NaN #7462

Merged
merged 5 commits into from
Sep 7, 2023

Conversation

sarutak
Copy link
Member

@sarutak sarutak commented Sep 1, 2023

Which issue does this PR close?

Closes #7458

Rationale for this change

The sign of NaN returned from a function seems to depend on platform.
But it's better for sqllogictest to be platform-independent.

What changes are included in this PR?

Revert #7403 and change one test which is sign sensitive .

Are these changes tested?

cargo test --test sqllogictests passed.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Sep 1, 2023
query R
SELECT * 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.

} else {
"-NaN".to_string()
}
"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.

Comment on lines 227 to 231
# select NaNs
query RRRR
select 'NaN'::double a, '-NaN'::double b, 'NaN'::float c, '-NaN'::float d
----
NaN -NaN NaN -NaN
Copy link
Member

Choose a reason for hiding this comment

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

Even simply literals also are impacted, i.e. platform dependent?

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.

I don't think so.
I believe NaN and -NaN are finally parsed here.
So, as long as f32::NAN, f64::NAN, -f32::NAN and -f64::NAN follows IEEE 754, simple literals should not be impacted.

But the string representation needs to be NaN regardless of NaN or -NaN.
So this test should be changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should leave the test to show the behavior of parsing -NaN.

Copy link
Member Author

Choose a reason for hiding this comment

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

@alamb
ToString::to_string ignores the sign of NaNs so if the sign of NaNs should be printed in the test result, we need to do like this.
But if we do so, the issue discussed in #7458 happens.
So, if we need to ensure a literal "-NaN"::double is parsed as -NaN, how about testing like this?

@berkaysynnada
Copy link
Contributor

Hi @sarutak.
Thank you for working on this issue. The tests pass now without any errors on my machine.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @sarutak -- I think this change is reasonable to me

Comment on lines 227 to 231
# select NaNs
query RRRR
select 'NaN'::double a, '-NaN'::double b, 'NaN'::float c, '-NaN'::float d
----
NaN -NaN NaN -NaN
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should leave the test to show the behavior of parsing -NaN.

@alamb
Copy link
Contributor

alamb commented Sep 7, 2023

Looks good to me -- thank you @sarutak

@alamb alamb merged commit 7c6d731 into apache:main Sep 7, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mismatch in query results in the local machine
4 participants