Fix two improper casts in HavingSpecMetricComparator.#5352
Merged
gianm merged 4 commits intoapache:masterfrom Feb 6, 2018
Merged
Fix two improper casts in HavingSpecMetricComparator.#5352gianm merged 4 commits intoapache:masterfrom
gianm merged 4 commits intoapache:masterfrom
Conversation
Fixes two things: 1. An improper double-to-long cast when comparing double metrics to any kind of value, which was a regression from apache#4883. 2. An improper double-to-long cast when comparing a long/int metric to a double/float value: the value was cast to long/int, drawing strange conclusions like int 100 matching a havingSpec of equalTo(100.5).
nishantmonu51
approved these changes
Feb 6, 2018
| if (value instanceof Long || value instanceof Integer) { | ||
| return Longs.compare(n, value.longValue()); | ||
| } else if (value instanceof Double || value instanceof Float) { | ||
| return BigDecimal.valueOf(n).compareTo(BigDecimal.valueOf(value.doubleValue())); |
Member
There was a problem hiding this comment.
please add comment about reason to not use Doubles.compare and floats.compare ?
Contributor
Author
|
@nishantmonu51 added comments; thanks for review. |
himanshug
reviewed
Feb 6, 2018
| float l = ((Float) metricValueObj).floatValue(); | ||
| return Floats.compare(l, value.floatValue()); | ||
| float n = (Float) metricValueObj; | ||
| return Floats.compare(n, value.floatValue()); |
Contributor
There was a problem hiding this comment.
can we combine float and double also similar to long and int... also check type of value instance and use BigDecimal if it is not double? ... to keep it similar to long/int case.
Contributor
Author
There was a problem hiding this comment.
@himanshug I edited the code to simplify it, and factored out the BigDecimal stuff to a helper method. Now the branches are more similar.
himanshug
approved these changes
Feb 6, 2018
gianm
added a commit
to gianm/druid
that referenced
this pull request
Feb 6, 2018
* Fix two improper casts in HavingSpecMetricComparator. Fixes two things: 1. An improper double-to-long cast when comparing double metrics to any kind of value, which was a regression from apache#4883. 2. An improper double-to-long cast when comparing a long/int metric to a double/float value: the value was cast to long/int, drawing strange conclusions like int 100 matching a havingSpec of equalTo(100.5). * Add comments. * Remove extraneous comment. * Simplify code a bit.
jon-wei
pushed a commit
that referenced
this pull request
Feb 7, 2018
* Fix two improper casts in HavingSpecMetricComparator. Fixes two things: 1. An improper double-to-long cast when comparing double metrics to any kind of value, which was a regression from #4883. 2. An improper double-to-long cast when comparing a long/int metric to a double/float value: the value was cast to long/int, drawing strange conclusions like int 100 matching a havingSpec of equalTo(100.5). * Add comments. * Remove extraneous comment. * Simplify code a bit.
gianm
added a commit
to implydata/druid-public
that referenced
this pull request
Feb 7, 2018
* Fix two improper casts in HavingSpecMetricComparator. Fixes two things: 1. An improper double-to-long cast when comparing double metrics to any kind of value, which was a regression from apache#4883. 2. An improper double-to-long cast when comparing a long/int metric to a double/float value: the value was cast to long/int, drawing strange conclusions like int 100 matching a havingSpec of equalTo(100.5). * Add comments. * Remove extraneous comment. * Simplify code a bit.
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.
Fixes two things:
kind of value, which was a regression from greater-than/less-than/equal-to havingSpec to call AggregatorFactory.finalizeComputation(..) #4883.
double/float value: the value was cast to long/int, drawing strange
conclusions like int 100 matching a havingSpec of equalTo(100.5).
Marked 0.12.0 since one of these was introduced in #4883, new in 0.12.0.