Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/15996#discussion_r94008071
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/createDataSourceTables.scala
---
@@ -134,146 +133,38 @@ case class CreateDataSourceTableAsSelectCommand(
assert(table.provider.isDefined)
assert(table.schema.isEmpty)
- val provider = table.provider.get
val sessionState = sparkSession.sessionState
val db =
table.identifier.database.getOrElse(sessionState.catalog.getCurrentDatabase)
val tableIdentWithDB = table.identifier.copy(database = Some(db))
val tableName = tableIdentWithDB.unquotedString
- var createMetastoreTable = false
- // We may need to reorder the columns of the query to match the
existing table.
- var reorderedColumns = Option.empty[Seq[NamedExpression]]
- if (sessionState.catalog.tableExists(tableIdentWithDB)) {
- // Check if we need to throw an exception or just return.
- mode match {
- case SaveMode.ErrorIfExists =>
- throw new AnalysisException(s"Table $tableName already exists. "
+
- s"If you are using saveAsTable, you can set SaveMode to
SaveMode.Append to " +
- s"insert data into the table or set SaveMode to
SaveMode.Overwrite to overwrite" +
- s"the existing data. " +
- s"Or, if you are using SQL CREATE TABLE, you need to drop
$tableName first.")
- case SaveMode.Ignore =>
- // Since the table already exists and the save mode is Ignore,
we will just return.
- return Seq.empty[Row]
- case SaveMode.Append =>
- val existingTable =
sessionState.catalog.getTableMetadata(tableIdentWithDB)
+ val result = if (sessionState.catalog.tableExists(tableIdentWithDB)) {
+ assert(mode != SaveMode.Overwrite, "analyzer will drop the table to
overwrite it.")
--- End diff --
How about `s"Expect the table $tableName has been dropped when the save
mode is Overwrite"`?
---
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]