Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8240,6 +8240,12 @@
],
"sqlState" : "42K0G"
},
"UNABLE_TO_CREATE_DATABASE" : {
"message" : [
"Unable to create database <name> as failed to create its directory <locationUri>."
],
"sqlState" : "58030"
},
"UNABLE_TO_FETCH_HIVE_TABLES" : {
"message" : [
"Unable to fetch tables of Hive database: <dbName>."
Expand Down Expand Up @@ -10808,11 +10814,6 @@
"<fieldCannotBeNullMsg>"
]
},
"_LEGACY_ERROR_TEMP_2033" : {
"message" : [
"Unable to create database <name> as failed to create its directory <locationUri>."
]
},
"_LEGACY_ERROR_TEMP_2034" : {
"message" : [
"Unable to drop database <name> as failed to delete its directory <locationUri>."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE
def unableToCreateDatabaseAsFailedToCreateDirectoryError(
dbDefinition: CatalogDatabase, e: IOException): Throwable = {
new SparkException(
errorClass = "_LEGACY_ERROR_TEMP_2033",
errorClass = "UNABLE_TO_CREATE_DATABASE",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error condition is more general than the actual failure path here. Why not UNABLE_TO_CREATE_DATABASE_DIRECTORY?

(Unfortunately, the code still uses "error class" in many places to refer to what is correctly called an "error condition".)

messageParameters = Map(
"name" -> dbDefinition.name,
"locationUri" -> dbDefinition.locationUri.toString()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.sql.catalyst.catalog

import org.apache.spark.SparkException
import org.apache.spark.util.Utils

/** Test suite for the [[InMemoryCatalog]]. */
class InMemoryCatalogSuite extends ExternalCatalogSuite {
Expand All @@ -28,4 +30,24 @@ class InMemoryCatalogSuite extends ExternalCatalogSuite {
override def newEmptyCatalog(): ExternalCatalog = new InMemoryCatalog
}

test("createDatabase throws UNABLE_TO_CREATE_DATABASE when mkdirs fails") {
val parentFile = Utils.createTempDir()
// A path nested under an existing regular file: the filesystem cannot create it as a
// directory, so `fs.mkdirs` throws an IOException.
val blockingFile = new java.io.File(parentFile, "not-a-directory")
java.nio.file.Files.createFile(blockingFile.toPath)
val dbLocation = new java.io.File(blockingFile, "db_dir").toURI

val catalog = new InMemoryCatalog
val db = CatalogDatabase("unreachable_db", "db", dbLocation, Map.empty)
checkError(
exception = intercept[SparkException] {
catalog.createDatabase(db, ignoreIfExists = false)
},
condition = "UNABLE_TO_CREATE_DATABASE",
parameters = Map(
"name" -> "unreachable_db",
"locationUri" -> dbLocation.toString))
}

}