{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/8010","labels_url":"https://api.github.com/repos/apache/spark/issues/8010/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/8010/comments","events_url":"https://api.github.com/repos/apache/spark/issues/8010/events","html_url":"https://github.com/apache/spark/pull/8010","id":99536666,"number":8010,"title":"[SPARK-8890][SQL] Fallback on sorting when writing many dynamic partitions","user":{"login":"marmbrus","id":527,"avatar_url":"https://avatars.githubusercontent.com/u/527?v=3","gravatar_id":"","url":"https://api.github.com/users/marmbrus","html_url":"https://github.com/marmbrus","followers_url":"https://api.github.com/users/marmbrus/followers","following_url":"https://api.github.com/users/marmbrus/following{/other_user}","gists_url":"https://api.github.com/users/marmbrus/gists{/gist_id}","starred_url":"https://api.github.com/users/marmbrus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marmbrus/subscriptions","organizations_url":"https://api.github.com/users/marmbrus/orgs","repos_url":"https://api.github.com/users/marmbrus/repos","events_url":"https://api.github.com/users/marmbrus/events{/privacy}","received_events_url":"https://api.github.com/users/marmbrus/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":28,"created_at":"2015-08-06T22:22:25Z","updated_at":"2015-08-07T20:25:11Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/8010","html_url":"https://github.com/apache/spark/pull/8010","diff_url":"https://github.com/apache/spark/pull/8010.diff","patch_url":"https://github.com/apache/spark/pull/8010.patch"},"body":"Previously, we would open a new file for each new dynamic written out using `HadoopFsRelation`.  For formats like parquet this is very costly due to the buffers required to get good compression.  In this PR I refactor the code allowing us to fall back on an external sort when many partitions are seen.  As such each task will open no more than `spark.sql.sources.maxFiles` files.  I also did the following cleanup:\r\n\r\n - Instead of keying the file HashMap on an expensive to compute string representation of the partition, we now use a fairly cheap UnsafeProjection that avoids heap allocations.\r\n - The control flow for instantiating and invoking a writer container has been simplified.  Now instead of switching in two places based on the use of partitioning, the specific writer container must implement a single method `writeRows` that is invoked using `runJob`.\r\n - `InternalOutputWriter` has been removed.  Instead we have a `private[sql]` method `writeInternal` that converts and calls the public method.  This method can be overridden by internal datasources to avoid the conversion.  This change remove a lot of code duplication and per-row `asInstanceOf` checks.\r\n - `commands.scala` has been split up."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/128826346","html_url":"https://github.com/apache/spark/pull/8010#issuecomment-128826346","issue_url":"https://api.github.com/repos/apache/spark/issues/8010","id":128826346,"user":{"login":"SparkQA","id":8108735,"avatar_url":"https://avatars.githubusercontent.com/u/8108735?v=3","gravatar_id":"","url":"https://api.github.com/users/SparkQA","html_url":"https://github.com/SparkQA","followers_url":"https://api.github.com/users/SparkQA/followers","following_url":"https://api.github.com/users/SparkQA/following{/other_user}","gists_url":"https://api.github.com/users/SparkQA/gists{/gist_id}","starred_url":"https://api.github.com/users/SparkQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SparkQA/subscriptions","organizations_url":"https://api.github.com/users/SparkQA/orgs","repos_url":"https://api.github.com/users/SparkQA/repos","events_url":"https://api.github.com/users/SparkQA/events{/privacy}","received_events_url":"https://api.github.com/users/SparkQA/received_events","type":"User","site_admin":false},"created_at":"2015-08-07T20:25:11Z","updated_at":"2015-08-07T20:25:11Z","body":"  [Test build #40189 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/40189/consoleFull) for   PR 8010 at commit [`17b690e`](https://github.com/apache/spark/commit/17b690e632e26beea80b9bee29bc75b4f52dbb0b)."}}