Skip to content

Conversation

@tlrx
Copy link
Member

@tlrx tlrx commented May 16, 2017

This pull request adds the parsing logic for InternalBinaryRange aggregation.

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.

LGTM

Copy link
Member

Choose a reason for hiding this comment

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

it seems like the key can really be null here, in which case we just skip the key field?

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, the key can be null. I didn't handle this case correctly so I changed InternalBinaryRangeTests so that it randomly generates a bucket with a null key. I also changed the bucket parsing so that it handles keyed buckets with null keys.

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.

I left two minor nits, otherwise LGTM.

Copy link
Member

Choose a reason for hiding this comment

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

As far as I can see both getFrom/getFromAsString and getTo/getToAsString return String values. Should we store the converted String instead of the BytesRef in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutly, good catch

Copy link
Member

Choose a reason for hiding this comment

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

Not so important, but as far as I can see InternalBinaryRange#toXContent() writes a String here, so we should be able to parse the value back with parser.text()?

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, thanks

@tlrx tlrx force-pushed the add-parsing-to-binary-range branch from 58b38aa to 426d371 Compare May 16, 2017 15:03
@tlrx
Copy link
Member Author

tlrx commented May 16, 2017

Thanks for your reviews! I changed few things around null keys and keyed buckets, I'll be happy if one of you can have another look.

Copy link
Member

Choose a reason for hiding this comment

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

it is ok to return null here when calling getKey and getKeyAsString? Although with keyed response we actually do print out a key? Seems like this behaviour doesn't align to REST but does align with what transport client does today?

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 might be missing something but my latest changes should align the behavior... When the key is null, a keyed response will generate a string to name the object in the XContent response but the getKey/getKeyAsString will still return null.

This is what we do here: when we stop to parse the response, we check if the response was keyed and in this case we "try to detect" if the key has been generated on purpose using the from/to values. If so, we know that the original key is null et we set it explicitly.

The InternalMultiBucketAggregationTestCase.assertBucket() takes care of verifying that the getKey/getKeyAsString methods returns the same values after the parsing

Copy link
Member

Choose a reason for hiding this comment

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

I had missed that last line :) sorry!

Copy link
Member

Choose a reason for hiding this comment

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

the thing that worries me a bit here is that we've been testing fromXContent and toXContent everywhere, but we never test the returned values through getters, assuming that they will be the same printed out as part of toXContent, which is not the case here.

Copy link
Member Author

Choose a reason for hiding this comment

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

we never test the returned values through getters, assuming that they will be the same printed out as part of toXContent, which is not the case here.

We should always test this. The InternalAggregationTestCase sub classes can override the assertFromXContent() method in order to test getters and other methods provided by the aggregation. Multi bucket ones can override assertBucket().

Copy link
Member

Choose a reason for hiding this comment

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

alright, sounds good!

@tlrx tlrx force-pushed the add-parsing-to-binary-range branch from 87518b5 to 1ee7eb1 Compare May 18, 2017 07:23
@tlrx tlrx merged commit 25fceb8 into elastic:feature/client_aggs_parsing May 18, 2017
@tlrx
Copy link
Member Author

tlrx commented May 18, 2017

Thanks @javanna @cbuescher

@tlrx tlrx deleted the add-parsing-to-binary-range branch May 18, 2017 07:25
javanna pushed a commit to javanna/elasticsearch that referenced this pull request May 23, 2017
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