{"action":"created","comment":{"url":"https://api.github.com/repos/druid-io/druid/pulls/comments/31272975","id":31272975,"diff_hunk":"@@ -0,0 +1,118 @@\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.extraction;\n+\n+import com.google.common.base.Function;\n+import com.google.common.base.Preconditions;\n+import com.google.common.base.Strings;\n+\n+import javax.annotation.Nullable;\n+\n+/**\n+ * Functional extraction uses a function to find the new value.\n+ * null values in the range can either retain the domain's value, or replace the null value with \"replaceMissingValueWith\"\n+ */\n+public abstract class FunctionalExtraction extends DimExtractionFn\n+{\n+  private final boolean retainMissingValue;\n+  private final String replaceMissingValueWith;\n+  private final Function<String, String> extractionFunction;\n+  private final ExtractionType extractionType;\n+\n+  /**\n+   * The general constructor which handles most of the logic for extractions which can be expressed as a function of string-->string\n+   *\n+   * @param extractionFunction      The function to call when doing the extraction. The function must be able to accept a null input.\n+   * @param retainMissingValue      Boolean value on if functions which result in `null` should use the original value or should be kept as `null`\n+   * @param replaceMissingValueWith String value to replace missing values with (instead of `null`)\n+   * @param injective               If this function always has 1:1 renames and the domain has the same cardinality of the input, this should be true and enables optimized query paths.\n+   */\n+  public FunctionalExtraction(\n+      final Function<String, String> extractionFunction,\n+      final boolean retainMissingValue,\n+      final String replaceMissingValueWith,\n+      final boolean injective\n+  )\n+  {\n+    this.retainMissingValue = retainMissingValue;\n+    this.replaceMissingValueWith = Strings.emptyToNull(replaceMissingValueWith);\n+    Preconditions.checkArgument(\n+        !(this.retainMissingValue && !Strings.isNullOrEmpty(this.replaceMissingValueWith)),\n+        \"Cannot specify a [replaceMissingValueWith] and set [retainMissingValue] to true\"\n+    );\n+\n+    // If missing values are to be retained, we have a slightly different code path\n+    // This is intended to have the absolutely fastest code path possible and not have any extra logic in the function\n+    if (this.retainMissingValue) {\n+\n+      this.extractionFunction = new Function<String, String>()\n+      {\n+        @Nullable\n+        @Override\n+        public String apply(@Nullable String dimValue)\n+        {\n+          final String retval = extractionFunction.apply(dimValue);\n+          return Strings.isNullOrEmpty(retval) ? Strings.emptyToNull(dimValue) : retval;\n+        }\n+      };\n+    } else {\n+      this.extractionFunction = new Function<String, String>()\n+      {\n+        @Nullable\n+        @Override\n+        public String apply(@Nullable String dimValue)\n+        {\n+          final String retval = extractionFunction.apply(dimValue);\n+          return Strings.isNullOrEmpty(retval) ? FunctionalExtraction.this.replaceMissingValueWith : retval;\n+        }\n+      };\n+    }\n+    this.extractionType = injective\n+                          ? ExtractionType.ONE_TO_ONE\n+                          : ExtractionType.MANY_TO_ONE;\n+  }\n+\n+  public boolean isRetainMissingValue() {return retainMissingValue;}","path":"processing/src/main/java/io/druid/query/extraction/FunctionalExtraction.java","position":92,"original_position":92,"commit_id":"088659f765203398412b6ccd9f843fbf892c0a55","original_commit_id":"088659f765203398412b6ccd9f843fbf892c0a55","user":{"login":"drcrallen","id":8213081,"avatar_url":"https://avatars.githubusercontent.com/u/8213081?v=3","gravatar_id":"","url":"https://api.github.com/users/drcrallen","html_url":"https://github.com/drcrallen","followers_url":"https://api.github.com/users/drcrallen/followers","following_url":"https://api.github.com/users/drcrallen/following{/other_user}","gists_url":"https://api.github.com/users/drcrallen/gists{/gist_id}","starred_url":"https://api.github.com/users/drcrallen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drcrallen/subscriptions","organizations_url":"https://api.github.com/users/drcrallen/orgs","repos_url":"https://api.github.com/users/drcrallen/repos","events_url":"https://api.github.com/users/drcrallen/events{/privacy}","received_events_url":"https://api.github.com/users/drcrallen/received_events","type":"User","site_admin":false},"body":"That's really weird, intellij formatting sees that as completely in spec","created_at":"2015-05-28T20:15:37Z","updated_at":"2015-05-28T20:15:37Z","html_url":"https://github.com/druid-io/druid/pull/1370#discussion_r31272975","pull_request_url":"https://api.github.com/repos/druid-io/druid/pulls/1370","_links":{"self":{"href":"https://api.github.com/repos/druid-io/druid/pulls/comments/31272975"},"html":{"href":"https://github.com/druid-io/druid/pull/1370#discussion_r31272975"},"pull_request":{"href":"https://api.github.com/repos/druid-io/druid/pulls/1370"}}},"pull_request":{"url":"https://api.github.com/repos/druid-io/druid/pulls/1370","id":35538198,"html_url":"https://github.com/druid-io/druid/pull/1370","diff_url":"https://github.com/druid-io/druid/pull/1370.diff","patch_url":"https://github.com/druid-io/druid/pull/1370.patch","issue_url":"https://api.github.com/repos/druid-io/druid/issues/1370","number":1370,"state":"open","locked":false,"title":"Add optimizations for ExtractionFn by enabling MANY_TO_ONE vs ONE_TO_ONE codepaths","user":{"login":"drcrallen","id":8213081,"avatar_url":"https://avatars.githubusercontent.com/u/8213081?v=3","gravatar_id":"","url":"https://api.github.com/users/drcrallen","html_url":"https://github.com/drcrallen","followers_url":"https://api.github.com/users/drcrallen/followers","following_url":"https://api.github.com/users/drcrallen/following{/other_user}","gists_url":"https://api.github.com/users/drcrallen/gists{/gist_id}","starred_url":"https://api.github.com/users/drcrallen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drcrallen/subscriptions","organizations_url":"https://api.github.com/users/drcrallen/orgs","repos_url":"https://api.github.com/users/drcrallen/repos","events_url":"https://api.github.com/users/drcrallen/events{/privacy}","received_events_url":"https://api.github.com/users/drcrallen/received_events","type":"User","site_admin":false},"body":"* Also adds ExplicitDimRenameFn which takes in an explicit mapping of renames\r\n\r\n\r\nThis is a fork of the improvements in the QTL branch to try and make them smaller overall patches","created_at":"2015-05-15T18:26:59Z","updated_at":"2015-05-28T20:15:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6c401c7cdab7ddfbb72d7bfa4d09766f81aab699","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/druid-io/druid/pulls/1370/commits","review_comments_url":"https://api.github.com/repos/druid-io/druid/pulls/1370/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/1370/comments","statuses_url":"https://api.github.com/repos/druid-io/druid/statuses/088659f765203398412b6ccd9f843fbf892c0a55","head":{"label":"metamx:dimExtractionOptimizations","ref":"dimExtractionOptimizations","sha":"088659f765203398412b6ccd9f843fbf892c0a55","user":{"login":"metamx","id":299329,"avatar_url":"https://avatars.githubusercontent.com/u/299329?v=3","gravatar_id":"","url":"https://api.github.com/users/metamx","html_url":"https://github.com/metamx","followers_url":"https://api.github.com/users/metamx/followers","following_url":"https://api.github.com/users/metamx/following{/other_user}","gists_url":"https://api.github.com/users/metamx/gists{/gist_id}","starred_url":"https://api.github.com/users/metamx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metamx/subscriptions","organizations_url":"https://api.github.com/users/metamx/orgs","repos_url":"https://api.github.com/users/metamx/repos","events_url":"https://api.github.com/users/metamx/events{/privacy}","received_events_url":"https://api.github.com/users/metamx/received_events","type":"Organization","site_admin":false},"repo":{"id":28248872,"name":"druid","full_name":"metamx/druid","owner":{"login":"metamx","id":299329,"avatar_url":"https://avatars.githubusercontent.com/u/299329?v=3","gravatar_id":"","url":"https://api.github.com/users/metamx","html_url":"https://github.com/metamx","followers_url":"https://api.github.com/users/metamx/followers","following_url":"https://api.github.com/users/metamx/following{/other_user}","gists_url":"https://api.github.com/users/metamx/gists{/gist_id}","starred_url":"https://api.github.com/users/metamx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metamx/subscriptions","organizations_url":"https://api.github.com/users/metamx/orgs","repos_url":"https://api.github.com/users/metamx/repos","events_url":"https://api.github.com/users/metamx/events{/privacy}","received_events_url":"https://api.github.com/users/metamx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/metamx/druid","description":"Real²time Exploratory Analytics on Large Datasets","fork":true,"url":"https://api.github.com/repos/metamx/druid","forks_url":"https://api.github.com/repos/metamx/druid/forks","keys_url":"https://api.github.com/repos/metamx/druid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/metamx/druid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/metamx/druid/teams","hooks_url":"https://api.github.com/repos/metamx/druid/hooks","issue_events_url":"https://api.github.com/repos/metamx/druid/issues/events{/number}","events_url":"https://api.github.com/repos/metamx/druid/events","assignees_url":"https://api.github.com/repos/metamx/druid/assignees{/user}","branches_url":"https://api.github.com/repos/metamx/druid/branches{/branch}","tags_url":"https://api.github.com/repos/metamx/druid/tags","blobs_url":"https://api.github.com/repos/metamx/druid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/metamx/druid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/metamx/druid/git/refs{/sha}","trees_url":"https://api.github.com/repos/metamx/druid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/metamx/druid/statuses/{sha}","languages_url":"https://api.github.com/repos/metamx/druid/languages","stargazers_url":"https://api.github.com/repos/metamx/druid/stargazers","contributors_url":"https://api.github.com/repos/metamx/druid/contributors","subscribers_url":"https://api.github.com/repos/metamx/druid/subscribers","subscription_url":"https://api.github.com/repos/metamx/druid/subscription","commits_url":"https://api.github.com/repos/metamx/druid/commits{/sha}","git_commits_url":"https://api.github.com/repos/metamx/druid/git/commits{/sha}","comments_url":"https://api.github.com/repos/metamx/druid/comments{/number}","issue_comment_url":"https://api.github.com/repos/metamx/druid/issues/comments{/number}","contents_url":"https://api.github.com/repos/metamx/druid/contents/{+path}","compare_url":"https://api.github.com/repos/metamx/druid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/metamx/druid/merges","archive_url":"https://api.github.com/repos/metamx/druid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/metamx/druid/downloads","issues_url":"https://api.github.com/repos/metamx/druid/issues{/number}","pulls_url":"https://api.github.com/repos/metamx/druid/pulls{/number}","milestones_url":"https://api.github.com/repos/metamx/druid/milestones{/number}","notifications_url":"https://api.github.com/repos/metamx/druid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/metamx/druid/labels{/name}","releases_url":"https://api.github.com/repos/metamx/druid/releases{/id}","created_at":"2014-12-19T22:30:25Z","updated_at":"2015-05-18T19:15:03Z","pushed_at":"2015-05-28T18:16:12Z","git_url":"git://github.com/metamx/druid.git","ssh_url":"git@github.com:metamx/druid.git","clone_url":"https://github.com/metamx/druid.git","svn_url":"https://github.com/metamx/druid","homepage":"http://druid.io","size":144357,"stargazers_count":25,"watchers_count":25,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":0,"forks":11,"open_issues":0,"watchers":25,"default_branch":"master"}},"base":{"label":"druid-io:master","ref":"master","sha":"f588a95f36f42dc86179dee2cabf7d0075141520","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":"Real²time Exploratory Analytics on Large Datasets","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}","created_at":"2012-10-23T19:08:07Z","updated_at":"2015-05-28T12:25:51Z","pushed_at":"2015-05-28T18:04:06Z","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":174506,"stargazers_count":1750,"watchers_count":1750,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":380,"mirror_url":null,"open_issues_count":146,"forks":380,"open_issues":146,"watchers":1750,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/druid-io/druid/pulls/1370"},"html":{"href":"https://github.com/druid-io/druid/pull/1370"},"issue":{"href":"https://api.github.com/repos/druid-io/druid/issues/1370"},"comments":{"href":"https://api.github.com/repos/druid-io/druid/issues/1370/comments"},"review_comments":{"href":"https://api.github.com/repos/druid-io/druid/pulls/1370/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/1370/commits"},"statuses":{"href":"https://api.github.com/repos/druid-io/druid/statuses/088659f765203398412b6ccd9f843fbf892c0a55"}}}}