Skip to content

Add an error margin when comparing floats. #129721

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gmarouli
Copy link
Contributor

We add a margin of error when comparing floats to the DynamicFieldMatcher to account for a small loss of accuracy when loading fields from synthetic source.

Furthermore, we switched the set to a list to take the order of array elements also into account since it's supported.

Fixes: #129527, #129528, #129529

@gmarouli gmarouli added auto-backport Automatically create backport pull requests when merged :StorageEngine/Mapping The storage related side of mappings v8.19.0 labels Jun 19, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

}

for (int i = 0; i < normalizedActual.size(); i++) {
if (floatsEquals(normalizedActual.get(i), normalizedExpected.get(i))) {
Copy link
Member

Choose a reason for hiding this comment

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

So if floatsEquals(...) returns true then there is no match? Maybe rename floatsEquals(...) to floatsNoEquals(...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh boy, my bad. Actually I prefer to keep it floatsEquals and fix the code because its more intuitive.

Copy link
Member

Choose a reason for hiding this comment

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

also good with me 👍

@gmarouli
Copy link
Contributor Author

Thank you @martijnvg for the review, such an oversight the method name and implementation 🙃 . I run the test locally with -Dtests.iters=N, because it's a rest test it takes a bit longer so around 600+ it reached the timeout. But I think it gave me enough confidence for now.

What do you think?

@gmarouli gmarouli requested review from martijnvg and kkrik-es June 20, 2025 08:53
@martijnvg
Copy link
Member

What do you think?

Yes, that should give good confidence.

Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Comment on lines +76 to +84
if (normalizedActual.size() != normalizedExpected.size()) {
return noMatchSupplier.get();
}

for (int i = 0; i < normalizedActual.size(); i++) {
if (floatEquals(normalizedActual.get(i), normalizedExpected.get(i)) == false) {
return noMatchSupplier.get();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Both of these checks are on the normalized lists, which have null values removed. This means if there's an extra null somewhere, or if the null is in a different position between the expected and actual, we wouldn't catch it here. Is this intentional?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged :StorageEngine/Mapping The storage related side of mappings Team:StorageEngine >test Issues or PRs that are addressing/adding tests v8.19.0 v9.1.0
Projects
None yet
5 participants