diff --git a/core/src/main/resources/error/error-classes.json b/core/src/main/resources/error/error-classes.json index 32083c23df8c..f8c599566bea 100644 --- a/core/src/main/resources/error/error-classes.json +++ b/core/src/main/resources/error/error-classes.json @@ -656,6 +656,11 @@ ], "sqlState" : "42000" }, + "INVALID_EMPTY_LOCATION" : { + "message" : [ + "The location name cannot be empty string, but `` was given." + ] + }, "INVALID_FIELD_NAME" : { "message" : [ "Field name is invalid: is not a struct." @@ -1161,11 +1166,6 @@ } } }, - "UNSUPPORTED_EMPTY_LOCATION" : { - "message" : [ - "Unsupported empty location." - ] - }, "UNSUPPORTED_FEATURE" : { "message" : [ "The feature is not supported:" diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala index 828f52fe71d0..c68d252f6175 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala @@ -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 = { diff --git a/sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala b/sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala index d00d07150b0b..d7e26b04ce47 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala @@ -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) @@ -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.get) } CreateDatabaseCommand(name, c.ifNotExists, location, comment, newProperties) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala index 88dbe49c5af6..34dd1fb9c393 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala @@ -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, @@ -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.get) } val finalProperties = properties.get(SupportsNamespaces.PROP_LOCATION).map { loc => properties + (SupportsNamespaces.PROP_LOCATION -> makeQualifiedDBObjectPath(loc)) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/AlterNamespaceSetLocationSuiteBase.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/AlterNamespaceSetLocationSuiteBase.scala index 653a6d918918..5b78665d878e 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/AlterNamespaceSetLocationSuiteBase.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/AlterNamespaceSetLocationSuiteBase.scala @@ -51,8 +51,8 @@ trait AlterNamespaceSetLocationSuiteBase extends QueryTest with DDLCommandTestUt exception = intercept[SparkIllegalArgumentException] { sql(sqlText) }, - errorClass = "UNSUPPORTED_EMPTY_LOCATION", - parameters = Map.empty) + errorClass = "INVALID_EMPTY_LOCATION", + parameters = Map("location" -> "")) } } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CreateNamespaceSuiteBase.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CreateNamespaceSuiteBase.scala index 1f0c3513dc93..e90469c29a59 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CreateNamespaceSuiteBase.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CreateNamespaceSuiteBase.scala @@ -74,8 +74,8 @@ trait CreateNamespaceSuiteBase extends QueryTest with DDLCommandTestUtils { exception = intercept[SparkIllegalArgumentException] { sql(sqlText) }, - errorClass = "UNSUPPORTED_EMPTY_LOCATION", - parameters = Map.empty) + errorClass = "INVALID_EMPTY_LOCATION", + parameters = Map("location" -> "")) val uri = new Path(path).toUri sql(s"CREATE NAMESPACE $ns LOCATION '$uri'") // Make sure the location is qualified.