Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/15996#discussion_r94006226
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/DataFrameWriter.scala ---
@@ -373,39 +378,50 @@ final class DataFrameWriter[T] private[sql](ds:
Dataset[T]) {
case (true, SaveMode.ErrorIfExists) =>
throw new AnalysisException(s"Table $tableIdent already exists.")
- case _ =>
- val existingTable = if (tableExists) {
-
Some(df.sparkSession.sessionState.catalog.getTableMetadata(tableIdent))
- } else {
- None
+ case (true, SaveMode.Overwrite) =>
+ // Get all input data source relations of the query.
+ val srcRelations = df.logicalPlan.collect {
+ case LogicalRelation(src: BaseRelation, _, _) => src
}
- val storage = if (tableExists) {
- existingTable.get.storage
- } else {
- DataSource.buildStorageFormatFromOptions(extraOptions.toMap)
- }
- val tableType = if (tableExists) {
- existingTable.get.tableType
- } else if (storage.locationUri.isDefined) {
- CatalogTableType.EXTERNAL
- } else {
- CatalogTableType.MANAGED
+ EliminateSubqueryAliases(catalog.lookupRelation(tableIdentWithDB))
match {
+ // Only do the check if the table is a data source table (the
relation is a BaseRelation).
+ case LogicalRelation(dest: BaseRelation, _, _) =>
+ if (srcRelations.contains(dest)) {
--- End diff --
Nit:
```Scala
case LogicalRelation(dest: BaseRelation, _, _) if
(srcRelations.contains(dest)) =>
throw new AnalysisException(...
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]