-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-29259][SQL] call fs.exists only when necessary #25928
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,8 +90,6 @@ case class InsertIntoHadoopFsRelationCommand( | |
| fs, catalogTable.get, qualifiedOutputPath, matchingPartitions) | ||
| } | ||
|
|
||
| val pathExists = fs.exists(qualifiedOutputPath) | ||
|
|
||
| val parameters = CaseInsensitiveMap(options) | ||
|
|
||
| val partitionOverwriteMode = parameters.get("partitionOverwriteMode") | ||
|
|
@@ -111,25 +109,30 @@ case class InsertIntoHadoopFsRelationCommand( | |
| outputPath = outputPath.toString, | ||
| dynamicPartitionOverwrite = dynamicPartitionOverwrite) | ||
|
|
||
| val doInsertion = (mode, pathExists) match { | ||
| case (SaveMode.ErrorIfExists, true) => | ||
| throw new AnalysisException(s"path $qualifiedOutputPath already exists.") | ||
| case (SaveMode.Overwrite, true) => | ||
| if (ifPartitionNotExists && matchingPartitions.nonEmpty) { | ||
| false | ||
| } else if (dynamicPartitionOverwrite) { | ||
| // For dynamic partition overwrite, do not delete partition directories ahead. | ||
| true | ||
| } else { | ||
| deleteMatchingPartitions(fs, qualifiedOutputPath, customPartitionLocations, committer) | ||
| val doInsertion = if (mode == SaveMode.Append) { | ||
srowen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| true | ||
| } else { | ||
| val pathExists = fs.exists(qualifiedOutputPath) | ||
| (mode, pathExists) match { | ||
| case (SaveMode.ErrorIfExists, true) => | ||
| throw new AnalysisException(s"path $qualifiedOutputPath already exists.") | ||
| case (SaveMode.Overwrite, true) => | ||
| if (ifPartitionNotExists && matchingPartitions.nonEmpty) { | ||
| false | ||
| } else if (dynamicPartitionOverwrite) { | ||
| // For dynamic partition overwrite, do not delete partition directories ahead. | ||
| true | ||
| } else { | ||
| deleteMatchingPartitions(fs, qualifiedOutputPath, customPartitionLocations, committer) | ||
| true | ||
| } | ||
| case (SaveMode.Overwrite, _) | (SaveMode.ErrorIfExists, false) => | ||
|
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. nit: we can simply put false here instead of 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. @viirya I just kept the existing code for these since I didn't want to make unnecessary changes. |
||
| true | ||
| } | ||
| case (SaveMode.Append, _) | (SaveMode.Overwrite, _) | (SaveMode.ErrorIfExists, false) => | ||
| true | ||
| case (SaveMode.Ignore, exists) => | ||
| !exists | ||
| case (s, exists) => | ||
| throw new IllegalStateException(s"unsupported save mode $s ($exists)") | ||
| case (SaveMode.Ignore, exists) => | ||
| !exists | ||
| case (s, exists) => | ||
| throw new IllegalStateException(s"unsupported save mode $s ($exists)") | ||
| } | ||
| } | ||
|
|
||
| if (doInsertion) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Would making this as
lazy valdo the same? Even not needed if we agree to follow my next suggestion.