-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[SPARK-8014] [SQL] Avoid premature metadata discovery when writing a HadoopFsRelation with a save mode other than Append #6583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ | |
|
||
package org.apache.spark.sql.sources | ||
|
||
import java.io.File | ||
|
||
import com.google.common.io.Files | ||
import org.apache.hadoop.fs.Path | ||
|
||
import org.apache.spark.{SparkException, SparkFunSuite} | ||
|
@@ -453,6 +456,20 @@ abstract class HadoopFsRelationTest extends QueryTest with SQLTestUtils { | |
} | ||
} | ||
} | ||
|
||
test("SPARK-7616: adjust column name order accordingly when saving partitioned table") { | ||
val df = (1 to 3).map(i => (i, s"val_$i", i * 2)).toDF("a", "b", "c") | ||
|
||
df.write | ||
.format(dataSourceName) | ||
.mode(SaveMode.Overwrite) | ||
.partitionBy("c", "a") | ||
.saveAsTable("t") | ||
|
||
withTable("t") { | ||
checkAnswer(table("t"), df.select('b, 'c, 'a).collect()) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this test case here so that it gets executed for all test suite that extend |
||
} | ||
|
||
class SimpleTextHadoopFsRelationSuite extends HadoopFsRelationTest { | ||
|
@@ -534,20 +551,6 @@ class ParquetHadoopFsRelationSuite extends HadoopFsRelationTest { | |
} | ||
} | ||
|
||
test("SPARK-7616: adjust column name order accordingly when saving partitioned table") { | ||
val df = (1 to 3).map(i => (i, s"val_$i", i * 2)).toDF("a", "b", "c") | ||
|
||
df.write | ||
.format("parquet") | ||
.mode(SaveMode.Overwrite) | ||
.partitionBy("c", "a") | ||
.saveAsTable("t") | ||
|
||
withTable("t") { | ||
checkAnswer(table("t"), df.select('b, 'c, 'a).collect()) | ||
} | ||
} | ||
|
||
test("SPARK-7868: _temporary directories should be ignored") { | ||
withTempPath { dir => | ||
val df = Seq("a", "b", "c").zipWithIndex.toDF() | ||
|
@@ -563,4 +566,32 @@ class ParquetHadoopFsRelationSuite extends HadoopFsRelationTest { | |
checkAnswer(read.format("parquet").load(dir.getCanonicalPath), df.collect()) | ||
} | ||
} | ||
|
||
test("SPARK-8014: Avoid scanning output directory when SaveMode isn't SaveMode.Append") { | ||
withTempDir { dir => | ||
val path = dir.getCanonicalPath | ||
val df = Seq(1 -> "a").toDF() | ||
|
||
// Creates an arbitrary file. If this directory gets scanned, ParquetRelation2 will throw | ||
// since it's not a valid Parquet file. | ||
val emptyFile = new File(path, "empty") | ||
Files.createParentDirs(emptyFile) | ||
Files.touch(emptyFile) | ||
|
||
// This shouldn't throw anything. | ||
df.write.format("parquet").mode(SaveMode.Ignore).save(path) | ||
|
||
// This should only complain that the destination directory already exists, rather than file | ||
// "empty" is not a Parquet file. | ||
assert { | ||
intercept[RuntimeException] { | ||
df.write.format("parquet").mode(SaveMode.ErrorIfExists).save(path) | ||
}.getMessage.contains("already exists") | ||
} | ||
|
||
// This shouldn't throw anything. | ||
df.write.format("parquet").mode(SaveMode.Overwrite).save(path) | ||
checkAnswer(read.format("parquet").load(path), df) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
r.schema
is where metadata discovery is triggered. This PR fixes this issue by moving this projection intoInsertIntoHadoopFsRelation
.