-
Notifications
You must be signed in to change notification settings - Fork 96
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
Missing theta sketch unwrapper in metric maker #128
Missing theta sketch unwrapper in metric maker #128
Conversation
3371ade
to
1a5132a
Compare
1a5132a
to
92c40b8
Compare
* | ||
* @return A post aggregation referencing a sketch value | ||
* @deprecated use the static version {@link #getSketchField(MetricField)} by preference | ||
*/ | ||
protected PostAggregation getSketchField(String fieldName) { |
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.
Needs @Deprecated
annotation
return ((ThetaSketchEstimatePostAggregation) field).getField(); | ||
} | ||
|
||
if (field instanceof ThetaSketchEstimatePostAggregation) { |
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.
Duplicate with the one above it?
import spock.lang.Specification | ||
|
||
import spock.lang.Unroll | ||
/** |
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.
Blank line needed
|
||
@Unroll | ||
def "getSketchField throws error when given a non sketch based field #fromMetric.name "() { | ||
setup: |
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.
Empty setup
block isn't useful
|
||
@Unroll | ||
def "getSketchField returns a sketch aggregation of type #expected.type for metric named: #fromMetric.name "() { | ||
setup: |
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.
Empty setup
block isn't doing anything
@@ -115,64 +184,59 @@ class MetricMakerSpec extends Specification { | |||
then: | |||
thrown(IllegalArgumentException) | |||
} | |||
def "When a metric has too many dependent metrics, an exception is thrown"(){ | |||
given: "One more than the number of dependent metrics this maker depends on." | |||
List<String> dependentMetricNames = buildDependentMetricNames(maker.getDependentMetricsRequired()+1) |
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.
This arithmetic should be more spaced
|
||
then: | ||
thrown(IllegalArgumentException) | ||
} | ||
|
||
def "When a claimed dependent metric does not exist in the maker's dictionary, an exception is thrown"(){ | ||
given: "A list of dependent metrics, one of which doesn't exist" | ||
List<String> dependentMetricNames = buildDependentMetricNames(maker.getDependentMetricsRequired()-1) | ||
maker.metrics.putAll(makeEmptyMetrics(dependentMetricNames)) | ||
List<String> dependentMetricNames = buildDependentMetricNames(DEPENDENT_METRICS-1) |
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.
This arithmetic should be more spaced
def "When a metric has too few dependent metrics, an exception is thrown."(){ | ||
given: "One fewer dependent metrics than this metric depends on" | ||
List<String> dependentMetricNames = buildDependentMetricNames(maker.getDependentMetricsRequired()-1) | ||
maker.metrics.putAll(makeEmptyMetrics(dependentMetricNames)) | ||
List<String> dependentMetricNames = buildDependentMetricNames(DEPENDENT_METRICS-1) |
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.
This arithmetic should be more spaced
} | ||
|
||
def setup(){ | ||
} |
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.
Delete empty method
92c40b8
to
8e2f1de
Compare
Responded to change requests |
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.
Just some personal preference things, feel free to leave it as is. 👍 (Just an addition question, is there a strong reason to make those functions static? It seems like it would add some work to get the field instead of reusing the code in the function which now takes a field instead of a string)
*/ | ||
protected static PostAggregation getNumericField(MetricField field) { | ||
// If the field is a sketch, wrap it in a sketch estimate, if it's an aggregation, create a post aggregation | ||
// Otherwise it is a number post aggregation already |
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.
Is this comment necessary? It should be in the function java doc already right?
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 agree that it is redundant. I'll consider removing it. I think it got duplicated up into the javadoc and wasn't pruned.
} | ||
|
||
if (field instanceof ThetaSketchEstimatePostAggregation) { | ||
return ((ThetaSketchEstimatePostAggregation) field).getField(); | ||
} | ||
|
||
// Check for sketches, since we require them after this point | ||
if (!field.isSketch()) { |
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.
Should we move this if
check above the previous two checks so that the code feels more logical?
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.
Not exactly. There are three possibilities. The thing IS a sketch, it is an estimating wrapper AROUND a sketch, or otherwise. The way to test whether it's a simple wrapper around a sketch is whether it's one of the Estimator aggregations.
* | ||
* @return A post aggregator representing a number field value | ||
*/ | ||
protected static PostAggregation getSketchField(MetricField field) { | ||
// SketchEstimatePostAggregations are just wrappers for the actual PostAggregation we want to return | ||
if (field instanceof SketchEstimatePostAggregation) { |
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.
It seems like SketchEstimatePostAggregation
is deprecated, should we log something here to take note of it?
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.
The nature of the situation is that the user has one of two sketch libraries implemented in their code. If they have the old sketch library in their code, then it's not a log-worthy event that this code is being used, because it's mandatory.
We'll probably pull the deprecated versions slightly after the next version bump.
|
||
when: | ||
maker.make(METRIC_NAME, dependentMetricNames) | ||
getMakerInstance().make(METRIC_NAME, dependentMetricNames) | ||
|
||
then: | ||
thrown(IllegalArgumentException) |
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 personally prefer adding the error message to the exception check, just to make sure that it is the correct exception thrown.
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.
fair enough
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.
done
Tightened testing on metric maker errors Much more comprehensive testing of field coercions. Deprecated dictionary dependent field coercion instance methods in favor of static field->field coercion methods.
615c883
to
5f5da6a
Compare
Fixed missing coercion theta sketch path.
Added a ton of tests.