Skip to content
Closed
10 changes: 5 additions & 5 deletions core/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,11 @@
],
"sqlState" : "42000"
},
"INVALID_EMPTY_LOCATION" : {
"message" : [
"The location name cannot be empty string or null, but `<location>` was given."
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a test when the location is NULL. I just worry that parameters substitution might not handle this. Please, check this.

Copy link
Contributor Author

@itholic itholic Nov 22, 2022

Choose a reason for hiding this comment

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

Good catch.
I tried to add a test with NULL, but it complains [PARSE_SYNTAX_ERROR] rather than [INVALID_EMPTY_LOCATION].
Let me exclude the "null" from the error message.

]
},
"INVALID_FIELD_NAME" : {
"message" : [
"Field name <fieldName> is invalid: <path> is not a struct."
Expand Down Expand Up @@ -1105,11 +1110,6 @@
}
}
},
"UNSUPPORTED_EMPTY_LOCATION" : {
"message" : [
"Unsupported empty location."
]
},
"UNSUPPORTED_FEATURE" : {
"message" : [
"The feature is not supported:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2799,10 +2799,10 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase {
"size" -> elementSize.toString))
}

def unsupportedEmptyLocationError(): SparkIllegalArgumentException = {
def invalidEmptyLocationError(location: String): SparkIllegalArgumentException = {
new SparkIllegalArgumentException(
errorClass = "UNSUPPORTED_EMPTY_LOCATION",
messageParameters = Map.empty)
errorClass = "INVALID_EMPTY_LOCATION",
messageParameters = Map("location" -> location))
}

def malformedProtobufMessageDetectedInMessageParsingError(e: Throwable): Throwable = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class ResolveSessionCatalog(val catalogManager: CatalogManager)

case SetNamespaceLocation(DatabaseInSessionCatalog(db), location) if conf.useV1Command =>
if (StringUtils.isEmpty(location)) {
throw QueryExecutionErrors.unsupportedEmptyLocationError()
throw QueryExecutionErrors.invalidEmptyLocationError(location)
}
AlterDatabaseSetLocationCommand(db, location)

Expand Down Expand Up @@ -243,7 +243,7 @@ class ResolveSessionCatalog(val catalogManager: CatalogManager)
val location = c.properties.get(SupportsNamespaces.PROP_LOCATION)
val newProperties = c.properties -- CatalogV2Util.NAMESPACE_RESERVED_PROPERTIES
if (location.isDefined && location.get.isEmpty) {
throw QueryExecutionErrors.unsupportedEmptyLocationError()
throw QueryExecutionErrors.invalidEmptyLocationError(location)
}
CreateDatabaseCommand(name, c.ifNotExists, location, comment, newProperties)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class DataSourceV2Strategy(session: SparkSession) extends Strategy with Predicat

case SetNamespaceLocation(ResolvedNamespace(catalog, ns), location) =>
if (StringUtils.isEmpty(location)) {
throw QueryExecutionErrors.unsupportedEmptyLocationError()
throw QueryExecutionErrors.invalidEmptyLocationError(location)
}
AlterNamespaceSetPropertiesExec(
catalog.asNamespaceCatalog,
Expand All @@ -369,7 +369,7 @@ class DataSourceV2Strategy(session: SparkSession) extends Strategy with Predicat
case CreateNamespace(ResolvedNamespace(catalog, ns), ifNotExists, properties) =>
val location = properties.get(SupportsNamespaces.PROP_LOCATION)
if (location.isDefined && location.get.isEmpty) {
throw QueryExecutionErrors.unsupportedEmptyLocationError()
throw QueryExecutionErrors.invalidEmptyLocationError(location)
}
val finalProperties = properties.get(SupportsNamespaces.PROP_LOCATION).map { loc =>
properties + (SupportsNamespaces.PROP_LOCATION -> makeQualifiedDBObjectPath(loc))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ trait AlterNamespaceSetLocationSuiteBase extends QueryTest with DDLCommandTestUt
exception = intercept[SparkIllegalArgumentException] {
sql(sqlText)
},
errorClass = "UNSUPPORTED_EMPTY_LOCATION",
errorClass = "INVALID_EMPTY_LOCATION",
parameters = Map.empty)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ trait CreateNamespaceSuiteBase extends QueryTest with DDLCommandTestUtils {
exception = intercept[SparkIllegalArgumentException] {
sql(sqlText)
},
errorClass = "UNSUPPORTED_EMPTY_LOCATION",
errorClass = "INVALID_EMPTY_LOCATION",
parameters = Map.empty)
val uri = new Path(path).toUri
sql(s"CREATE NAMESPACE $ns LOCATION '$uri'")
Expand Down