-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-32516][SQL] 'path' option cannot coexist with load()'s path parameters #29328
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 all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
63f3d60
initial commit
imback82 b4a2096
Merge branch 'master' into dfw_option
imback82 296d4bb
fix unit tests partially
imback82 c7fc414
v1 fix
imback82 ba2232f
address comments
imback82 099d08b
Merge branch 'master' into dfw_option
imback82 9b6be0c
Address PR comments
imback82 17c94a4
revert changes
imback82 4c6ada7
remove a test
imback82 60b8e82
Address comments
imback82 cd15fe2
function rename
imback82 3e02205
Address comments
imback82 d344eb9
Fix tests
imback82 650d45d
address comments
imback82 808b7c0
Update migration guide
imback82 63c9383
checks for "paths"
imback82 ab7fc24
Merge branch 'master' into dfw_option
imback82 ac007c0
address PR comments
imback82 62794e5
test fix
imback82 d5c4203
address PR comments
imback82 92bf5ef
add a config for legacy behavior
imback82 e1decd4
fully restore the legacy behavior
imback82 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 |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ import org.apache.spark.sql.execution.datasources.csv._ | |
| import org.apache.spark.sql.execution.datasources.jdbc._ | ||
| import org.apache.spark.sql.execution.datasources.json.TextInputJsonDataSource | ||
| import org.apache.spark.sql.execution.datasources.v2.{DataSourceV2Relation, DataSourceV2Utils} | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.types.StructType | ||
| import org.apache.spark.sql.util.CaseInsensitiveStringMap | ||
| import org.apache.spark.unsafe.types.UTF8String | ||
|
|
@@ -229,7 +230,11 @@ class DataFrameReader private[sql](sparkSession: SparkSession) extends Logging { | |
| */ | ||
| def load(path: String): DataFrame = { | ||
| // force invocation of `load(...varargs...)` | ||
| option("path", path).load(Seq.empty: _*) | ||
| if (sparkSession.sessionState.conf.legacyPathOptionBehavior) { | ||
| option("path", path).load(Seq.empty: _*) | ||
|
Contributor
Author
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. This is needed to restore the legacy behavior. Note that the legacy behavior is different for the following:
|
||
| } else { | ||
| load(Seq(path): _*) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -245,15 +250,30 @@ class DataFrameReader private[sql](sparkSession: SparkSession) extends Logging { | |
| "read files of Hive data source directly.") | ||
| } | ||
|
|
||
imback82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val legacyPathOptionBehavior = sparkSession.sessionState.conf.legacyPathOptionBehavior | ||
| if (!legacyPathOptionBehavior && | ||
| (extraOptions.contains("path") || extraOptions.contains("paths")) && paths.nonEmpty) { | ||
| throw new AnalysisException("There is a 'path' or 'paths' option set and load() is called " + | ||
| "with path parameters. Either remove the path option if it's the same as the path " + | ||
| "parameter, or add it to the load() parameter if you do want to read multiple paths.") | ||
| } | ||
|
|
||
| val updatedPaths = if (!legacyPathOptionBehavior && paths.length == 1) { | ||
| option("path", paths.head) | ||
| Seq.empty | ||
| } else { | ||
| paths | ||
| } | ||
|
|
||
| DataSource.lookupDataSourceV2(source, sparkSession.sessionState.conf).map { provider => | ||
| val catalogManager = sparkSession.sessionState.catalogManager | ||
| val sessionOptions = DataSourceV2Utils.extractSessionConfigs( | ||
| source = provider, conf = sparkSession.sessionState.conf) | ||
| val pathsOption = if (paths.isEmpty) { | ||
| val pathsOption = if (updatedPaths.isEmpty) { | ||
| None | ||
| } else { | ||
| val objectMapper = new ObjectMapper() | ||
| Some("paths" -> objectMapper.writeValueAsString(paths.toArray)) | ||
| Some("paths" -> objectMapper.writeValueAsString(updatedPaths.toArray)) | ||
| } | ||
|
|
||
| val finalOptions = sessionOptions ++ extraOptions.originalMap ++ pathsOption | ||
|
|
@@ -281,9 +301,9 @@ class DataFrameReader private[sql](sparkSession: SparkSession) extends Logging { | |
| sparkSession, | ||
| DataSourceV2Relation.create(table, catalog, ident, dsOptions)) | ||
|
|
||
| case _ => loadV1Source(paths: _*) | ||
| case _ => loadV1Source(updatedPaths: _*) | ||
| } | ||
| }.getOrElse(loadV1Source(paths: _*)) | ||
| }.getOrElse(loadV1Source(updatedPaths: _*)) | ||
| } | ||
|
|
||
| private def loadV1Source(paths: String*) = { | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.