{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/74132414","id":74132414,"diff_hunk":"@@ -425,6 +430,111 @@ case class AlterTableDropPartitionCommand(\n \n }\n \n+/**\n+ * Recover Partitions in ALTER TABLE: recover all the partition in the directory of a table and\n+ * update the catalog.\n+ *\n+ * The syntax of this command is:\n+ * {{{\n+ *   ALTER TABLE table RECOVER PARTITIONS;\n+ *   MSCK REPAIR TABLE table;\n+ * }}}\n+ */\n+case class AlterTableRecoverPartitionsCommand(\n+    tableName: TableIdentifier,\n+    cmd: String = \"ALTER TABLE RECOVER PARTITIONS\") extends RunnableCommand {\n+  override def run(spark: SparkSession): Seq[Row] = {\n+    val catalog = spark.sessionState.catalog\n+    if (!catalog.tableExists(tableName)) {\n+      throw new AnalysisException(s\"Table $tableName in $cmd does not exist.\")\n+    }\n+    val table = catalog.getTableMetadata(tableName)\n+    if (catalog.isTemporaryTable(tableName)) {\n+      throw new AnalysisException(\n+        s\"Operation not allowed: $cmd on temporary tables: $tableName\")\n+    }\n+    if (DDLUtils.isDatasourceTable(table)) {\n+      throw new AnalysisException(\n+        s\"Operation not allowed: $cmd on datasource tables: $tableName\")\n+    }\n+    if (table.tableType != CatalogTableType.EXTERNAL) {\n+      throw new AnalysisException(\n+        s\"Operation not allowed: $cmd only works on external tables: $tableName\")\n+    }\n+    if (!DDLUtils.isTablePartitioned(table)) {\n+      throw new AnalysisException(\n+        s\"Operation not allowed: $cmd only works on partitioned tables: $tableName\")\n+    }\n+    if (table.storage.locationUri.isEmpty) {\n+      throw new AnalysisException(\n+        s\"Operation not allowed: $cmd only works on table with location provided: $tableName\")\n+    }\n+\n+    val root = new Path(table.storage.locationUri.get)\n+    val fs = root.getFileSystem(spark.sparkContext.hadoopConfiguration)\n+    // Dummy jobconf to get to the pathFilter defined in configuration\n+    // It's very expensive to create a JobConf(ClassUtil.findContainingJar() is slow)\n+    val jobConf = new JobConf(spark.sparkContext.hadoopConfiguration, this.getClass)\n+    val pathFilter = FileInputFormat.getInputPathFilter(jobConf)\n+    val partitionSpecsAndLocs = scanPartitions(\n+      spark, fs, pathFilter, root, Map(), table.partitionColumnNames.map(_.toLowerCase))\n+    val parts = partitionSpecsAndLocs.map { case (spec, location) =>\n+      // inherit table storage format (possibly except for location)\n+      CatalogTablePartition(spec, table.storage.copy(locationUri = Some(location.toUri.toString)))\n+    }\n+    spark.sessionState.catalog.createPartitions(tableName,\n+      parts.toArray[CatalogTablePartition], ignoreIfExists = true)","path":"sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala","position":85,"original_position":85,"commit_id":"e5906cf408f225b5023ed6d250f850fcd447168a","original_commit_id":"e5906cf408f225b5023ed6d250f850fcd447168a","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"body":"no, this is true for Hive <=0.12, for Hive 0.13+, they are sent in single RPC. so we should verify that what's limit for a single RPC","created_at":"2016-08-09T19:55:25Z","updated_at":"2016-08-09T19:55:25Z","html_url":"https://github.com/apache/spark/pull/14500#discussion_r74132414","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/14500","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/74132414"},"html":{"href":"https://github.com/apache/spark/pull/14500#discussion_r74132414"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/14500"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/14500","id":80160348,"html_url":"https://github.com/apache/spark/pull/14500","diff_url":"https://github.com/apache/spark/pull/14500.diff","patch_url":"https://github.com/apache/spark/pull/14500.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/14500","number":14500,"state":"closed","locked":false,"title":"[SPARK-16905] SQL DDL: MSCK REPAIR TABLE","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nMSCK REPAIR TABLE could be used to recover the partitions in external catalog based on partitions in file system.\r\n\r\nAnother syntax is: ALTER TABLE table RECOVER PARTITIONS\r\n\r\nThe implementation in this PR will only list partitions (not the files with a partition) in driver (in parallel if needed).\r\n\r\n## How was this patch tested?\r\n\r\nAdded unit tests for it and Hive compatibility test suite.\r\n\r\n","created_at":"2016-08-04T22:26:58Z","updated_at":"2016-08-09T19:55:25Z","closed_at":"2016-08-09T18:24:07Z","merged_at":null,"merge_commit_sha":"d8fc4ce656e0c61a284f5d7b956841a572fef313","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/14500/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/14500/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/14500/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/e5906cf408f225b5023ed6d250f850fcd447168a","head":{"label":"davies:repair_table","ref":"repair_table","sha":"e5906cf408f225b5023ed6d250f850fcd447168a","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"repo":{"id":21724875,"name":"spark","full_name":"davies/spark","owner":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davies/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/davies/spark","forks_url":"https://api.github.com/repos/davies/spark/forks","keys_url":"https://api.github.com/repos/davies/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davies/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davies/spark/teams","hooks_url":"https://api.github.com/repos/davies/spark/hooks","issue_events_url":"https://api.github.com/repos/davies/spark/issues/events{/number}","events_url":"https://api.github.com/repos/davies/spark/events","assignees_url":"https://api.github.com/repos/davies/spark/assignees{/user}","branches_url":"https://api.github.com/repos/davies/spark/branches{/branch}","tags_url":"https://api.github.com/repos/davies/spark/tags","blobs_url":"https://api.github.com/repos/davies/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davies/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davies/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/davies/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davies/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/davies/spark/languages","stargazers_url":"https://api.github.com/repos/davies/spark/stargazers","contributors_url":"https://api.github.com/repos/davies/spark/contributors","subscribers_url":"https://api.github.com/repos/davies/spark/subscribers","subscription_url":"https://api.github.com/repos/davies/spark/subscription","commits_url":"https://api.github.com/repos/davies/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/davies/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/davies/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/davies/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/davies/spark/contents/{+path}","compare_url":"https://api.github.com/repos/davies/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davies/spark/merges","archive_url":"https://api.github.com/repos/davies/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davies/spark/downloads","issues_url":"https://api.github.com/repos/davies/spark/issues{/number}","pulls_url":"https://api.github.com/repos/davies/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/davies/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/davies/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davies/spark/labels{/name}","releases_url":"https://api.github.com/repos/davies/spark/releases{/id}","deployments_url":"https://api.github.com/repos/davies/spark/deployments","created_at":"2014-07-11T06:39:41Z","updated_at":"2016-03-16T14:14:59Z","pushed_at":"2016-08-08T22:35:32Z","git_url":"git://github.com/davies/spark.git","ssh_url":"git@github.com:davies/spark.git","clone_url":"https://github.com/davies/spark.git","svn_url":"https://github.com/davies/spark","homepage":null,"size":182229,"stargazers_count":2,"watchers_count":2,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"1f96c97f2374a95140a0c72b1f4eae50ac21d84a","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-08-09T19:31:42Z","pushed_at":"2016-08-09T19:48:43Z","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":509444,"stargazers_count":9604,"watchers_count":9604,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":8921,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":455,"forks":8921,"open_issues":455,"watchers":9604,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/14500"},"html":{"href":"https://github.com/apache/spark/pull/14500"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/14500"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/14500/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/14500/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/14500/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/e5906cf408f225b5023ed6d250f850fcd447168a"}}}}
{"actor":{"display_login":"davies"}}