Fixed rounding of bounds in scaled float comparison#27207
Merged
dakrone merged 2 commits intoelastic:masterfrom Nov 3, 2017
original-brownbear:27189
Merged
Fixed rounding of bounds in scaled float comparison#27207dakrone merged 2 commits intoelastic:masterfrom original-brownbear:27189
dakrone merged 2 commits intoelastic:masterfrom
original-brownbear:27189
Conversation
jpountz
approved these changes
Nov 3, 2017
Contributor
jpountz
left a comment
There was a problem hiding this comment.
I left a comment about testing more cases, but your change looks good to me.
Contributor
There was a problem hiding this comment.
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());
}
Contributor
Author
There was a problem hiding this comment.
@jpountz thanks for reviewing, I like adding some more assertions :) I'll just add those to this PR?
Contributor
Author
|
@jpountz added your assertions :) |
Member
|
Thanks @original-brownbear, I'll wait for CI to finish and then merge this |
Contributor
Author
|
Rebased this one just now since it failed the BWC tests here https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+pull-request/5329/console |
Contributor
Author
|
@dakrone now it's green :) |
dakrone
pushed a commit
that referenced
this pull request
Nov 3, 2017
dakrone
pushed a commit
that referenced
this pull request
Nov 3, 2017
martijnvg
added a commit
that referenced
this pull request
Nov 4, 2017
* 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)
martijnvg
added a commit
that referenced
this pull request
Nov 4, 2017
* 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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