Skip to content

Conversation

@sarutak
Copy link
Member

@sarutak sarutak commented Aug 22, 2023

Which issue does this PR close?

Closes #7377

Rationale for this change

This PR fixes an issue that 'NaN'::double in ('NaN'::double) is evaluated as false, which is inconsistent with the result of 'NaN'::double = 'NaN'::double.

What changes are included in this PR?

The root cause is that equality is evaluated using PartialEq::eq. So the fix is using to_bits for equality check for float values like as ScalarValue::Float64 does.

NOTE: This issue doesn't happen when Simplifier simplifies IN expr like

a IN (x, y, z) -> a = x OR a = y OR a = z

Are these changes tested?

Modified an existing test.

Are there any user-facing changes?

Yes, but this change is for correctness.

@github-actions github-actions bot added the physical-expr Changes to the physical-expr crates label Aug 22, 2023
let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![Arc::new(a)])?;

// expression: "a in (0.0, 0.2)"
// expression: "a in (0.0, 0.1)"
Copy link
Member Author

@sarutak sarutak Aug 22, 2023

Choose a reason for hiding this comment

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

Some comments are wrong and it's a tiny issue. So I'll fix them within this PR.

where
T: ArrayAccessor,
T::Item: PartialEq + HashValue,
T::Item: IsEqual + HashValue,
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Member

@viirya viirya left a comment

Choose a reason for hiding this comment

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

Can we add end-to-end test for this too?

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Aug 23, 2023
----
1.2
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.

Hmm, shouldn't it be -NaN?

Copy link
Member Author

@sarutak sarutak Aug 23, 2023

Choose a reason for hiding this comment

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

It's actually -NaN but just shown as NaN.
I've already noticed this issue and have plan to fix it, but it's a separate issue.

Copy link
Member

Choose a reason for hiding this comment

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

Okay

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.

Thank you @sarutak

cc @tustvold for your catalog of various floating point oddities

@alamb alamb merged commit b0d538e into apache:main Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IN expr doesn't work properly for NaN

3 participants