cloud-fan commented on a change in pull request #26476: [SPARK-29851][SQL] V2
catalog: Change default behavior of dropping namespace to cascade
URL: https://github.com/apache/spark/pull/26476#discussion_r345058517
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DropNamespaceExec.scala
##########
@@ -21,26 +21,35 @@ import org.apache.spark.SparkException
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
import org.apache.spark.sql.catalyst.expressions.Attribute
-import org.apache.spark.sql.connector.catalog.SupportsNamespaces
+import org.apache.spark.sql.connector.catalog.{CatalogPlugin,
SupportsNamespaces}
/**
* Physical plan node for dropping a namespace.
*/
case class DropNamespaceExec(
- catalog: SupportsNamespaces,
+ catalog: CatalogPlugin,
namespace: Seq[String],
ifExists: Boolean,
cascade: Boolean)
extends V2CommandExec {
override protected def run(): Seq[InternalRow] = {
+ import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+
+ val nsCatalog = catalog.asNamespaceCatalog
val ns = namespace.toArray
- if (catalog.namespaceExists(ns)) {
- try {
- catalog.dropNamespace(ns)
- } catch {
- case e: IllegalStateException if cascade =>
+ if (nsCatalog.namespaceExists(ns)) {
+ // The default behavior of `SupportsNamespace.dropNamespace()` is
cascading,
+ // so make sure the namespace to drop is empty.
+ if (!cascade) {
+ if (catalog.asTableCatalog.listTables(ns).nonEmpty
+ || nsCatalog.listNamespaces(ns).nonEmpty) {
throw new SparkException(
- "Cascade option for droping namespace is not supported in V2
catalog", e)
+ s"Cannot drop a non-empty namespace: ${namespace.quoted}.")
Review comment:
nit: maybe better to mention that users can specify the CASCADE option to
drop everything.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]