cloud-fan commented on a change in pull request #35271:
URL: https://github.com/apache/spark/pull/35271#discussion_r791324763



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalog.scala
##########
@@ -282,12 +282,12 @@ class JDBCTableCatalog extends TableCatalog with 
SupportsNamespaces with Logging
       namespace: Array[String],
       cascade: Boolean): Boolean = namespace match {
     case Array(db) if namespaceExists(namespace) =>
-      if (listTables(Array(db)).nonEmpty) {
+      if (!cascade && listTables(Array(db)).nonEmpty) {

Review comment:
       `listTables` could be expensive. Can we try-catch the exception thrown 
by JDBC and detect the case when the schema/database is not empty?

##########
File path: sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala
##########
@@ -51,6 +51,9 @@ import org.apache.spark.sql.types._
 @DeveloperApi
 case class JdbcType(databaseTypeDefinition : String, jdbcNullType : Int)
 
+class NamespaceNotEmptyException(message: String, cause: Option[Throwable] = 
None)

Review comment:
       can we reuse the existing `NonEmptyNamespaceException`?

##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala
##########
@@ -215,6 +215,7 @@ private object PostgresDialect extends JdbcDialect with 
SQLConfHelper {
           // https://www.postgresql.org/docs/14/errcodes-appendix.html
           case "42P07" => throw new IndexAlreadyExistsException(message, cause 
= Some(e))
           case "42704" => throw new NoSuchIndexException(message, cause = 
Some(e))
+          case "2BP01" => throw new NamespaceNotEmptyException(message, cause 
= Some(e))

Review comment:
       how about other dialects?




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to