{"action":"created","comment":{"url":"https://api.github.com/repos/druid-io/druid/pulls/comments/83581030","pull_request_review_id":4415111,"id":83581030,"diff_hunk":"@@ -0,0 +1,195 @@\n+/*\n+ * Licensed to Metamarkets Group Inc. (Metamarkets) under one\n+ * or more contributor license agreements. See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership. Metamarkets licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License. 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 io.druid.query.aggregation.post;\n+\n+import com.fasterxml.jackson.annotation.JsonCreator;\n+import com.fasterxml.jackson.annotation.JsonProperty;\n+import com.google.common.base.Preconditions;\n+import com.google.common.collect.Sets;\n+import io.druid.math.expr.Expr;\n+import io.druid.math.expr.Parser;\n+import io.druid.query.aggregation.PostAggregator;\n+\n+import java.util.Comparator;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Objects;\n+import java.util.Set;\n+\n+/**\n+ */\n+public class ExpressionPostAggregator implements PostAggregator\n+{\n+  private static final Comparator<Number> DEFAULT_COMPARATOR = new Comparator<Number>()\n+  {\n+    @Override\n+    public int compare(Number o1, Number o2)\n+    {\n+      if (o1 instanceof Long && o2 instanceof Long) {\n+        return Long.compare(o1.longValue(), o2.longValue());\n+      }\n+      return Double.compare(o1.doubleValue(), o2.doubleValue());\n+    }\n+  };\n+\n+  private final String name;\n+  private final String expression;\n+  private final Comparator comparator;\n+  private final String ordering;\n+\n+  private final Expr parsed;\n+  private final List<String> dependentFields;\n+\n+  @JsonCreator\n+  public ExpressionPostAggregator(\n+      @JsonProperty(\"name\") String name,\n+      @JsonProperty(\"expression\") String expression,\n+      @JsonProperty(\"ordering\") String ordering\n+  )\n+  {\n+    Preconditions.checkArgument(expression != null, \"expression cannot be null\");\n+\n+    this.name = name;\n+    this.expression = expression;\n+    this.ordering = ordering;\n+    this.comparator = ordering == null ? DEFAULT_COMPARATOR : Ordering.valueOf(ordering);\n+\n+    this.parsed = Parser.parse(expression);\n+    this.dependentFields = Parser.findRequiredBindings(parsed);\n+  }\n+\n+  public ExpressionPostAggregator(String name, String fnName)\n+  {\n+    this(name, fnName, null);\n+  }\n+\n+  @Override\n+  public Set<String> getDependentFields()\n+  {\n+    return Sets.newHashSet(dependentFields);\n+  }\n+\n+  @Override\n+  public Comparator getComparator()\n+  {\n+    return comparator;\n+  }\n+\n+  @Override\n+  public Object compute(Map<String, Object> values)\n+  {\n+    return parsed.eval(Parser.withMap(values));\n+  }\n+\n+  @Override\n+  @JsonProperty\n+  public String getName()\n+  {\n+    return name;\n+  }\n+\n+  @JsonProperty(\"expression\")\n+  public String getExpression()\n+  {\n+    return expression;\n+  }\n+\n+  @JsonProperty(\"ordering\")\n+  public String getOrdering()\n+  {\n+    return ordering;\n+  }\n+\n+  @Override\n+  public String toString()\n+  {\n+    return \"ExpressionPostAggregator{\" +\n+           \"name='\" + name + '\\'' +\n+           \", expression='\" + expression + '\\'' +\n+           \", ordering=\" + ordering +\n+           '}';\n+  }\n+\n+  public static enum Ordering implements Comparator<Number>\n+  {\n+    // ensures the following order: numeric > NaN > Infinite","path":"processing/src/main/java/io/druid/query/aggregation/post/ExpressionPostAggregator.java","position":132,"original_position":132,"commit_id":"a450350ed2f45c7147a9b77688adb2839ac83fd3","original_commit_id":"a450350ed2f45c7147a9b77688adb2839ac83fd3","user":{"login":"gianm","id":1214075,"avatar_url":"https://avatars.githubusercontent.com/u/1214075?v=3","gravatar_id":"","url":"https://api.github.com/users/gianm","html_url":"https://github.com/gianm","followers_url":"https://api.github.com/users/gianm/followers","following_url":"https://api.github.com/users/gianm/following{/other_user}","gists_url":"https://api.github.com/users/gianm/gists{/gist_id}","starred_url":"https://api.github.com/users/gianm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gianm/subscriptions","organizations_url":"https://api.github.com/users/gianm/orgs","repos_url":"https://api.github.com/users/gianm/repos","events_url":"https://api.github.com/users/gianm/events{/privacy}","received_events_url":"https://api.github.com/users/gianm/received_events","type":"User","site_admin":false},"body":"The default is Long.compare / Double.compare, this code only gets used if you say `\"ordering\" : \"numericFirst\"`. So I think that's okay.","created_at":"2016-10-17T05:54:32Z","updated_at":"2016-10-17T05:54:32Z","html_url":"https://github.com/druid-io/druid/pull/2783#discussion_r83581030","pull_request_url":"https://api.github.com/repos/druid-io/druid/pulls/2783","_links":{"self":{"href":"https://api.github.com/repos/druid-io/druid/pulls/comments/83581030"},"html":{"href":"https://github.com/druid-io/druid/pull/2783#discussion_r83581030"},"pull_request":{"href":"https://api.github.com/repos/druid-io/druid/pulls/2783"}}},"pull_request":{"url":"https://api.github.com/repos/druid-io/druid/pulls/2783","id":65110227,"html_url":"https://github.com/druid-io/druid/pull/2783","diff_url":"https://github.com/druid-io/druid/pull/2783.diff","patch_url":"https://github.com/druid-io/druid/pull/2783.patch","issue_url":"https://api.github.com/repos/druid-io/druid/issues/2783","number":2783,"state":"open","locked":false,"title":"Math expressional parameters for aggregator","user":{"login":"navis","id":809395,"avatar_url":"https://avatars.githubusercontent.com/u/809395?v=3","gravatar_id":"","url":"https://api.github.com/users/navis","html_url":"https://github.com/navis","followers_url":"https://api.github.com/users/navis/followers","following_url":"https://api.github.com/users/navis/following{/other_user}","gists_url":"https://api.github.com/users/navis/gists{/gist_id}","starred_url":"https://api.github.com/users/navis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/navis/subscriptions","organizations_url":"https://api.github.com/users/navis/orgs","repos_url":"https://api.github.com/users/navis/repos","events_url":"https://api.github.com/users/navis/events{/privacy}","received_events_url":"https://api.github.com/users/navis/received_events","type":"User","site_admin":false},"body":"Someone wanted druid to support expressional parameter for aggregator something like `sum(a + b / c)`. I don't know why it's needed either but this is it. Will make propose in dev mailing list soon after. \r\n\r\nBased on great work(#2090) of @himanshug.","created_at":"2016-04-04T08:29:14Z","updated_at":"2016-10-17T05:54:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"988dd7359b16eb56299c6fc13a3b88cea478c93f","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/druid-io/druid/milestones/21","html_url":"https://github.com/druid-io/druid/milestones/0.9.3","labels_url":"https://api.github.com/repos/druid-io/druid/milestones/21/labels","id":1831000,"number":21,"title":"0.9.3","description":"","creator":{"login":"fjy","id":428325,"avatar_url":"https://avatars.githubusercontent.com/u/428325?v=3","gravatar_id":"","url":"https://api.github.com/users/fjy","html_url":"https://github.com/fjy","followers_url":"https://api.github.com/users/fjy/followers","following_url":"https://api.github.com/users/fjy/following{/other_user}","gists_url":"https://api.github.com/users/fjy/gists{/gist_id}","starred_url":"https://api.github.com/users/fjy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fjy/subscriptions","organizations_url":"https://api.github.com/users/fjy/orgs","repos_url":"https://api.github.com/users/fjy/repos","events_url":"https://api.github.com/users/fjy/events{/privacy}","received_events_url":"https://api.github.com/users/fjy/received_events","type":"User","site_admin":false},"open_issues":47,"closed_issues":16,"state":"open","created_at":"2016-06-15T22:35:58Z","updated_at":"2016-10-15T04:13:23Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/druid-io/druid/pulls/2783/commits","review_comments_url":"https://api.github.com/repos/druid-io/druid/pulls/2783/comments","review_comment_url":"https://api.github.com/repos/druid-io/druid/pulls/comments{/number}","comments_url":"https://api.github.com/repos/druid-io/druid/issues/2783/comments","statuses_url":"https://api.github.com/repos/druid-io/druid/statuses/a450350ed2f45c7147a9b77688adb2839ac83fd3","head":{"label":"navis:expression-paramed-aggregator","ref":"expression-paramed-aggregator","sha":"a450350ed2f45c7147a9b77688adb2839ac83fd3","user":{"login":"navis","id":809395,"avatar_url":"https://avatars.githubusercontent.com/u/809395?v=3","gravatar_id":"","url":"https://api.github.com/users/navis","html_url":"https://github.com/navis","followers_url":"https://api.github.com/users/navis/followers","following_url":"https://api.github.com/users/navis/following{/other_user}","gists_url":"https://api.github.com/users/navis/gists{/gist_id}","starred_url":"https://api.github.com/users/navis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/navis/subscriptions","organizations_url":"https://api.github.com/users/navis/orgs","repos_url":"https://api.github.com/users/navis/repos","events_url":"https://api.github.com/users/navis/events{/privacy}","received_events_url":"https://api.github.com/users/navis/received_events","type":"User","site_admin":false},"repo":{"id":45149930,"name":"druid","full_name":"navis/druid","owner":{"login":"navis","id":809395,"avatar_url":"https://avatars.githubusercontent.com/u/809395?v=3","gravatar_id":"","url":"https://api.github.com/users/navis","html_url":"https://github.com/navis","followers_url":"https://api.github.com/users/navis/followers","following_url":"https://api.github.com/users/navis/following{/other_user}","gists_url":"https://api.github.com/users/navis/gists{/gist_id}","starred_url":"https://api.github.com/users/navis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/navis/subscriptions","organizations_url":"https://api.github.com/users/navis/orgs","repos_url":"https://api.github.com/users/navis/repos","events_url":"https://api.github.com/users/navis/events{/privacy}","received_events_url":"https://api.github.com/users/navis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/navis/druid","description":"Column oriented distributed data store ideal for powering interactive applications","fork":true,"url":"https://api.github.com/repos/navis/druid","forks_url":"https://api.github.com/repos/navis/druid/forks","keys_url":"https://api.github.com/repos/navis/druid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/navis/druid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/navis/druid/teams","hooks_url":"https://api.github.com/repos/navis/druid/hooks","issue_events_url":"https://api.github.com/repos/navis/druid/issues/events{/number}","events_url":"https://api.github.com/repos/navis/druid/events","assignees_url":"https://api.github.com/repos/navis/druid/assignees{/user}","branches_url":"https://api.github.com/repos/navis/druid/branches{/branch}","tags_url":"https://api.github.com/repos/navis/druid/tags","blobs_url":"https://api.github.com/repos/navis/druid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/navis/druid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/navis/druid/git/refs{/sha}","trees_url":"https://api.github.com/repos/navis/druid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/navis/druid/statuses/{sha}","languages_url":"https://api.github.com/repos/navis/druid/languages","stargazers_url":"https://api.github.com/repos/navis/druid/stargazers","contributors_url":"https://api.github.com/repos/navis/druid/contributors","subscribers_url":"https://api.github.com/repos/navis/druid/subscribers","subscription_url":"https://api.github.com/repos/navis/druid/subscription","commits_url":"https://api.github.com/repos/navis/druid/commits{/sha}","git_commits_url":"https://api.github.com/repos/navis/druid/git/commits{/sha}","comments_url":"https://api.github.com/repos/navis/druid/comments{/number}","issue_comment_url":"https://api.github.com/repos/navis/druid/issues/comments{/number}","contents_url":"https://api.github.com/repos/navis/druid/contents/{+path}","compare_url":"https://api.github.com/repos/navis/druid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/navis/druid/merges","archive_url":"https://api.github.com/repos/navis/druid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/navis/druid/downloads","issues_url":"https://api.github.com/repos/navis/druid/issues{/number}","pulls_url":"https://api.github.com/repos/navis/druid/pulls{/number}","milestones_url":"https://api.github.com/repos/navis/druid/milestones{/number}","notifications_url":"https://api.github.com/repos/navis/druid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/navis/druid/labels{/name}","releases_url":"https://api.github.com/repos/navis/druid/releases{/id}","deployments_url":"https://api.github.com/repos/navis/druid/deployments","created_at":"2015-10-29T00:22:35Z","updated_at":"2015-10-29T00:22:47Z","pushed_at":"2016-10-13T01:13:56Z","git_url":"git://github.com/navis/druid.git","ssh_url":"git@github.com:navis/druid.git","clone_url":"https://github.com/navis/druid.git","svn_url":"https://github.com/navis/druid","homepage":"http://druid.io","size":110089,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"druid-io:master","ref":"master","sha":"3a83e0513e1b1b7dfb43b285afc5cf89ae418a53","user":{"login":"druid-io","id":4203474,"avatar_url":"https://avatars.githubusercontent.com/u/4203474?v=3","gravatar_id":"","url":"https://api.github.com/users/druid-io","html_url":"https://github.com/druid-io","followers_url":"https://api.github.com/users/druid-io/followers","following_url":"https://api.github.com/users/druid-io/following{/other_user}","gists_url":"https://api.github.com/users/druid-io/gists{/gist_id}","starred_url":"https://api.github.com/users/druid-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/druid-io/subscriptions","organizations_url":"https://api.github.com/users/druid-io/orgs","repos_url":"https://api.github.com/users/druid-io/repos","events_url":"https://api.github.com/users/druid-io/events{/privacy}","received_events_url":"https://api.github.com/users/druid-io/received_events","type":"Organization","site_admin":false},"repo":{"id":6358188,"name":"druid","full_name":"druid-io/druid","owner":{"login":"druid-io","id":4203474,"avatar_url":"https://avatars.githubusercontent.com/u/4203474?v=3","gravatar_id":"","url":"https://api.github.com/users/druid-io","html_url":"https://github.com/druid-io","followers_url":"https://api.github.com/users/druid-io/followers","following_url":"https://api.github.com/users/druid-io/following{/other_user}","gists_url":"https://api.github.com/users/druid-io/gists{/gist_id}","starred_url":"https://api.github.com/users/druid-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/druid-io/subscriptions","organizations_url":"https://api.github.com/users/druid-io/orgs","repos_url":"https://api.github.com/users/druid-io/repos","events_url":"https://api.github.com/users/druid-io/events{/privacy}","received_events_url":"https://api.github.com/users/druid-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/druid-io/druid","description":"Column oriented distributed data store ideal for powering interactive applications","fork":false,"url":"https://api.github.com/repos/druid-io/druid","forks_url":"https://api.github.com/repos/druid-io/druid/forks","keys_url":"https://api.github.com/repos/druid-io/druid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/druid-io/druid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/druid-io/druid/teams","hooks_url":"https://api.github.com/repos/druid-io/druid/hooks","issue_events_url":"https://api.github.com/repos/druid-io/druid/issues/events{/number}","events_url":"https://api.github.com/repos/druid-io/druid/events","assignees_url":"https://api.github.com/repos/druid-io/druid/assignees{/user}","branches_url":"https://api.github.com/repos/druid-io/druid/branches{/branch}","tags_url":"https://api.github.com/repos/druid-io/druid/tags","blobs_url":"https://api.github.com/repos/druid-io/druid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/druid-io/druid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/druid-io/druid/git/refs{/sha}","trees_url":"https://api.github.com/repos/druid-io/druid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/druid-io/druid/statuses/{sha}","languages_url":"https://api.github.com/repos/druid-io/druid/languages","stargazers_url":"https://api.github.com/repos/druid-io/druid/stargazers","contributors_url":"https://api.github.com/repos/druid-io/druid/contributors","subscribers_url":"https://api.github.com/repos/druid-io/druid/subscribers","subscription_url":"https://api.github.com/repos/druid-io/druid/subscription","commits_url":"https://api.github.com/repos/druid-io/druid/commits{/sha}","git_commits_url":"https://api.github.com/repos/druid-io/druid/git/commits{/sha}","comments_url":"https://api.github.com/repos/druid-io/druid/comments{/number}","issue_comment_url":"https://api.github.com/repos/druid-io/druid/issues/comments{/number}","contents_url":"https://api.github.com/repos/druid-io/druid/contents/{+path}","compare_url":"https://api.github.com/repos/druid-io/druid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/druid-io/druid/merges","archive_url":"https://api.github.com/repos/druid-io/druid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/druid-io/druid/downloads","issues_url":"https://api.github.com/repos/druid-io/druid/issues{/number}","pulls_url":"https://api.github.com/repos/druid-io/druid/pulls{/number}","milestones_url":"https://api.github.com/repos/druid-io/druid/milestones{/number}","notifications_url":"https://api.github.com/repos/druid-io/druid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/druid-io/druid/labels{/name}","releases_url":"https://api.github.com/repos/druid-io/druid/releases{/id}","deployments_url":"https://api.github.com/repos/druid-io/druid/deployments","created_at":"2012-10-23T19:08:07Z","updated_at":"2016-10-17T02:57:02Z","pushed_at":"2016-10-16T00:45:31Z","git_url":"git://github.com/druid-io/druid.git","ssh_url":"git@github.com:druid-io/druid.git","clone_url":"https://github.com/druid-io/druid.git","svn_url":"https://github.com/druid-io/druid","homepage":"http://druid.io","size":157261,"stargazers_count":3825,"watchers_count":3825,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":899,"mirror_url":null,"open_issues_count":552,"forks":899,"open_issues":552,"watchers":3825,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/druid-io/druid/pulls/2783"},"html":{"href":"https://github.com/druid-io/druid/pull/2783"},"issue":{"href":"https://api.github.com/repos/druid-io/druid/issues/2783"},"comments":{"href":"https://api.github.com/repos/druid-io/druid/issues/2783/comments"},"review_comments":{"href":"https://api.github.com/repos/druid-io/druid/pulls/2783/comments"},"review_comment":{"href":"https://api.github.com/repos/druid-io/druid/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/druid-io/druid/pulls/2783/commits"},"statuses":{"href":"https://api.github.com/repos/druid-io/druid/statuses/a450350ed2f45c7147a9b77688adb2839ac83fd3"}}}}
{"actor":{"display_login":"gianm"}}