{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/36934368","id":36934368,"diff_hunk":"@@ -0,0 +1,43 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * 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, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.spark.sql.sources\n+\n+import org.apache.hadoop.fs.{FileStatus, FileSystem, Path}\n+import org.apache.spark.rdd.RDD\n+import org.apache.spark.sql.SQLContext\n+\n+object CombineSmallFile {\n+  def combineWithFiles[T](rdd: RDD[T], sqlContext: SQLContext, inputFiles: Array[FileStatus])\n+      : RDD[T] = {\n+    if (sqlContext.conf.combineSmallFile) {\n+      val totalLen = inputFiles.map { file =>\n+        if (file.isDir) 0L else file.getLen\n+      }.sum\n+      val numPartitions = (totalLen / sqlContext.conf.splitSize + 1).toInt\n+      rdd.coalesce(numPartitions)","path":"sql/core/src/main/scala/org/apache/spark/sql/sources/CombineSmallFile.scala","position":32,"original_position":32,"commit_id":"3ae34b46edc482065ba94471d73fb649b5b72785","original_commit_id":"3ae34b46edc482065ba94471d73fb649b5b72785","user":{"login":"watermen","id":1400819,"avatar_url":"https://avatars.githubusercontent.com/u/1400819?v=3","gravatar_id":"","url":"https://api.github.com/users/watermen","html_url":"https://github.com/watermen","followers_url":"https://api.github.com/users/watermen/followers","following_url":"https://api.github.com/users/watermen/following{/other_user}","gists_url":"https://api.github.com/users/watermen/gists{/gist_id}","starred_url":"https://api.github.com/users/watermen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watermen/subscriptions","organizations_url":"https://api.github.com/users/watermen/orgs","repos_url":"https://api.github.com/users/watermen/repos","events_url":"https://api.github.com/users/watermen/events{/privacy}","received_events_url":"https://api.github.com/users/watermen/received_events","type":"User","site_admin":false},"body":"2GB will split into 16 takes(if hadoop block size is 128M) with `spark.sql.small.file.combine=false`, instead of 1 task. So turn 16 to 8 is also combine.","created_at":"2015-08-13T01:47:38Z","updated_at":"2015-08-13T01:47:38Z","html_url":"https://github.com/apache/spark/pull/8125#discussion_r36934368","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/8125","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/36934368"},"html":{"href":"https://github.com/apache/spark/pull/8125#discussion_r36934368"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/8125"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/8125","id":42223578,"html_url":"https://github.com/apache/spark/pull/8125","diff_url":"https://github.com/apache/spark/pull/8125.diff","patch_url":"https://github.com/apache/spark/pull/8125.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/8125","number":8125,"state":"open","locked":false,"title":"[SPARK-8813][SQL] Combine files when there're many small files in table","user":{"login":"watermen","id":1400819,"avatar_url":"https://avatars.githubusercontent.com/u/1400819?v=3","gravatar_id":"","url":"https://api.github.com/users/watermen","html_url":"https://github.com/watermen","followers_url":"https://api.github.com/users/watermen/followers","following_url":"https://api.github.com/users/watermen/following{/other_user}","gists_url":"https://api.github.com/users/watermen/gists{/gist_id}","starred_url":"https://api.github.com/users/watermen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watermen/subscriptions","organizations_url":"https://api.github.com/users/watermen/orgs","repos_url":"https://api.github.com/users/watermen/repos","events_url":"https://api.github.com/users/watermen/events{/privacy}","received_events_url":"https://api.github.com/users/watermen/received_events","type":"User","site_admin":false},"body":"Many small files in table will lead to many small tasks in Spark. It will affect performance. So this patch use `coalesce` operator to combine small files in table. \r\nIt'll cover `TableReader` and `HadoopFsRelation(ParquetRelation/OrcRelation/JSONRelation)`.\r\nMany users use sql in `spark-sql` shell, and \r\n```\r\nsqlContext.read.parquet(\"hdfs://some/path\").coalesce(1).collect()\r\n```\r\n advised by @liancheng is not convenience in this case.\r\nThis patch add two configurations below(if it is ok, I'll add them to doc):\r\n\r\n| Property Name | Default | Meaning |\r\n| ------------- | ------- | ------- |\r\n| spark.sql.small.file.combine | true | Whether to combine small file.\r\n| spark.sql.small.file.split.size | 256000000 | The size of split after combine small file.\r\n\r\n/cc @liancheng @marmbrus @scwf ","created_at":"2015-08-12T10:10:34Z","updated_at":"2015-08-13T01:47:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5e19b6477fd3809f0171e2bd8f43f37c75c4ce85","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/8125/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/8125/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/8125/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/3ae34b46edc482065ba94471d73fb649b5b72785","head":{"label":"watermen:SPARK-8813-new","ref":"SPARK-8813-new","sha":"3ae34b46edc482065ba94471d73fb649b5b72785","user":{"login":"watermen","id":1400819,"avatar_url":"https://avatars.githubusercontent.com/u/1400819?v=3","gravatar_id":"","url":"https://api.github.com/users/watermen","html_url":"https://github.com/watermen","followers_url":"https://api.github.com/users/watermen/followers","following_url":"https://api.github.com/users/watermen/following{/other_user}","gists_url":"https://api.github.com/users/watermen/gists{/gist_id}","starred_url":"https://api.github.com/users/watermen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watermen/subscriptions","organizations_url":"https://api.github.com/users/watermen/orgs","repos_url":"https://api.github.com/users/watermen/repos","events_url":"https://api.github.com/users/watermen/events{/privacy}","received_events_url":"https://api.github.com/users/watermen/received_events","type":"User","site_admin":false},"repo":{"id":26309097,"name":"spark","full_name":"watermen/spark","owner":{"login":"watermen","id":1400819,"avatar_url":"https://avatars.githubusercontent.com/u/1400819?v=3","gravatar_id":"","url":"https://api.github.com/users/watermen","html_url":"https://github.com/watermen","followers_url":"https://api.github.com/users/watermen/followers","following_url":"https://api.github.com/users/watermen/following{/other_user}","gists_url":"https://api.github.com/users/watermen/gists{/gist_id}","starred_url":"https://api.github.com/users/watermen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watermen/subscriptions","organizations_url":"https://api.github.com/users/watermen/orgs","repos_url":"https://api.github.com/users/watermen/repos","events_url":"https://api.github.com/users/watermen/events{/privacy}","received_events_url":"https://api.github.com/users/watermen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/watermen/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/watermen/spark","forks_url":"https://api.github.com/repos/watermen/spark/forks","keys_url":"https://api.github.com/repos/watermen/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/watermen/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/watermen/spark/teams","hooks_url":"https://api.github.com/repos/watermen/spark/hooks","issue_events_url":"https://api.github.com/repos/watermen/spark/issues/events{/number}","events_url":"https://api.github.com/repos/watermen/spark/events","assignees_url":"https://api.github.com/repos/watermen/spark/assignees{/user}","branches_url":"https://api.github.com/repos/watermen/spark/branches{/branch}","tags_url":"https://api.github.com/repos/watermen/spark/tags","blobs_url":"https://api.github.com/repos/watermen/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/watermen/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/watermen/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/watermen/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/watermen/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/watermen/spark/languages","stargazers_url":"https://api.github.com/repos/watermen/spark/stargazers","contributors_url":"https://api.github.com/repos/watermen/spark/contributors","subscribers_url":"https://api.github.com/repos/watermen/spark/subscribers","subscription_url":"https://api.github.com/repos/watermen/spark/subscription","commits_url":"https://api.github.com/repos/watermen/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/watermen/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/watermen/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/watermen/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/watermen/spark/contents/{+path}","compare_url":"https://api.github.com/repos/watermen/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/watermen/spark/merges","archive_url":"https://api.github.com/repos/watermen/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/watermen/spark/downloads","issues_url":"https://api.github.com/repos/watermen/spark/issues{/number}","pulls_url":"https://api.github.com/repos/watermen/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/watermen/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/watermen/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/watermen/spark/labels{/name}","releases_url":"https://api.github.com/repos/watermen/spark/releases{/id}","created_at":"2014-11-07T07:37:56Z","updated_at":"2015-02-04T02:18:35Z","pushed_at":"2015-08-12T09:52:34Z","git_url":"git://github.com/watermen/spark.git","ssh_url":"git@github.com:watermen/spark.git","clone_url":"https://github.com/watermen/spark.git","svn_url":"https://github.com/watermen/spark","homepage":null,"size":114868,"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:master","ref":"master","sha":"5c99d8bf98cbf7f568345d02a814fc318cbfca75","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}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-08-13T01:46:12Z","pushed_at":"2015-08-13T01:43:50Z","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":1601274,"stargazers_count":5063,"watchers_count":5063,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4619,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":325,"forks":4619,"open_issues":325,"watchers":5063,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/8125"},"html":{"href":"https://github.com/apache/spark/pull/8125"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/8125"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/8125/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/8125/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/8125/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/3ae34b46edc482065ba94471d73fb649b5b72785"}}}}