-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-37804][SQL][TEST] Unify v1 and v2 CREATE NAMESPACE tests #35093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } | ||
| } | ||
|
|
||
| test("SPARK-37456: Location in CreateNamespace should be qualified") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be covered in test("namespace with location") for all catalogs.
| sql(s"CREATE NAMESPACE IF NOT EXISTS $ns") | ||
|
|
||
| // The namespace already exists, so this should fail. | ||
| // TODO: non-Hive catalogs throw NamespaceAlreadyExistsException. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new TODO similar to // TODO: HiveExternalCatalog throws DatabaseAlreadyExistsException. Basically, hive catalog throws a different exception (and a slightly different message, requiring alreadyExistErrorMessage).
|
cc @cloud-fan @MaxGekk. Happy New Year! |
| */ | ||
| class CreateNamespaceSuite extends v1.CreateNamespaceSuiteBase with CommandSuiteBase { | ||
| override def commandVersion: String = super[CreateNamespaceSuiteBase].commandVersion | ||
| override def alreadyExistErrorMessage: String = s"$notFoundMsgPrefix $namespace already exists" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Hive, there is no ' ' around the namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this exception thrown by hive? or by Spark?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is thrown by Hive: org.apache.hadoop.hive.metastore.api.AlreadyExistsException: Database db already exists and wrapped to AnalysisException here:
spark/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala
Lines 111 to 112 in 9c6f3fb
| throw new AnalysisException( | |
| e.getClass.getCanonicalName + ": " + e.getMessage, cause = Some(e)) |
| override def namespace: String = "db" | ||
| override def notFoundMsgPrefix: String = "Database" | ||
|
|
||
| test("Create namespace using default warehouse path") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only difference b/w v1 and v2 catalog.
| trait CreateNamespaceSuiteBase extends QueryTest with DDLCommandTestUtils { | ||
| import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._ | ||
|
|
||
| override val command = "Create NAMESPACE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| override val command = "Create NAMESPACE" | |
| override val command = "CREATE NAMESPACE" |
| assert(!path.startsWith("file:/")) | ||
|
|
||
| val e = intercept[IllegalArgumentException] { | ||
| sql(s"CREATE NAMESPACE $ns Location ''") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| sql(s"CREATE NAMESPACE $ns Location ''") | |
| sql(s"CREATE NAMESPACE $ns LOCATION ''") |
| assert(e.getMessage.contains("Can not create a Path from an empty string")) | ||
|
|
||
| val uri = new Path(path).toUri | ||
| sql(s"CREATE NAMESPACE $ns Location '$uri'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| sql(s"CREATE NAMESPACE $ns Location '$uri'") | |
| sql(s"CREATE NAMESPACE $ns LOCATION '$uri'") |
| } | ||
| } | ||
|
|
||
| test("test handling of 'IF NOT EXIST'") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we merge this test case to the one above? It's just adding sql(s"CREATE NAMESPACE IF NOT EXISTS $ns") to the end of the above test case
|
thanks, merging to master! |
### What changes were proposed in this pull request? This PR proposes to use V2 commands as default as outlined in [SPARK-36588](https://issues.apache.org/jira/browse/SPARK-36588), and this PR migrates `CREATE NAMESPACE` to use v2 command by default. Note that the work to tests covering both v1/v2 were done in #35093. ### Why are the changes needed? It's been a while since we introduced the v2 commands, and it seems reasonable to use v2 commands by default even for the session catalog, with a legacy config to fall back to the v1 commands. ### Does this PR introduce _any_ user-facing change? The error message will be slightly different if namespace already exists when v2 command is run against v1 catalog: v1 command: `Database 'db' already exists"` vs. v2 command: `Namespace 'db' already exists"` Also, the error message will be slightly different if namespace already exists when v1 command is run against Hive catalog: Before: `Database db already exists"` vs. After: `Database 'db' already exists"` ### How was this patch tested? Existing *CreateNamespaceSuite tests cover this PR's change. Closes #35113 from imback82/migrate_create_namespace. Authored-by: Terry Kim <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
### What changes were proposed in this pull request? This PR proposes to use V2 commands as default as outlined in [SPARK-36588](https://issues.apache.org/jira/browse/SPARK-36588), and this PR migrates `CREATE NAMESPACE` to use v2 command by default. Note that the work to tests covering both v1/v2 were done in apache#35093. ### Why are the changes needed? It's been a while since we introduced the v2 commands, and it seems reasonable to use v2 commands by default even for the session catalog, with a legacy config to fall back to the v1 commands. ### Does this PR introduce _any_ user-facing change? The error message will be slightly different if namespace already exists when v2 command is run against v1 catalog: v1 command: `Database 'db' already exists"` vs. v2 command: `Namespace 'db' already exists"` Also, the error message will be slightly different if namespace already exists when v1 command is run against Hive catalog: Before: `Database db already exists"` vs. After: `Database 'db' already exists"` ### How was this patch tested? Existing *CreateNamespaceSuite tests cover this PR's change. Closes apache#35113 from imback82/migrate_create_namespace. Authored-by: Terry Kim <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
What changes were proposed in this pull request?
CREATE NAMESPACEparsing tests toCreateNamespaceParserSuite.CREATE NAMESPACEtests into one traitorg.apache.spark.sql.execution.command.CreateNamespaceSuiteBase, and put datasource specific tests to thev1.CreateNamespaceSuiteandv2.CreateNamespaceSuite.The changes follow the approach of #30287.
Why are the changes needed?
CREATE NAMESPACEtests for both DSv1/Hive DSv1 and DSv2Does this PR introduce any user-facing change?
No
How was this patch tested?
Existing unit tests and new tests.