{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/comments/62323794","id":62323794,"diff_hunk":"@@ -0,0 +1,228 @@\n+/*\n+ * Copyright © 2016 Cask Data, Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n+ * use this file except in compliance with the License. You may obtain a copy of\n+ * 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, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n+ * License for the specific language governing permissions and limitations under\n+ * the License.\n+ */\n+\n+package co.cask.hydrator.plugin;\n+\n+import co.cask.cdap.api.annotation.Description;\n+import co.cask.cdap.api.annotation.Name;\n+import co.cask.cdap.api.annotation.Plugin;\n+import co.cask.cdap.api.data.format.StructuredRecord;\n+import co.cask.cdap.api.data.schema.Schema;\n+import co.cask.cdap.api.plugin.PluginConfig;\n+import co.cask.cdap.etl.api.Emitter;\n+import co.cask.cdap.etl.api.LookupConfig;\n+import co.cask.cdap.etl.api.LookupProvider;\n+import co.cask.cdap.etl.api.Transform;\n+import co.cask.cdap.etl.api.TransformContext;\n+import com.google.common.collect.Lists;\n+import com.google.common.collect.Maps;\n+import com.google.gson.Gson;\n+import com.google.gson.GsonBuilder;\n+import com.google.gson.JsonArray;\n+import com.google.gson.JsonElement;\n+import com.google.gson.JsonParser;\n+import com.google.gson.JsonSyntaxException;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.util.List;\n+import java.util.Map;\n+\n+/**\n+ * Transforms records using custom mapping provided by the config.\n+ */\n+@Plugin(type = \"transform\")\n+@Name(\"ValueMapper\")\n+@Description(\"Maps and convert record values from input sources using a mapping dataset\")\n+public class ValueMapper extends Transform<StructuredRecord, StructuredRecord> {\n+\n+  private static final Gson GSON = new GsonBuilder().create();\n+  private static final Logger LOG = LoggerFactory.getLogger(ValueMapper.class);\n+  private final Config config;\n+  private final Map<Schema, Schema> schemaCache = Maps.newHashMap();\n+  private final Map<String, String> fieldsMapping = Maps.newHashMap();\n+  private final Map<String, ValueMapperLookUp> datasetMapping =\n+          Maps.newHashMap();\n+  private JsonArray mappingArray;\n+\n+  // for unit tests, otherwise config is injected by plugin framework.\n+  public ValueMapper(Config config) {\n+    this.config = config;\n+  }\n+\n+  @Override\n+  public void transform(StructuredRecord input, Emitter<StructuredRecord> emitter) throws Exception {\n+    LOG.debug(\"in transform start :\" + input.get(\"name\"));\n+    Schema outputSchema = getOutputSchema(input.getSchema());\n+    StructuredRecord.Builder builder = createOutputRecords(input, outputSchema);\n+    StructuredRecord ss = builder.build();\n+    LOG.debug(\"in transform end :\" + ss.get(\"designationName\"));\n+    emitter.emit(ss);\n+  }\n+\n+  /**\n+   * Creates output structure record using mapping dataset and set them to builder.\n+   */\n+  private StructuredRecord.Builder createOutputRecords(StructuredRecord input, Schema outputSchema) {","path":"transform-plugins/src/main/java/co/cask/hydrator/plugin/ValueMapper.java","position":null,"original_position":79,"commit_id":"df088aab7cf67af287d8eea089ad88b4d4fbfd74","original_commit_id":"5e6e859dcc994f8f24d3b5c14434dbdfdd2be7dc","user":{"login":"romy-khetan","id":3714394,"avatar_url":"https://avatars.githubusercontent.com/u/3714394?v=3","gravatar_id":"","url":"https://api.github.com/users/romy-khetan","html_url":"https://github.com/romy-khetan","followers_url":"https://api.github.com/users/romy-khetan/followers","following_url":"https://api.github.com/users/romy-khetan/following{/other_user}","gists_url":"https://api.github.com/users/romy-khetan/gists{/gist_id}","starred_url":"https://api.github.com/users/romy-khetan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romy-khetan/subscriptions","organizations_url":"https://api.github.com/users/romy-khetan/orgs","repos_url":"https://api.github.com/users/romy-khetan/repos","events_url":"https://api.github.com/users/romy-khetan/events{/privacy}","received_events_url":"https://api.github.com/users/romy-khetan/received_events","type":"User","site_admin":false},"body":"Accepted and incorporated.","created_at":"2016-05-06T12:34:45Z","updated_at":"2016-05-06T12:34:45Z","html_url":"https://github.com/caskdata/hydrator-plugins/pull/250#discussion_r62323794","pull_request_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/250","_links":{"self":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/comments/62323794"},"html":{"href":"https://github.com/caskdata/hydrator-plugins/pull/250#discussion_r62323794"},"pull_request":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/250"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/250","id":69032275,"html_url":"https://github.com/caskdata/hydrator-plugins/pull/250","diff_url":"https://github.com/caskdata/hydrator-plugins/pull/250.diff","patch_url":"https://github.com/caskdata/hydrator-plugins/pull/250.patch","issue_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/250","number":250,"state":"open","locked":false,"title":"CDAP5878 - ValueMapper Plugin implemented. Initial draft.","user":{"login":"romy-khetan","id":3714394,"avatar_url":"https://avatars.githubusercontent.com/u/3714394?v=3","gravatar_id":"","url":"https://api.github.com/users/romy-khetan","html_url":"https://github.com/romy-khetan","followers_url":"https://api.github.com/users/romy-khetan/followers","following_url":"https://api.github.com/users/romy-khetan/following{/other_user}","gists_url":"https://api.github.com/users/romy-khetan/gists{/gist_id}","starred_url":"https://api.github.com/users/romy-khetan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romy-khetan/subscriptions","organizations_url":"https://api.github.com/users/romy-khetan/orgs","repos_url":"https://api.github.com/users/romy-khetan/repos","events_url":"https://api.github.com/users/romy-khetan/events{/privacy}","received_events_url":"https://api.github.com/users/romy-khetan/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-05T16:31:12Z","updated_at":"2016-05-06T12:34:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"69c5c49a24939787b68c955b86566386287d3f3d","assignee":null,"milestone":{"url":"https://api.github.com/repos/caskdata/hydrator-plugins/milestones/3","html_url":"https://github.com/caskdata/hydrator-plugins/milestones/3.4","labels_url":"https://api.github.com/repos/caskdata/hydrator-plugins/milestones/3/labels","id":1750160,"number":3,"title":"3.4","description":null,"creator":{"login":"nitinmotgi","id":1365919,"avatar_url":"https://avatars.githubusercontent.com/u/1365919?v=3","gravatar_id":"","url":"https://api.github.com/users/nitinmotgi","html_url":"https://github.com/nitinmotgi","followers_url":"https://api.github.com/users/nitinmotgi/followers","following_url":"https://api.github.com/users/nitinmotgi/following{/other_user}","gists_url":"https://api.github.com/users/nitinmotgi/gists{/gist_id}","starred_url":"https://api.github.com/users/nitinmotgi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nitinmotgi/subscriptions","organizations_url":"https://api.github.com/users/nitinmotgi/orgs","repos_url":"https://api.github.com/users/nitinmotgi/repos","events_url":"https://api.github.com/users/nitinmotgi/events{/privacy}","received_events_url":"https://api.github.com/users/nitinmotgi/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":0,"state":"open","created_at":"2016-05-05T18:00:57Z","updated_at":"2016-05-05T18:00:57Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/250/commits","review_comments_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/250/comments","review_comment_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/comments{/number}","comments_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/250/comments","statuses_url":"https://api.github.com/repos/caskdata/hydrator-plugins/statuses/df088aab7cf67af287d8eea089ad88b4d4fbfd74","head":{"label":"romy-khetan:develop","ref":"develop","sha":"df088aab7cf67af287d8eea089ad88b4d4fbfd74","user":{"login":"romy-khetan","id":3714394,"avatar_url":"https://avatars.githubusercontent.com/u/3714394?v=3","gravatar_id":"","url":"https://api.github.com/users/romy-khetan","html_url":"https://github.com/romy-khetan","followers_url":"https://api.github.com/users/romy-khetan/followers","following_url":"https://api.github.com/users/romy-khetan/following{/other_user}","gists_url":"https://api.github.com/users/romy-khetan/gists{/gist_id}","starred_url":"https://api.github.com/users/romy-khetan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romy-khetan/subscriptions","organizations_url":"https://api.github.com/users/romy-khetan/orgs","repos_url":"https://api.github.com/users/romy-khetan/repos","events_url":"https://api.github.com/users/romy-khetan/events{/privacy}","received_events_url":"https://api.github.com/users/romy-khetan/received_events","type":"User","site_admin":false},"repo":{"id":57360824,"name":"hydrator-plugins","full_name":"romy-khetan/hydrator-plugins","owner":{"login":"romy-khetan","id":3714394,"avatar_url":"https://avatars.githubusercontent.com/u/3714394?v=3","gravatar_id":"","url":"https://api.github.com/users/romy-khetan","html_url":"https://github.com/romy-khetan","followers_url":"https://api.github.com/users/romy-khetan/followers","following_url":"https://api.github.com/users/romy-khetan/following{/other_user}","gists_url":"https://api.github.com/users/romy-khetan/gists{/gist_id}","starred_url":"https://api.github.com/users/romy-khetan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romy-khetan/subscriptions","organizations_url":"https://api.github.com/users/romy-khetan/orgs","repos_url":"https://api.github.com/users/romy-khetan/repos","events_url":"https://api.github.com/users/romy-khetan/events{/privacy}","received_events_url":"https://api.github.com/users/romy-khetan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/romy-khetan/hydrator-plugins","description":"Cask Hydrator Plugins Repository","fork":true,"url":"https://api.github.com/repos/romy-khetan/hydrator-plugins","forks_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/forks","keys_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/teams","hooks_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/hooks","issue_events_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/issues/events{/number}","events_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/events","assignees_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/assignees{/user}","branches_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/branches{/branch}","tags_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/tags","blobs_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/languages","stargazers_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/stargazers","contributors_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/contributors","subscribers_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/subscribers","subscription_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/subscription","commits_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/contents/{+path}","compare_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/merges","archive_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/downloads","issues_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/issues{/number}","pulls_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/labels{/name}","releases_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/releases{/id}","deployments_url":"https://api.github.com/repos/romy-khetan/hydrator-plugins/deployments","created_at":"2016-04-29T06:37:39Z","updated_at":"2016-04-29T06:37:42Z","pushed_at":"2016-05-06T11:36:48Z","git_url":"git://github.com/romy-khetan/hydrator-plugins.git","ssh_url":"git@github.com:romy-khetan/hydrator-plugins.git","clone_url":"https://github.com/romy-khetan/hydrator-plugins.git","svn_url":"https://github.com/romy-khetan/hydrator-plugins","homepage":"","size":2071,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"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":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"e20aa35cfc1bf20ae49d4c97e8e7dae22414144d","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":39922362,"name":"hydrator-plugins","full_name":"caskdata/hydrator-plugins","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/hydrator-plugins","description":"Cask Hydrator Plugins Repository","fork":false,"url":"https://api.github.com/repos/caskdata/hydrator-plugins","forks_url":"https://api.github.com/repos/caskdata/hydrator-plugins/forks","keys_url":"https://api.github.com/repos/caskdata/hydrator-plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/hydrator-plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/hydrator-plugins/teams","hooks_url":"https://api.github.com/repos/caskdata/hydrator-plugins/hooks","issue_events_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/hydrator-plugins/events","assignees_url":"https://api.github.com/repos/caskdata/hydrator-plugins/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/hydrator-plugins/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/hydrator-plugins/tags","blobs_url":"https://api.github.com/repos/caskdata/hydrator-plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/hydrator-plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/hydrator-plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/hydrator-plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/hydrator-plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/hydrator-plugins/languages","stargazers_url":"https://api.github.com/repos/caskdata/hydrator-plugins/stargazers","contributors_url":"https://api.github.com/repos/caskdata/hydrator-plugins/contributors","subscribers_url":"https://api.github.com/repos/caskdata/hydrator-plugins/subscribers","subscription_url":"https://api.github.com/repos/caskdata/hydrator-plugins/subscription","commits_url":"https://api.github.com/repos/caskdata/hydrator-plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/hydrator-plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/hydrator-plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/caskdata/hydrator-plugins/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/hydrator-plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/hydrator-plugins/merges","archive_url":"https://api.github.com/repos/caskdata/hydrator-plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/hydrator-plugins/downloads","issues_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/hydrator-plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/hydrator-plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/hydrator-plugins/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/hydrator-plugins/releases{/id}","deployments_url":"https://api.github.com/repos/caskdata/hydrator-plugins/deployments","created_at":"2015-07-30T00:14:48Z","updated_at":"2016-05-05T02:47:34Z","pushed_at":"2016-05-06T11:36:49Z","git_url":"git://github.com/caskdata/hydrator-plugins.git","ssh_url":"git@github.com:caskdata/hydrator-plugins.git","clone_url":"https://github.com/caskdata/hydrator-plugins.git","svn_url":"https://github.com/caskdata/hydrator-plugins","homepage":"","size":2103,"stargazers_count":8,"watchers_count":8,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":5,"forks":10,"open_issues":5,"watchers":8,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/250"},"html":{"href":"https://github.com/caskdata/hydrator-plugins/pull/250"},"issue":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/250"},"comments":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/250/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/250/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/250/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/statuses/df088aab7cf67af287d8eea089ad88b4d4fbfd74"}}}}