-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-37478][SQL][TESTS] Unify v1 and v2 DROP NAMESPACE tests #34819
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("DropNamespace: Namespace does not exist") { | ||
| // Namespace $catalog.unknown does not exist. | ||
| val message = intercept[AnalysisException] { | ||
| sql(s"DROP DATABASE $catalog.unknown") | ||
| }.getMessage | ||
| assert(message.contains(s"Database 'unknown' not found")) |
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 test in V1 throws NoSuchDatabaseException that is different from NoSuchNamespaceException in V2. So it is separated into V1 and V2 Suite instead of placed in SuiteBase.
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.
do these 2 exceptions both extends AnalysisException? We can check that instead.
| test("DropNamespace: Namespace does not exist") { | ||
| // Namespace $catalog.unknown does not exist. | ||
| val message = intercept[AnalysisException] { | ||
| sql(s"DROP DATABASE $catalog.unknown") | ||
| }.getMessage | ||
| assert(message.contains(s"Namespace 'unknown' not found")) |
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 test in V2 throws NoSuchNamespaceException that is different from NoSuchDatabaseException in V1. So it is separated into V1 and V2 Suite instead of placed in SuiteBase.
| def assertDropFails(): Unit = { | ||
| val e = intercept[AnalysisException] { | ||
| sql(s"DROP NAMESPACE $catalog.ns") | ||
| } | ||
| assert(e.getMessage.contains("Database ns is not empty. One or more tables 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.
The exception and message of test drop non-empty namespace with a non-cascading mode that throw in V1 DropNamespaceSuite are different from V2 DropNamespaceSuite.
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.
Can we unify it? We don't need to block this PR and can do this later.
| def assertDropFails(): Unit = { | ||
| val e = intercept[SparkException] { | ||
| sql(s"DROP NAMESPACE $catalog.ns") | ||
| } | ||
| assert(e.getMessage.contains("Cannot drop a non-empty namespace: ns")) |
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.
The exception and message of test drop non-empty namespace with a non-cascading mode that throw in V1 DropNamespaceSuite are different from V2 DropNamespaceSuite.
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.
We can follow DescribeNamespaceSuiteBase and add a method to abstract out the differences in the error message.
| trait DropNamespaceSuiteBase extends command.DropNamespaceSuiteBase { | ||
| override protected def builtinTopNamespaces: Seq[String] = Seq("default") | ||
|
|
||
| test("DropNamespace: drop default 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.
default namespace does not exist in V2, test for V1 and Hive only.
|
@MaxGekk, @cloud-fan, @imback82 Could you take a look? Many thanks! |
|
Kubernetes integration test starting |
|
Kubernetes integration test status failure |
| protected def builtinTopNamespaces: Seq[String] = Seq.empty | ||
| protected def isCasePreserving: Boolean = true | ||
|
|
||
| protected def checkNamespace(sqlText: String, expected: Seq[String]) = { |
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.
since we don't need the sqlText parameter, as it's always SHOW NAMESPACES IN $catalog
|
Test build #145948 has finished for PR 34819 at commit
|
|
ping @cloud-fan, updated as your reviews. Could you take a look? Thanks! |
|
Kubernetes integration test starting |
|
Kubernetes integration test status failure |
|
|
||
| protected def builtinTopNamespaces: Seq[String] = Seq.empty | ||
| protected def isCasePreserving: Boolean = true | ||
| protected def assertDropFails |
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.
| protected def assertDropFails | |
| protected def assertDropFails(): Unit |
| test("DropNamespace: Namespace does not exist") { | ||
| // Namespace $catalog.unknown does not exist. | ||
| val message = intercept[AnalysisException] { | ||
| sql(s"DROP DATABASE $catalog.unknown") |
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.
Can we consistently use DROP NAMESPACE in the tests?
| checkNamespace(Seq("ns") ++ builtinTopNamespaces) | ||
|
|
||
| // $catalog.ns.table is present, thus $catalog.ns cannot be dropped. | ||
| assertDropFails |
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.
| assertDropFails | |
| assertDropFails() |
| checkNamespace(builtinTopNamespaces) | ||
| } | ||
|
|
||
| test("DropNamespace: drop namespace with case sensitivity") { |
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.
nit: this is the drop namespace test suite, do we really need to put the DropNamespace: prefix in all the test names here?
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.
yeah, will remove it. Thanks!
| */ | ||
| class DropNamespaceSuite extends command.DropNamespaceSuiteBase with CommandSuiteBase { | ||
| override protected def assertDropFails(): Unit = { | ||
| val e = intercept[SparkException] { |
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.
Can we leave a TODO to unify the error? I think both v1 and v2 commands should throw AnalysisException, and the error message should only have one difference between v1 and v2: Cannot drop a non-empty namespace: ... vs Cannot drop a non-empty database: ...
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.
If you think the change is small, you can also include it in this PR
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.
I will create a follow-up PR for this, it's ok? @cloud-fan
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.
Can we leave a TODO to unify the error? I think both v1 and v2 commands should throw
AnalysisException, and the error message should only have one difference between v1 and v2:Cannot drop a non-empty namespace: ...vsCannot drop a non-empty database: ...
The error message of Hive External Catalog test is Database ns is not empty. One or more tables exist., which is identical to the error message of v1. So we should keep this and remove TODO, or we should unify the error of v1, v2 test and then seperate the hive's one. Thanks. @cloud-fan @huaxingao
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.
can we change the v1 error message to match v2?
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.
yes, we can. After that, the test in Hive External Catalog would fail since it extends v1.DropNamespaceSuiteBase. So I think we should unify the error of v1, v2 test, and then create another one in Hive external catalog test that contains error message Database ns is not empty. One or more tables exist.. WDYT, @cloud-fan ?
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.
can we unify the error message everywhere? We can try-catch the error from hive catalog and re-throw it with a different error message?
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.
yeah, I think we can. I'll try. Thank you, @cloud-fan. 😃
cloud-fan
left a comment
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.
LGTM except for a few comments
|
Test build #145971 has finished for PR 34819 at commit
|
|
Kubernetes integration test starting |
|
Kubernetes integration test status failure |
|
Test build #145980 has finished for PR 34819 at commit
|
|
thanks, merging to master! |
|
Thank you! |
### What changes were proposed in this pull request? According to [#cmt](#34819 (comment)), unify the error of v1, v2 and hive external catalog in DROP NAMESPACE tests. ### Why are the changes needed? Currently, v1 and hive external catalog command throw `AnalysisException`, while v2 command throws `SparkException`. The error messages of v1 and hive catalog are also completely different from v2. So this PR is for unifying those errors to `AnalysisException`. The error message will have one difference between v1/hive and v2: `Cannot drop a non-empty database: ...` vs `Cannot drop a non-empty namespace: ...` ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? v1/v2 and Hive v1 DropNamespaceSuite: ```$ build/sbt -Phive-2.3 -Phive-thriftserver "test:testOnly *DropNamespaceSuite"``` Closes #35007 from dchvn/unify_dropnamespace_error. Authored-by: dch nguyen <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
What changes were proposed in this pull request?
DROP NAMESPACEparsing tests fromDDLParserSuitetoDropNamespaceParserSuitecommand.DropNamespaceSuiteBasethat is parent ofv1.DropNamespaceSuiteBaseandv2.DropNamespaceSuite.v1.DropNamespaceSuiteBasethat is parent ofv1.DropNamespaceSuiteandhive.execution.command.DropNamespaceSuite.DROP NAMESPACEfromDDLSuiteand v2 tests fromDataSourceV2SQLSuiteto the common traitDropNamespaceSuiteBase.DescribeNamespaceSuiteBasetov1.DropNamespaceSuiteBaseandv2.DropNamespaceSuiteThe changes follow the approach of #30287
Why are the changes needed?
DROP NAMESPACEtests for both DSv1/Hive DSv1 and DSv2Does this PR introduce any user-facing change?
No
How was this patch tested?
v1/v2 and Hive v1 DropNamespaceSuite:
$ build/sbt -Phive-2.3 -Phive-thriftserver "test:testOnly *DropNamespaceSuite"