-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fixed rounding of bounds in scaled float comparison #27207
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
Conversation
255440b to
783d46b
Compare
jpountz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a comment about testing more cases, but your change looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expanded your assertions a bit if you are ok with them:
public void testRoundsUpperBoundCorrectly() {
ScaledFloatFieldMapper.ScaledFloatFieldType ft = new ScaledFloatFieldMapper.ScaledFloatFieldType();
ft.setName("scaled_float");
ft.setScalingFactor(100.0);
Query scaledFloatQ = ft.rangeQuery(null, 0.1, true, false, null);
assertEquals("scaled_float:[-9223372036854775808 TO 9]", scaledFloatQ.toString());
scaledFloatQ = ft.rangeQuery(null, 0.1, true, true, null);
assertEquals("scaled_float:[-9223372036854775808 TO 10]", scaledFloatQ.toString());
scaledFloatQ = ft.rangeQuery(null, 0.095, true, false, null);
assertEquals("scaled_float:[-9223372036854775808 TO 9]", scaledFloatQ.toString());
scaledFloatQ = ft.rangeQuery(null, 0.095, true, true, null);
assertEquals("scaled_float:[-9223372036854775808 TO 9]", scaledFloatQ.toString());
scaledFloatQ = ft.rangeQuery(null, 0.105, true, false, null);
assertEquals("scaled_float:[-9223372036854775808 TO 10]", scaledFloatQ.toString());
scaledFloatQ = ft.rangeQuery(null, 0.105, true, true, null);
assertEquals("scaled_float:[-9223372036854775808 TO 10]", scaledFloatQ.toString());
}
public void testRoundsLowerBoundCorrectly() {
ScaledFloatFieldMapper.ScaledFloatFieldType ft = new ScaledFloatFieldMapper.ScaledFloatFieldType();
ft.setName("scaled_float");
ft.setScalingFactor(100.0);
Query scaledFloatQ = ft.rangeQuery(-0.1, null, false, true, null);
assertEquals("scaled_float:[-9 TO 9223372036854775807]", scaledFloatQ.toString());
scaledFloatQ = ft.rangeQuery(-0.1, null, true, true, null);
assertEquals("scaled_float:[-10 TO 9223372036854775807]", scaledFloatQ.toString());
scaledFloatQ = ft.rangeQuery(-0.095, null, false, true, null);
assertEquals("scaled_float:[-9 TO 9223372036854775807]", scaledFloatQ.toString());
scaledFloatQ = ft.rangeQuery(-0.095, null, true, true, null);
assertEquals("scaled_float:[-9 TO 9223372036854775807]", scaledFloatQ.toString());
scaledFloatQ = ft.rangeQuery(-0.105, null, false, true, null);
assertEquals("scaled_float:[-10 TO 9223372036854775807]", scaledFloatQ.toString());
scaledFloatQ = ft.rangeQuery(-0.105, null, true, true, null);
assertEquals("scaled_float:[-10 TO 9223372036854775807]", scaledFloatQ.toString());
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jpountz thanks for reviewing, I like adding some more assertions :) I'll just add those to this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please!
|
@jpountz added your assertions :) |
|
Thanks @original-brownbear, I'll wait for CI to finish and then merge this |
593f8ee to
a20f366
Compare
|
Rebased this one just now since it failed the BWC tests here https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+pull-request/5329/console |
|
@dakrone now it's green :) |
* es/master: Fix snapshot getting stuck in INIT state (#27214) Add an example of dynamic field names (#27255) #26260 Allow ip_range to accept CIDR notation (#27192) #27189 Fixed rounding of bounds in scaled float comparison (#27207) Add support for Gradle 4.3 (#27249) Fixes QueryStringQueryBuilderTests build: Fix setting the incorrect bwc version in mixed cluster qa module [Test] Fix QueryStringQueryBuilderTests.testExistsFieldQuery BWC Adjust assertions for sequence numbers BWC tests Do not create directories if repository is readonly (#26909) [Test] Fix InternalStatsTests [Test] Fix QueryStringQueryBuilderTests.testExistsFieldQuery Uses norms for exists query if enabled (#27237) Reinstate recommendation for ≥ 3 master-eligible nodes. (#27204)
* 6.x: Add an example of dynamic field names (#27255) fixed checkstyle violation #26260 Allow ip_range to accept CIDR notation (#27192) #27189 Fixed rounding of bounds in scaled float comparison (#27207) [TEST] Fix failing exists query test test: Do not run old parent/child tests against a cluster with minimum version greater than 6.0.0 Add support for Gradle 4.3 (#27249) Fixes QueryStringQueryBuilderTests build: Fix setting the incorrect bwc version in mixed cluster qa module fix compil after backport [Test] Fix QueryStringQueryBuilderTests.testExistsFieldQuery BWC Adjust assertions for sequence numbers BWC tests Do not create directories if repository is readonly (#26909) [Test] Fix QueryStringQueryBuilderTests.testExistsFieldQuery Uses norms for exists query if enabled (#27237) Reinstate recommendation for ≥ 3 master-eligible nodes. (#27204)
This fixes #27189 I think:
nextDown,nextUpand multiplication by the scaling factor to reduce rounding errors. Now the error incurred bynextUpandnextDowndoesn't propagate into the multiplication by the scaling factor, whereas without this change the error incurred when multiplying twodoublecan cancel out theMath.nextDownstep as seen in the example belowwhile