Skip to content

Conversation

@cbuescher
Copy link
Member

Similar to #23973 this adds parsing from xContent for the Min, Max, Avg, Sum and ValueCount aggregation.
I tried to pull out common functionality to ParsedNumericMetricsAggregation.SingleValue. Since InternalCardinality
and InternalValueCount store a long value instead of a double, parsing and getters/setters for the value are slightly
different so I didn't include their parsed counterparts under ParsedNumericMetricsAggregation.SingleValue for now.
Also included one case where I tried pulling out common xContent rendering into the shared interface (in Sum) for discussion.
I'm unsure if I like that one but it would help reduce some code duplication.

This PR is WIP against a feature branch.

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

I had a first look, I'm happy to see that many things can be mutualized. I don't really like how the parsed Cardinality/ValueCount extends the ParsedNumericMetricsAggregation.SingleValue and don't use the double there and provide their own long value. I'm wondering if we could let SingleValue take care of the stringified value and have a Long and Double version of SingleValue where all parsing logic and XContent rendering would be placed.

I have to admit that I'm not sure if that's possible at all, so I'll take a look at this too

Copy link
Member

Choose a reason for hiding this comment

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

I tend to use the current class name, because this name is only used in log/error traces so that one can easily spot the class to look at. It seems that there's no convention in the codebase for that, so let's fix one at least for aggregations.

I'm +1 on ParsedAvg.class.getSimpleName() (but I'm OK to use AvgAggregationBuilder.NAME if both @javanna and you prefer)

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a strong opinion here, I don't think it makes a whole lot of difference

Copy link
Member Author

Choose a reason for hiding this comment

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

Will according to suggestion by @tlrx than, since I also don't mind much.

Copy link
Member

Choose a reason for hiding this comment

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

nit: Maybe declareSingeValueFields ?

Copy link
Member Author

Choose a reason for hiding this comment

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

okay

Copy link
Member

Choose a reason for hiding this comment

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

Maybe declareAggregationFields()? I think that "common" doesn't have much sense where there's 2-3 levels of inheritance..

Copy link
Member Author

Choose a reason for hiding this comment

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

okay

Copy link
Member

Choose a reason for hiding this comment

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

I think it can be shortened to
(parser, context) -> parseValue(parser, defaultNullValue)

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

Copy link
Member

Choose a reason for hiding this comment

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

Can we move all statics down? (after doXContentBody())

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

left a few comments but LGTM

Copy link
Member

Choose a reason for hiding this comment

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

do we need this class? and why does SingleValue have to be an inner class?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know, the idea was to pull out value()/getValueAsString() and the internal fields for the Min/Max/Sum/Avg aggregation, maybe some others of the single value aggregations that just store a double. I tried to mimic the inheritance structure of InternalNumericMetricsAggregation here, which contains inner classes for SingleValue and MultiValue. Maybe we don't need it, but I'd like to keep it for now and revisit this decision once we are done with all the single value aggregations.

Copy link
Member

Choose a reason for hiding this comment

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

I think this hierarchy makes little sense and we should not copy it to our objects unless there are good reasons to do so. Is the only reason consistency?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is sharing value/valueAsString() a good reason to keep ParsedNumericMetricsAggregation? Or rename it to ParsedSingleValueMetricsAggregation and remove the inner SingleValue class? My suspicion at this point is that we might also reuse some stuff for the MultiValue case but I cannot tell until we start working on those.

Copy link
Member

Choose a reason for hiding this comment

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

I do not see what ParsedNumericMetricsAggregation holds. Seems like it is used only as an ancestor for its inner class? In that case let's have ParsedSingleValueNumericMetricsAggregation as a top level class?

Copy link
Member

Choose a reason for hiding this comment

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

should we try and do without depending on DocValueFormat here? We can just do what this method does?

Copy link
Member Author

Choose a reason for hiding this comment

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

I replaced this with Double.toString(value).

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a strong opinion here, I don't think it makes a whole lot of difference

Copy link
Member

Choose a reason for hiding this comment

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

where is this logic in InternalAvg?

Copy link
Member Author

Choose a reason for hiding this comment

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

In InternalAvg the value field is only rendered if the avg normalizer (count) is not 0. (count != 0 ? getValue() : null). I choose to parse back null as Double.POSITIVE_INFINITY because that is what you get back when you divide a positive double by 0L. So I check for that value here to get the same xContent output like InternalAvg.

Copy link
Member

Choose a reason for hiding this comment

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

sounds good! leave a comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a comment.

Copy link
Member

Choose a reason for hiding this comment

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

what's left todo here? the static method is already in the interface?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was an example of how we could share the xContent rendering logic between InternalXY and ParsedXY aggregations. I don't know if it would work in all places. I only did it for SUM, I could try to do it for Min/Max/Avg etc but that means slight changes in the existing internal aggregations. Not sure which way to go here atm, maybe you have some opinion?

Copy link
Member

Choose a reason for hiding this comment

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

I think we should do it only when it's very simple to do. It is a bit funky to have this static method in the interface but that is the best place for it. @tlrx what do you think?

Copy link
Member Author

@cbuescher cbuescher Apr 18, 2017

Choose a reason for hiding this comment

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

I tried doing this for the aggregations in this PR in 1048678, but I'm not sure I like it. It avoids some code duplication but makes reading and reasoning about the code much harder in my opinion. Maybe we should only do it when it really saves a lot of duplication (like really long xContent methods), wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

yea I tend to agree, I am +0 on this :) I defer to Tanguy

Copy link
Member

Choose a reason for hiding this comment

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

here too, shall we try and not depend on the formatter?

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed this to Long.toString(valueCount).

Copy link
Member

Choose a reason for hiding this comment

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

s/formated/formatted

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

Copy link
Member

Choose a reason for hiding this comment

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

leftover

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

Copy link
Member

Choose a reason for hiding this comment

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

complete POSITIVE with POSITIVE_INFINITY ?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@cbuescher cbuescher removed the WIP label Apr 18, 2017
@cbuescher cbuescher force-pushed the addParsing-singleValueAggs branch from 0762331 to 9e6d11d Compare April 18, 2017 11:02
@cbuescher
Copy link
Member Author

@tlrx @javanna thanks for the reviews, I added changes according to most of your comments, left two discussions open for now before I squash/merge this later

@tlrx
Copy link
Member

tlrx commented Apr 18, 2017

Maybe we should only do it when it really saves a lot of duplication (like really long xContent methods), wdyt?

Yes, I agree. I think we should only do it when it saves a lot of duplication with custom logic. In this case it saves 1 line but added many more, and it also "force" people to look at what the Sum.renderXContent() is doing. I think we should not add those.

@cbuescher cbuescher force-pushed the addParsing-singleValueAggs branch from 1048678 to a6112a5 Compare April 18, 2017 16:01
@cbuescher cbuescher force-pushed the addParsing-singleValueAggs branch from a6112a5 to 210e101 Compare April 18, 2017 16:10
@cbuescher
Copy link
Member Author

@tlrx thanks, I reverted the commit where I pulled the xContent rendering into the interfaces, rebased and reordered the PR so changes are more self contained. I think I will merge this one manually to the feature branch without squashing so that the history better reflects the individual changes to each aggregation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants