{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/comments/43835717","id":43835717,"diff_hunk":"@@ -0,0 +1,119 @@\n+/*\n+ * Copyright © 2015 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.plugin.etl.batch.source;\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.dataset.DatasetProperties;\n+import co.cask.cdap.api.dataset.lib.KeyValue;\n+import co.cask.cdap.api.dataset.lib.KeyValueTable;\n+import co.cask.cdap.etl.api.Emitter;\n+import co.cask.cdap.etl.api.PipelineConfigurer;\n+import co.cask.cdap.etl.api.batch.BatchRuntimeContext;\n+import co.cask.cdap.etl.api.batch.BatchSource;\n+import co.cask.cdap.etl.api.batch.BatchSourceContext;\n+import co.cask.plugin.etl.batch.commons.HiveSchemaConverter;\n+import co.cask.plugin.etl.batch.commons.HiveSchemaStore;\n+import com.google.common.base.Objects;\n+import org.apache.hadoop.conf.Configuration;\n+import org.apache.hadoop.io.WritableComparable;\n+import org.apache.hadoop.mapreduce.Job;\n+import org.apache.hadoop.util.VersionInfo;\n+import org.apache.hive.hcatalog.data.HCatRecord;\n+import org.apache.hive.hcatalog.data.schema.HCatSchema;\n+import org.apache.hive.hcatalog.mapreduce.HCatInputFormat;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+\n+/**\n+ * Batch source for Hive.\n+ */\n+@Plugin(type = \"batchsource\")\n+@Name(\"Hive\")\n+@Description(\"Batch source to read from external Hive table\")\n+public class HiveBatchSource extends BatchSource<WritableComparable, HCatRecord, StructuredRecord> {\n+\n+  private static final Logger LOG = LoggerFactory.getLogger(HiveBatchSource.class);\n+\n+  private static final String DEFAULT_HIVE_DATABASE = \"default\";\n+\n+  private HiveSourceConfig config;\n+  private HCatRecordTransformer hCatRecordTransformer;\n+\n+  @Override\n+  public void configurePipeline(PipelineConfigurer pipelineConfigurer) {\n+    //TODO: remove this way of storing Hive schema once we can share info between prepareRun and initialize stage.\n+    pipelineConfigurer.createDataset(HiveSchemaStore.HIVE_TABLE_SCHEMA_STORE, KeyValueTable.class,\n+                                     DatasetProperties.EMPTY);\n+  }\n+\n+  @Override\n+  public void prepareRun(BatchSourceContext context) throws Exception {\n+    // This line is to load VersionInfo class here to make it available in the HCatInputFormat.setInput call. This is\n+    // needed to support CDAP 3.2 where we were just exposing the classes of the plugin jar and not the resources.\n+    LOG.trace(\"Hadoop version: {}\", VersionInfo.getVersion());\n+    Job job = context.getHadoopJob();\n+    Configuration configuration = job.getConfiguration();\n+    job.setInputFormatClass(HCatInputFormat.class);\n+    configuration.set(\"hive.metastore.uris\", config.metaStoreURI);\n+    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();\n+    try {\n+      Thread.currentThread().setContextClassLoader(getClass().getClassLoader());","path":"hive-plugins/src/main/java/co/cask/plugin/etl/batch/source/HiveBatchSource.java","position":79,"original_position":79,"commit_id":"04b978f1de675111696ac95060b88d4b84659a0b","original_commit_id":"04b978f1de675111696ac95060b88d4b84659a0b","user":{"login":"albertshau","id":5215004,"avatar_url":"https://avatars.githubusercontent.com/u/5215004?v=3","gravatar_id":"","url":"https://api.github.com/users/albertshau","html_url":"https://github.com/albertshau","followers_url":"https://api.github.com/users/albertshau/followers","following_url":"https://api.github.com/users/albertshau/following{/other_user}","gists_url":"https://api.github.com/users/albertshau/gists{/gist_id}","starred_url":"https://api.github.com/users/albertshau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/albertshau/subscriptions","organizations_url":"https://api.github.com/users/albertshau/orgs","repos_url":"https://api.github.com/users/albertshau/repos","events_url":"https://api.github.com/users/albertshau/events{/privacy}","received_events_url":"https://api.github.com/users/albertshau/received_events","type":"User","site_admin":false},"body":"add a comment about why this is required","created_at":"2015-11-04T02:16:34Z","updated_at":"2015-11-04T02:16:34Z","html_url":"https://github.com/caskdata/hydrator-plugins/pull/43#discussion_r43835717","pull_request_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/43","_links":{"self":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/comments/43835717"},"html":{"href":"https://github.com/caskdata/hydrator-plugins/pull/43#discussion_r43835717"},"pull_request":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/43"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/43","id":49222929,"html_url":"https://github.com/caskdata/hydrator-plugins/pull/43","diff_url":"https://github.com/caskdata/hydrator-plugins/pull/43.diff","patch_url":"https://github.com/caskdata/hydrator-plugins/pull/43.patch","issue_url":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/43","number":43,"state":"open","locked":false,"title":"Hive Plugins: Add Hive Batch Source and Sink","user":{"login":"rohitsinha54","id":1472867,"avatar_url":"https://avatars.githubusercontent.com/u/1472867?v=3","gravatar_id":"","url":"https://api.github.com/users/rohitsinha54","html_url":"https://github.com/rohitsinha54","followers_url":"https://api.github.com/users/rohitsinha54/followers","following_url":"https://api.github.com/users/rohitsinha54/following{/other_user}","gists_url":"https://api.github.com/users/rohitsinha54/gists{/gist_id}","starred_url":"https://api.github.com/users/rohitsinha54/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rohitsinha54/subscriptions","organizations_url":"https://api.github.com/users/rohitsinha54/orgs","repos_url":"https://api.github.com/users/rohitsinha54/repos","events_url":"https://api.github.com/users/rohitsinha54/events{/privacy}","received_events_url":"https://api.github.com/users/rohitsinha54/received_events","type":"User","site_admin":false},"body":"- Adding Hive Batch Source\r\n- Tested on HDP 2.2 cluster running Hadoop 2.4 and Hive 0.13 and CDH 5.4.5 running Hadoop 2.6 and Hive 1.1 (with respective dependencies in pom).\r\n","created_at":"2015-10-30T01:49:46Z","updated_at":"2015-11-04T02:16:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"51428e602e0c93b89176a96c5cf6996d96b1f961","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/43/commits","review_comments_url":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/43/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/43/comments","statuses_url":"https://api.github.com/repos/caskdata/hydrator-plugins/statuses/04b978f1de675111696ac95060b88d4b84659a0b","head":{"label":"caskdata:feature/hive-source","ref":"feature/hive-source","sha":"04b978f1de675111696ac95060b88d4b84659a0b","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}","created_at":"2015-07-30T00:14:48Z","updated_at":"2015-11-02T06:17:19Z","pushed_at":"2015-11-04T01:15:53Z","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":"http://cdap.io","size":2142,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":5,"forks":1,"open_issues":5,"watchers":2,"default_branch":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"2b28c345c2fe6a953eb7adb8e7752653f07e03a1","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}","created_at":"2015-07-30T00:14:48Z","updated_at":"2015-11-02T06:17:19Z","pushed_at":"2015-11-04T01:15:53Z","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":"http://cdap.io","size":2142,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":5,"forks":1,"open_issues":5,"watchers":2,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/43"},"html":{"href":"https://github.com/caskdata/hydrator-plugins/pull/43"},"issue":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/43"},"comments":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/issues/43/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/pulls/43/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/43/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/hydrator-plugins/statuses/04b978f1de675111696ac95060b88d4b84659a0b"}}}}