Skip to content

Fix match query on a scaled_float property no longer matches for some values #17879

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 1 commit into
base: main
Choose a base branch
from

Conversation

kkewwei
Copy link
Contributor

@kkewwei kkewwei commented Apr 10, 2025

Description

This PR only addresses the mismatch issue.

As it's known, float and double types suffer from precision loss, and it's inevitable. When reading doc_value in the filed(such as range, sorting, or aggregation), it can lead to unforeseen exceptions. The root cause lies in the fact that the precision of float/double data is already lost before storing.

long scaledValue = Math.round(doubleValue * scalingFactor);

It can be extremely terrifying when related to money.

To solve it, I will submit a new PR. In this PR, I will create a new type big_decimal, supported by BigDecimal to effectively eliminate the precision loss.

Related Issues

Resolves #12433

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Contributor

❌ Gradle check result for 40380fb: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@kkewwei kkewwei force-pushed the scaled_float_not_match branch from 40380fb to adbf317 Compare April 10, 2025 15:05
Copy link
Contributor

❌ Gradle check result for adbf317: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@kkewwei kkewwei marked this pull request as draft April 10, 2025 16:10
@@ -229,7 +229,7 @@ public String typeName() {
@Override
public Query termQuery(Object value, QueryShardContext context) {
failIfNotIndexedAndNoDocValues();
long scaledValue = Math.round(scale(value));
long scaledValue = Math.round(parse(value) * scalingFactor);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistent with precision loss when indexing

Copy link
Contributor Author

@kkewwei kkewwei Apr 14, 2025

Choose a reason for hiding this comment

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

We can also change the code in indexing, but it will cause indexing performance regression.

Math.round(doubleValue * scalingFactor) -> Math.round(scale(value))

Copy link
Member

Choose a reason for hiding this comment

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

This look good to me, it's better to extract this logic Math.round(parse(value) * scalingFactor) to a single place, so termQuery and parseCreateField for indexing just use that.

@kkewwei kkewwei marked this pull request as ready for review April 10, 2025 16:36
Copy link
Contributor

❌ Gradle check result for 7a2fa3f: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@kkewwei kkewwei force-pushed the scaled_float_not_match branch 2 times, most recently from 2ba7c47 to ade3cae Compare April 11, 2025 02:46
Copy link
Contributor

❌ Gradle check result for 66bb50e: null

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@kkewwei
Copy link
Contributor Author

kkewwei commented Apr 11, 2025

❌ Gradle check result for 66bb50e: null

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

MinimumClusterManagerNodesIT.testThreeNodesNoClusterManagerBlock #14289
RemoteStoreBackpressureAndResiliencyIT.testWritesRejectedDueToTimeLagBreach #12411
DedicatedClusterSnapshotRestoreIT.testSnapshotWithStuckNode #15806

@kkewwei
Copy link
Contributor Author

kkewwei commented Apr 11, 2025

@bowenlan-amzn would you mind have a look in your spare time, very thank you.

@kkewwei kkewwei force-pushed the scaled_float_not_match branch from 66bb50e to 75cea4e Compare April 14, 2025 08:20
Copy link
Contributor

❌ Gradle check result for 75cea4e: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@kkewwei kkewwei force-pushed the scaled_float_not_match branch from 75cea4e to 88bcdda Compare April 14, 2025 09:46
Copy link
Contributor

❌ Gradle check result for 88bcdda: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@kkewwei
Copy link
Contributor Author

kkewwei commented Apr 14, 2025

❌ Gradle check result for 88bcdda: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

EhCacheDiskCacheTests.testComputeIfAbsentConcurrently #16159

Copy link
Contributor

❌ Gradle check result for b1a19aa: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@kkewwei kkewwei force-pushed the scaled_float_not_match branch from b1a19aa to b36c641 Compare April 18, 2025 02:57
Copy link
Contributor

❌ Gradle check result for b36c641: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@kkewwei kkewwei closed this Apr 18, 2025
@kkewwei kkewwei reopened this Apr 18, 2025
Copy link
Contributor

❌ Gradle check result for b36c641: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@kkewwei
Copy link
Contributor Author

kkewwei commented Apr 18, 2025

❌ Gradle check result for b36c641: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

RemoteStorePinnedTimestampsGarbageCollectionIT.testLiveIndexNoPinnedTimestampsWithExtraGenSetting #16088
DedicatedClusterSnapshotRestoreIT.testSnapshotWithStuckNode #15806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Search Search query, autocomplete ...etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] match query on a scaled_float property no longer matches for some values
2 participants