Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/20886#discussion_r179008019
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
---
@@ -298,15 +299,32 @@ class SessionCatalog(
makeQualifiedPath(tableDefinition.storage.locationUri.get)
tableDefinition.copy(
storage = tableDefinition.storage.copy(locationUri =
Some(qualifiedTableLocation)),
- identifier = TableIdentifier(table, Some(db)))
+ identifier = tableIdentifier)
} else {
- tableDefinition.copy(identifier = TableIdentifier(table, Some(db)))
+ tableDefinition.copy(identifier = tableIdentifier)
}
requireDbExists(db)
+ if (!ignoreIfExists) {
+ validateTableLocation(newTableDefinition)
+ }
externalCatalog.createTable(newTableDefinition, ignoreIfExists)
}
+ def validateTableLocation(table: CatalogTable): Unit = {
+ // SPARK-19724: the default location of a managed table should be
non-existent or empty.
+ if (table.tableType == CatalogTableType.MANAGED &&
!conf.allowNonemptyManagedTableLocation) {
+ val tableLocation =
+ new
Path(table.storage.locationUri.getOrElse(defaultTablePath(table.identifier)))
+ val fs = tableLocation.getFileSystem(hadoopConf)
+
+ if (fs.exists(tableLocation) &&
fs.listStatus(tableLocation).nonEmpty) {
+ throw new AnalysisException(s"Can not create the managed
table('${table.identifier}')" +
--- End diff --
`Can not` -> `Not allowed to`
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]