Skip to content
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

Merged
merged 1 commit into from
Jan 18, 2017

Conversation

michael-mclawhorn
Copy link
Contributor

Fixed missing coercion theta sketch path.
Added a ton of tests.

@michael-mclawhorn michael-mclawhorn force-pushed the MissingThetaSketchUnwrapperInMetricMaker branch from 3371ade to 1a5132a Compare December 20, 2016 21:51
@michael-mclawhorn michael-mclawhorn force-pushed the MissingThetaSketchUnwrapperInMetricMaker branch from 1a5132a to 92c40b8 Compare December 20, 2016 23:09
*
* @return A post aggregation referencing a sketch value
* @deprecated use the static version {@link #getSketchField(MetricField)} by preference
*/
protected PostAggregation getSketchField(String fieldName) {
Copy link
Collaborator

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) {
Copy link
Collaborator

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
/**
Copy link
Collaborator

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:
Copy link
Collaborator

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:
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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(){
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Delete empty method

@michael-mclawhorn michael-mclawhorn force-pushed the MissingThetaSketchUnwrapperInMetricMaker branch from 92c40b8 to 8e2f1de Compare January 3, 2017 17:32
@michael-mclawhorn
Copy link
Contributor Author

Responded to change requests

Copy link
Collaborator

@garyluoex garyluoex left a 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
Copy link
Collaborator

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?

Copy link
Contributor Author

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()) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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)
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair enough

Copy link
Contributor Author

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.
@michael-mclawhorn michael-mclawhorn force-pushed the MissingThetaSketchUnwrapperInMetricMaker branch from 615c883 to 5f5da6a Compare January 18, 2017 17:34
@michael-mclawhorn michael-mclawhorn merged commit 5f5da6a into master Jan 18, 2017
@michael-mclawhorn michael-mclawhorn deleted the MissingThetaSketchUnwrapperInMetricMaker branch January 18, 2017 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants