Skip to content

Conversation

@tlrx
Copy link
Member

@tlrx tlrx commented May 5, 2017

This pull request adds parsing methods for Long/Double/String terms aggregations

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 minor comments, LGTM otherwise

if (keyAsString != null) {
return keyAsString;
}
return DocValueFormat.RAW.format((Double) getKey());
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 remove the dependency on DocValueFormat here?

if (keyAsString != null) {
return keyAsString;
}
return DocValueFormat.RAW.format((Long) getKey());
Copy link
Member

Choose a reason for hiding this comment

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

this casting is rather annoying. but I guess we can't do much about it as MultiBucketsAggregation.Bucket has getKey return an Object.

Copy link
Member

Choose a reason for hiding this comment

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

also remove DocValueFormat usage here too?

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 casting is rather annoying. but I guess we can't do much about it as MultiBucketsAggregation.Bucket has getKey return an Object.

It also annoyed @cbuescher when he reviewed the parsing PR about histograms. I think I can remove the generic type and get rid of the casting at once, I'll do that.

}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

make it final?


@Override
public List<? extends Terms.Bucket> getBuckets() {
return buckets.stream().map(bucket -> (Terms.Bucket) bucket).collect(Collectors.toList());
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 get rid of this casting somehow?

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, by adding a generic type to ParsedMultiBucketAggregation

this.docCountErrorUpperBound = docCountErrorUpperBound;
}

private void setSumOtherDocCount(long sumOtherDocCount) {
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 we can get rid of private setters and just set the field values where we need to set them?

if (keyAsString != null) {
return keyAsString;
}
return DocValueFormat.RAW.format((BytesRef) super.getKey());
Copy link
Member

Choose a reason for hiding this comment

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

remove DocValueFormat dep here too?

@tlrx
Copy link
Member Author

tlrx commented May 9, 2017

Thanks @javanna for your review. I updated the code according to your comments. Can you please have another look?

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.

looks great @tlrx thanks a lot!

} else {
return DocValueFormat.RAW.format((Long) super.getKey());
}
if (key != null){
Copy link
Member

Choose a reason for hiding this comment

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

missing whitespace after the parentheses :)

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@tlrx thanks, after looking at this I think I start to understand the structure of how we parse multi bucket aggregations a lot better. Given the already complicated inheritance structure of the aggregations & buckets it looks great in using what we already have.

}

protected Aggregations(List<? extends Aggregation> aggregations) {
public Aggregations(List<? extends Aggregation> aggregations) {
Copy link
Member

Choose a reason for hiding this comment

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

+1 I also needed this in #24564

bucket.showDocCountError = true;
}
} else if (token == XContentParser.Token.START_OBJECT) {
aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class));
Copy link
Member

Choose a reason for hiding this comment

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

Side note: we talked about this earlier, if we encounter a "type#name" combination here where "type" isn't registered we will throw an exception, there is no way to ignore this at the moment. I don't know if we should add that option to parseTypedKeysObject and also to parser#namedObject
This has nothing to do with this PR.

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 think it's good thing that an exception is thrown. Handling uneregistered aggregation types is like handling unknown fields - for now we throw exceptions. If we want to manage those then I agree we will add to change the behavior of parseTypedKeysObject.

@tlrx tlrx merged commit 3c66ac0 into elastic:feature/client_aggs_parsing May 10, 2017
@tlrx
Copy link
Member Author

tlrx commented May 10, 2017

Thanks @javanna @cbuescher !

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