-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-51281][SQL] DataFrameWriterV2 should respect the path option #50040
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 6 commits
feff1e4
215a606
88299af
8f12984
d2cc6e5
f046b2e
8702883
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 |
|---|---|---|
|
|
@@ -5545,6 +5545,15 @@ object SQLConf { | |
| .booleanConf | ||
| .createWithDefault(false) | ||
|
|
||
| val LEGACY_DF_WRITER_V2_IGNORE_PATH_OPTION = | ||
| buildConf("spark.sql.legacy.dataFrameWriterV2IgnorePathOption") | ||
| .internal() | ||
| .doc("When set to true, DataFrameWriterV2 ignores the 'path' option and always write data " + | ||
| "to the default table location.") | ||
| .version("3.5.5") | ||
|
||
| .booleanConf | ||
| .createWithDefault(false) | ||
|
|
||
| /** | ||
| * Holds information about keys that have been deprecated. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,10 +28,12 @@ import org.apache.spark.sql.Column | |
| import org.apache.spark.sql.catalyst.analysis.{NoSuchTableException, UnresolvedFunction, UnresolvedIdentifier, UnresolvedRelation} | ||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression, Literal} | ||
| import org.apache.spark.sql.catalyst.plans.logical._ | ||
| import org.apache.spark.sql.catalyst.util.CaseInsensitiveMap | ||
| import org.apache.spark.sql.connector.catalog.TableWritePrivilege._ | ||
| import org.apache.spark.sql.connector.expressions._ | ||
| import org.apache.spark.sql.errors.QueryCompilationErrors | ||
| import org.apache.spark.sql.execution.QueryExecution | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.types.IntegerType | ||
|
|
||
| /** | ||
|
|
@@ -146,25 +148,30 @@ final class DataFrameWriterV2[T] private[sql](table: String, ds: Dataset[T]) | |
|
|
||
| /** @inheritdoc */ | ||
| override def create(): Unit = { | ||
| val tableSpec = UnresolvedTableSpec( | ||
| properties = properties.toMap, | ||
| provider = provider, | ||
| optionExpression = OptionList(Seq.empty), | ||
| location = None, | ||
| comment = None, | ||
| collation = None, | ||
| serde = None, | ||
| external = false) | ||
| runCommand( | ||
| CreateTableAsSelect( | ||
| UnresolvedIdentifier(tableName), | ||
| partitioning.getOrElse(Seq.empty) ++ clustering, | ||
| logicalPlan, | ||
| tableSpec, | ||
| buildTableSpec(), | ||
| options.toMap, | ||
| false)) | ||
| } | ||
|
|
||
| private def buildTableSpec(): UnresolvedTableSpec = { | ||
| val ignorePathOption = sparkSession.sessionState.conf.getConf( | ||
| SQLConf.LEGACY_DF_WRITER_V2_IGNORE_PATH_OPTION) | ||
| UnresolvedTableSpec( | ||
| properties = properties.toMap, | ||
| provider = provider, | ||
| optionExpression = OptionList(Seq.empty), | ||
| location = if (ignorePathOption) None else CaseInsensitiveMap(options.toMap).get("path"), | ||
|
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 the actual change. |
||
| comment = None, | ||
| collation = None, | ||
| serde = None, | ||
| external = false) | ||
| } | ||
|
|
||
| /** @inheritdoc */ | ||
| override def replace(): Unit = { | ||
| internalReplace(orCreate = false) | ||
|
|
@@ -212,20 +219,11 @@ final class DataFrameWriterV2[T] private[sql](table: String, ds: Dataset[T]) | |
| } | ||
|
|
||
| private def internalReplace(orCreate: Boolean): Unit = { | ||
| val tableSpec = UnresolvedTableSpec( | ||
| properties = properties.toMap, | ||
| provider = provider, | ||
| optionExpression = OptionList(Seq.empty), | ||
| location = None, | ||
| comment = None, | ||
| collation = None, | ||
| serde = None, | ||
| external = false) | ||
| runCommand(ReplaceTableAsSelect( | ||
| UnresolvedIdentifier(tableName), | ||
| partitioning.getOrElse(Seq.empty) ++ clustering, | ||
| logicalPlan, | ||
| tableSpec, | ||
| buildTableSpec(), | ||
| writeOptions = options.toMap, | ||
| orCreate = orCreate)) | ||
| } | ||
|
|
||
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.
Could we fix the bug? It means users might already use the 'path' option.
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.
I got it. The bug exists about 3 years. So let the bug as a legacy behavior looks better.