{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/87676512","pull_request_review_id":8283485,"id":87676512,"diff_hunk":"@@ -54,6 +61,61 @@ case class InsertIntoHiveTable(\n   @transient private lazy val hiveContext = new Context(sc.hiveconf)\n   @transient private lazy val catalog = sc.catalog\n \n+  val stagingDir = new HiveConf().getVar(HiveConf.ConfVars.STAGINGDIR)\n+\n+  private def executionId: String = {\n+    val rand: Random = new Random\n+    val format: SimpleDateFormat = new SimpleDateFormat(\"yyyy-MM-dd_HH-mm-ss_SSS\")\n+    val executionId: String = \"hive_\" + format.format(new Date) + \"_\" + Math.abs(rand.nextLong)\n+    return executionId\n+  }\n+\n+  private def getStagingDir(inputPath: Path, hadoopConf: Configuration): Path = {\n+    val inputPathUri: URI = inputPath.toUri\n+    val inputPathName: String = inputPathUri.getPath\n+    val fs: FileSystem = inputPath.getFileSystem(hadoopConf)\n+    val stagingPathName: String =\n+      if (inputPathName.indexOf(stagingDir) == -1) {\n+        new Path(inputPathName, stagingDir).toString\n+      } else {\n+        inputPathName.substring(0, inputPathName.indexOf(stagingDir) + stagingDir.length)\n+      }\n+    val dir: Path =\n+      fs.makeQualified(\n+        new Path(stagingPathName + \"_\" + executionId + \"-\" + TaskRunner.getTaskRunnerID))\n+    logDebug(\"Created staging dir = \" + dir + \" for path = \" + inputPath)\n+    try {\n+      if (!FileUtils.mkdir(fs, dir, true, hadoopConf)) {\n+        throw new IllegalStateException(\"Cannot create staging directory  '\" + dir.toString + \"'\")\n+      }\n+      fs.deleteOnExit(dir)\n+    }\n+    catch {\n+      case e: IOException =>\n+        throw new RuntimeException(\n+          \"Cannot create staging directory '\" + dir.toString + \"': \" + e.getMessage, e)\n+\n+    }\n+    return dir","path":"sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveTable.scala","position":74,"original_position":74,"commit_id":"ac65375a64c2a8a2fe019dc0e2c031f413df74b8","original_commit_id":"ac65375a64c2a8a2fe019dc0e2c031f413df74b8","user":{"login":"fidato13","id":14843631,"avatar_url":"https://avatars.githubusercontent.com/u/14843631?v=3","gravatar_id":"","url":"https://api.github.com/users/fidato13","html_url":"https://github.com/fidato13","followers_url":"https://api.github.com/users/fidato13/followers","following_url":"https://api.github.com/users/fidato13/following{/other_user}","gists_url":"https://api.github.com/users/fidato13/gists{/gist_id}","starred_url":"https://api.github.com/users/fidato13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidato13/subscriptions","organizations_url":"https://api.github.com/users/fidato13/orgs","repos_url":"https://api.github.com/users/fidato13/repos","events_url":"https://api.github.com/users/fidato13/events{/privacy}","received_events_url":"https://api.github.com/users/fidato13/received_events","type":"User","site_admin":false},"body":"Can the extra noise (return statement) in scala code be removed please.","created_at":"2016-11-11T23:46:02Z","updated_at":"2016-11-11T23:46:02Z","html_url":"https://github.com/apache/spark/pull/15819#discussion_r87676512","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/15819","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/87676512"},"html":{"href":"https://github.com/apache/spark/pull/15819#discussion_r87676512"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/15819"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/15819","id":92889043,"html_url":"https://github.com/apache/spark/pull/15819","diff_url":"https://github.com/apache/spark/pull/15819.diff","patch_url":"https://github.com/apache/spark/pull/15819.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/15819","number":15819,"state":"open","locked":false,"title":"[SPARK-18372][SQL].Staging directory fail to be removed ","user":{"login":"merlintang","id":1431801,"avatar_url":"https://avatars.githubusercontent.com/u/1431801?v=3","gravatar_id":"","url":"https://api.github.com/users/merlintang","html_url":"https://github.com/merlintang","followers_url":"https://api.github.com/users/merlintang/followers","following_url":"https://api.github.com/users/merlintang/following{/other_user}","gists_url":"https://api.github.com/users/merlintang/gists{/gist_id}","starred_url":"https://api.github.com/users/merlintang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlintang/subscriptions","organizations_url":"https://api.github.com/users/merlintang/orgs","repos_url":"https://api.github.com/users/merlintang/repos","events_url":"https://api.github.com/users/merlintang/events{/privacy}","received_events_url":"https://api.github.com/users/merlintang/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nThis fix is related to be bug: https://issues.apache.org/jira/browse/SPARK-18372 . \r\nThe insertIntoHiveTable would generate a .staging directory, but this directory  fail to be removed in the end. \r\n\r\n## How was this patch tested?\r\nmanual tests\r\n\r\nAuthor: Mingjie Tang <mtang@hortonworks.com>\r\n","created_at":"2016-11-09T00:51:16Z","updated_at":"2016-11-11T23:46:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"83679d0713f80e90fb907cf1cb5718f62b986a74","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/15819/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/15819/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/15819/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/ac65375a64c2a8a2fe019dc0e2c031f413df74b8","head":{"label":"merlintang:branch-1.6","ref":"branch-1.6","sha":"ac65375a64c2a8a2fe019dc0e2c031f413df74b8","user":{"login":"merlintang","id":1431801,"avatar_url":"https://avatars.githubusercontent.com/u/1431801?v=3","gravatar_id":"","url":"https://api.github.com/users/merlintang","html_url":"https://github.com/merlintang","followers_url":"https://api.github.com/users/merlintang/followers","following_url":"https://api.github.com/users/merlintang/following{/other_user}","gists_url":"https://api.github.com/users/merlintang/gists{/gist_id}","starred_url":"https://api.github.com/users/merlintang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlintang/subscriptions","organizations_url":"https://api.github.com/users/merlintang/orgs","repos_url":"https://api.github.com/users/merlintang/repos","events_url":"https://api.github.com/users/merlintang/events{/privacy}","received_events_url":"https://api.github.com/users/merlintang/received_events","type":"User","site_admin":false},"repo":{"id":71845862,"name":"spark","full_name":"merlintang/spark","owner":{"login":"merlintang","id":1431801,"avatar_url":"https://avatars.githubusercontent.com/u/1431801?v=3","gravatar_id":"","url":"https://api.github.com/users/merlintang","html_url":"https://github.com/merlintang","followers_url":"https://api.github.com/users/merlintang/followers","following_url":"https://api.github.com/users/merlintang/following{/other_user}","gists_url":"https://api.github.com/users/merlintang/gists{/gist_id}","starred_url":"https://api.github.com/users/merlintang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlintang/subscriptions","organizations_url":"https://api.github.com/users/merlintang/orgs","repos_url":"https://api.github.com/users/merlintang/repos","events_url":"https://api.github.com/users/merlintang/events{/privacy}","received_events_url":"https://api.github.com/users/merlintang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/merlintang/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/merlintang/spark","forks_url":"https://api.github.com/repos/merlintang/spark/forks","keys_url":"https://api.github.com/repos/merlintang/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/merlintang/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/merlintang/spark/teams","hooks_url":"https://api.github.com/repos/merlintang/spark/hooks","issue_events_url":"https://api.github.com/repos/merlintang/spark/issues/events{/number}","events_url":"https://api.github.com/repos/merlintang/spark/events","assignees_url":"https://api.github.com/repos/merlintang/spark/assignees{/user}","branches_url":"https://api.github.com/repos/merlintang/spark/branches{/branch}","tags_url":"https://api.github.com/repos/merlintang/spark/tags","blobs_url":"https://api.github.com/repos/merlintang/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/merlintang/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/merlintang/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/merlintang/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/merlintang/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/merlintang/spark/languages","stargazers_url":"https://api.github.com/repos/merlintang/spark/stargazers","contributors_url":"https://api.github.com/repos/merlintang/spark/contributors","subscribers_url":"https://api.github.com/repos/merlintang/spark/subscribers","subscription_url":"https://api.github.com/repos/merlintang/spark/subscription","commits_url":"https://api.github.com/repos/merlintang/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/merlintang/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/merlintang/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/merlintang/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/merlintang/spark/contents/{+path}","compare_url":"https://api.github.com/repos/merlintang/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/merlintang/spark/merges","archive_url":"https://api.github.com/repos/merlintang/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/merlintang/spark/downloads","issues_url":"https://api.github.com/repos/merlintang/spark/issues{/number}","pulls_url":"https://api.github.com/repos/merlintang/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/merlintang/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/merlintang/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/merlintang/spark/labels{/name}","releases_url":"https://api.github.com/repos/merlintang/spark/releases{/id}","deployments_url":"https://api.github.com/repos/merlintang/spark/deployments","created_at":"2016-10-25T01:03:41Z","updated_at":"2016-10-25T01:04:07Z","pushed_at":"2016-11-09T00:43:42Z","git_url":"git://github.com/merlintang/spark.git","ssh_url":"git@github.com:merlintang/spark.git","clone_url":"https://github.com/merlintang/spark.git","svn_url":"https://github.com/merlintang/spark","homepage":null,"size":248391,"stargazers_count":0,"watchers_count":0,"language":"Scala","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":"master"}},"base":{"label":"apache:branch-1.6","ref":"branch-1.6","sha":"9136e2693d8272fff66dc187e28a310cf7593022","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2016-11-11T19:01:26Z","pushed_at":"2016-11-11T23:12:38Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":608563,"stargazers_count":10694,"watchers_count":10694,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9988,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":444,"forks":9988,"open_issues":444,"watchers":10694,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/15819"},"html":{"href":"https://github.com/apache/spark/pull/15819"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/15819"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/15819/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/15819/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/15819/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/ac65375a64c2a8a2fe019dc0e2c031f413df74b8"}}}}
{"actor":{"display_login":"fidato13"}}