{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/116956390","pull_request_review_id":38618773,"id":116956390,"diff_hunk":"@@ -0,0 +1,168 @@\n+/*\n+ * Licensed to Elasticsearch under one or more contributor\n+ * license agreements. See the NOTICE file distributed with\n+ * this work for additional information regarding copyright\n+ * ownership. Elasticsearch licenses this file to you under\n+ * the Apache License, Version 2.0 (the \"License\"); you may\n+ * not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package org.elasticsearch.search.aggregations.bucket.range;\n+\n+import org.elasticsearch.common.xcontent.ObjectParser;\n+import org.elasticsearch.common.xcontent.XContentBuilder;\n+import org.elasticsearch.common.xcontent.XContentParser;\n+import org.elasticsearch.common.xcontent.XContentParserUtils;\n+import org.elasticsearch.search.aggregations.Aggregation;\n+import org.elasticsearch.search.aggregations.Aggregations;\n+import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation;\n+import org.elasticsearch.search.aggregations.bucket.range.ip.IpRangeAggregationBuilder;\n+\n+import java.io.IOException;\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;\n+\n+public class ParsedBinaryRange extends ParsedMultiBucketAggregation<ParsedBinaryRange.ParsedBucket> implements Range {\n+\n+    @Override\n+    public String getType() {\n+        return IpRangeAggregationBuilder.NAME;\n+    }\n+\n+    @Override\n+    public List<? extends Range.Bucket> getBuckets() {\n+        return buckets;\n+    }\n+\n+    private static ObjectParser<ParsedBinaryRange, Void> PARSER =\n+            new ObjectParser<>(ParsedBinaryRange.class.getSimpleName(), true, ParsedBinaryRange::new);\n+    static {\n+        declareMultiBucketAggregationFields(PARSER,\n+                parser -> ParsedBucket.fromXContent(parser, false),\n+                parser -> ParsedBucket.fromXContent(parser, true));\n+    }\n+\n+    public static ParsedBinaryRange fromXContent(XContentParser parser, String name) throws IOException {\n+        ParsedBinaryRange aggregation = PARSER.parse(parser, null);\n+        aggregation.setName(name);\n+        return aggregation;\n+    }\n+\n+    public static class ParsedBucket extends ParsedMultiBucketAggregation.ParsedBucket implements Range.Bucket {\n+\n+        private String key;\n+        private String from;\n+        private String to;\n+\n+        @Override\n+        public Object getKey() {\n+            return key;\n+        }\n+\n+        @Override\n+        public String getKeyAsString() {\n+            return key;\n+        }\n+\n+        @Override\n+        public Object getFrom() {\n+            return from;\n+        }\n+\n+        @Override\n+        public String getFromAsString() {\n+            return from;\n+        }\n+\n+        @Override\n+        public Object getTo() {\n+            return to;\n+        }\n+\n+        @Override\n+        public String getToAsString() {\n+            return to;\n+        }\n+\n+        @Override\n+        public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {\n+            if (isKeyed()) {\n+                builder.startObject(key != null ? key : rangeKey(from, to));\n+            } else {\n+                builder.startObject();\n+                if (key != null) {\n+                    builder.field(CommonFields.KEY.getPreferredName(), key);\n+                }\n+            }\n+            if (from != null) {\n+                builder.field(CommonFields.FROM.getPreferredName(), getFrom());\n+            }\n+            if (to != null) {\n+                builder.field(CommonFields.TO.getPreferredName(), getTo());\n+            }\n+            builder.field(CommonFields.DOC_COUNT.getPreferredName(), getDocCount());\n+            getAggregations().toXContentInternal(builder, params);\n+            builder.endObject();\n+            return builder;\n+        }\n+\n+        static ParsedBucket fromXContent(final XContentParser parser, final boolean keyed) throws IOException {\n+            final ParsedBucket bucket = new ParsedBucket();\n+            bucket.setKeyed(keyed);\n+            XContentParser.Token token = parser.currentToken();\n+            String currentFieldName = parser.currentName();\n+\n+            String rangeKey = null;\n+            if (keyed) {\n+                ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);\n+                rangeKey = currentFieldName;\n+                ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);\n+            }\n+\n+            List<Aggregation> aggregations = new ArrayList<>();\n+            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {\n+                if (token == XContentParser.Token.FIELD_NAME) {\n+                    currentFieldName = parser.currentName();\n+                } else if (token.isValue()) {\n+                    if (CommonFields.KEY.getPreferredName().equals(currentFieldName)) {\n+                        bucket.key = parser.text();\n+                    } else if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) {\n+                        bucket.setDocCount(parser.longValue());\n+                    } else if (CommonFields.FROM.getPreferredName().equals(currentFieldName)) {\n+                        bucket.from = parser.text();\n+                    } else if (CommonFields.TO.getPreferredName().equals(currentFieldName)) {\n+                        bucket.to = parser.text();\n+                    }\n+                } else if (token == XContentParser.Token.START_OBJECT) {\n+                    aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class));\n+                }\n+            }\n+            bucket.setAggregations(new Aggregations(aggregations));\n+\n+            if (keyed) {\n+                if (rangeKey(bucket.from, bucket.to).equals(rangeKey)) {\n+                    bucket.key = null;","path":"core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ParsedBinaryRange.java","position":156,"original_position":156,"commit_id":"87518b5460ba12cd871b19855a541bcd4388ed60","original_commit_id":"87518b5460ba12cd871b19855a541bcd4388ed60","user":{"login":"tlrx","id":642733,"avatar_url":"https://avatars2.githubusercontent.com/u/642733?v=3","gravatar_id":"","url":"https://api.github.com/users/tlrx","html_url":"https://github.com/tlrx","followers_url":"https://api.github.com/users/tlrx/followers","following_url":"https://api.github.com/users/tlrx/following{/other_user}","gists_url":"https://api.github.com/users/tlrx/gists{/gist_id}","starred_url":"https://api.github.com/users/tlrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlrx/subscriptions","organizations_url":"https://api.github.com/users/tlrx/orgs","repos_url":"https://api.github.com/users/tlrx/repos","events_url":"https://api.github.com/users/tlrx/events{/privacy}","received_events_url":"https://api.github.com/users/tlrx/received_events","type":"User","site_admin":false},"body":"> 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.\r\n\r\nWe 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().","created_at":"2017-05-17T09:48:14Z","updated_at":"2017-05-17T09:48:14Z","html_url":"https://github.com/elastic/elasticsearch/pull/24706#discussion_r116956390","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/24706","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/116956390"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/24706#discussion_r116956390"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/24706"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/24706","id":120792845,"html_url":"https://github.com/elastic/elasticsearch/pull/24706","diff_url":"https://github.com/elastic/elasticsearch/pull/24706.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/24706.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/24706","number":24706,"state":"open","locked":false,"title":"Add parsing method for binary range aggregation","user":{"login":"tlrx","id":642733,"avatar_url":"https://avatars2.githubusercontent.com/u/642733?v=3","gravatar_id":"","url":"https://api.github.com/users/tlrx","html_url":"https://github.com/tlrx","followers_url":"https://api.github.com/users/tlrx/followers","following_url":"https://api.github.com/users/tlrx/following{/other_user}","gists_url":"https://api.github.com/users/tlrx/gists{/gist_id}","starred_url":"https://api.github.com/users/tlrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlrx/subscriptions","organizations_url":"https://api.github.com/users/tlrx/orgs","repos_url":"https://api.github.com/users/tlrx/repos","events_url":"https://api.github.com/users/tlrx/events{/privacy}","received_events_url":"https://api.github.com/users/tlrx/received_events","type":"User","site_admin":false},"body":"This pull request adds the parsing logic for `InternalBinaryRange` aggregation.","created_at":"2017-05-16T10:23:58Z","updated_at":"2017-05-17T09:48:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2a5470309e93526af2fc856b91c1945b54f801fd","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/24706/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/24706/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/24706/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/87518b5460ba12cd871b19855a541bcd4388ed60","head":{"label":"tlrx:add-parsing-to-binary-range","ref":"add-parsing-to-binary-range","sha":"87518b5460ba12cd871b19855a541bcd4388ed60","user":{"login":"tlrx","id":642733,"avatar_url":"https://avatars2.githubusercontent.com/u/642733?v=3","gravatar_id":"","url":"https://api.github.com/users/tlrx","html_url":"https://github.com/tlrx","followers_url":"https://api.github.com/users/tlrx/followers","following_url":"https://api.github.com/users/tlrx/following{/other_user}","gists_url":"https://api.github.com/users/tlrx/gists{/gist_id}","starred_url":"https://api.github.com/users/tlrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlrx/subscriptions","organizations_url":"https://api.github.com/users/tlrx/orgs","repos_url":"https://api.github.com/users/tlrx/repos","events_url":"https://api.github.com/users/tlrx/events{/privacy}","received_events_url":"https://api.github.com/users/tlrx/received_events","type":"User","site_admin":false},"repo":{"id":24718639,"name":"elasticsearch","full_name":"tlrx/elasticsearch","owner":{"login":"tlrx","id":642733,"avatar_url":"https://avatars2.githubusercontent.com/u/642733?v=3","gravatar_id":"","url":"https://api.github.com/users/tlrx","html_url":"https://github.com/tlrx","followers_url":"https://api.github.com/users/tlrx/followers","following_url":"https://api.github.com/users/tlrx/following{/other_user}","gists_url":"https://api.github.com/users/tlrx/gists{/gist_id}","starred_url":"https://api.github.com/users/tlrx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlrx/subscriptions","organizations_url":"https://api.github.com/users/tlrx/orgs","repos_url":"https://api.github.com/users/tlrx/repos","events_url":"https://api.github.com/users/tlrx/events{/privacy}","received_events_url":"https://api.github.com/users/tlrx/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tlrx/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/tlrx/elasticsearch","forks_url":"https://api.github.com/repos/tlrx/elasticsearch/forks","keys_url":"https://api.github.com/repos/tlrx/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tlrx/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tlrx/elasticsearch/teams","hooks_url":"https://api.github.com/repos/tlrx/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/tlrx/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/tlrx/elasticsearch/events","assignees_url":"https://api.github.com/repos/tlrx/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/tlrx/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/tlrx/elasticsearch/tags","blobs_url":"https://api.github.com/repos/tlrx/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tlrx/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tlrx/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/tlrx/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tlrx/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/tlrx/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/tlrx/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/tlrx/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/tlrx/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/tlrx/elasticsearch/subscription","commits_url":"https://api.github.com/repos/tlrx/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/tlrx/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/tlrx/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/tlrx/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/tlrx/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/tlrx/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tlrx/elasticsearch/merges","archive_url":"https://api.github.com/repos/tlrx/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tlrx/elasticsearch/downloads","issues_url":"https://api.github.com/repos/tlrx/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/tlrx/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/tlrx/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/tlrx/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tlrx/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/tlrx/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/tlrx/elasticsearch/deployments","created_at":"2014-10-02T12:51:44Z","updated_at":"2014-10-02T08:42:36Z","pushed_at":"2017-05-16T15:09:54Z","git_url":"git://github.com/tlrx/elasticsearch.git","ssh_url":"git@github.com:tlrx/elasticsearch.git","clone_url":"https://github.com/tlrx/elasticsearch.git","svn_url":"https://github.com/tlrx/elasticsearch","homepage":"http://elasticsearch.org","size":260171,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:feature/client_aggs_parsing","ref":"feature/client_aggs_parsing","sha":"d5fc520741943c83cfac58b4f3289f65af233c6d","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars3.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars3.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/elasticsearch/deployments","created_at":"2010-02-08T13:20:56Z","updated_at":"2017-05-17T07:50:14Z","pushed_at":"2017-05-17T09:43:56Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":340968,"stargazers_count":22703,"watchers_count":22703,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7983,"mirror_url":null,"open_issues_count":1338,"forks":7983,"open_issues":1338,"watchers":22703,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/24706"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/24706"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/24706"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/24706/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/24706/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/24706/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/87518b5460ba12cd871b19855a541bcd4388ed60"}}}}
{"actor":{"display_login":"tlrx"}}