Skip to content

Conversation

@dchvn
Copy link
Contributor

@dchvn dchvn commented Dec 6, 2021

What changes were proposed in this pull request?

  1. Move the DROP NAMESPACE parsing tests from DDLParserSuite to DropNamespaceParserSuite
  2. Define the class command.DropNamespaceSuiteBase that is parent of v1.DropNamespaceSuiteBase and v2.DropNamespaceSuite.
  3. Define the class v1.DropNamespaceSuiteBase that is parent of v1.DropNamespaceSuite and hive.execution.command.DropNamespaceSuite.
  4. Place the v1 tests for DROP NAMESPACE from DDLSuite and v2 tests from DataSourceV2SQLSuite to the common trait DropNamespaceSuiteBase.
  5. Move TODO test from DescribeNamespaceSuiteBase to v1.DropNamespaceSuiteBase and v2.DropNamespaceSuite

The changes follow the approach of #30287

Why are the changes needed?

  1. The unification will allow to run common DROP NAMESPACE tests for both DSv1/Hive DSv1 and DSv2
  2. We can detect missing features and differences between DSv1 and DSv2 implementations.

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"

@github-actions github-actions bot added the SQL label Dec 6, 2021
Comment on lines 62 to 67
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"))
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Comment on lines 49 to 54
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"))
Copy link
Contributor Author

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.

Comment on lines 46 to 50
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"))
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Comment on lines 33 to 37
def assertDropFails(): Unit = {
val e = intercept[SparkException] {
sql(s"DROP NAMESPACE $catalog.ns")
}
assert(e.getMessage.contains("Cannot drop a non-empty namespace: ns"))
Copy link
Contributor Author

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.

Copy link
Contributor

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") {
Copy link
Contributor Author

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.

@dchvn
Copy link
Contributor Author

dchvn commented Dec 6, 2021

@MaxGekk, @cloud-fan, @imback82 Could you take a look? Many thanks!

@dchvn dchvn changed the title [SPARK-33849][SQL][TESTS] Unify v1 and v2 DROP NAMESPACE tests [SPARK-37478][SQL][TESTS] Unify v1 and v2 DROP NAMESPACE tests Dec 6, 2021
@SparkQA
Copy link

SparkQA commented Dec 6, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50423/

@SparkQA
Copy link

SparkQA commented Dec 6, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50423/

protected def builtinTopNamespaces: Seq[String] = Seq.empty
protected def isCasePreserving: Boolean = true

protected def checkNamespace(sqlText: String, expected: Seq[String]) = {
Copy link
Contributor

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

@SparkQA
Copy link

SparkQA commented Dec 6, 2021

Test build #145948 has finished for PR 34819 at commit c60e31b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dchvn
Copy link
Contributor Author

dchvn commented Dec 7, 2021

ping @cloud-fan, updated as your reviews. Could you take a look? Thanks!

@SparkQA
Copy link

SparkQA commented Dec 7, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50446/

@SparkQA
Copy link

SparkQA commented Dec 7, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50446/


protected def builtinTopNamespaces: Seq[String] = Seq.empty
protected def isCasePreserving: Boolean = true
protected def assertDropFails
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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")
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assertDropFails
assertDropFails()

checkNamespace(builtinTopNamespaces)
}

test("DropNamespace: drop namespace with case sensitivity") {
Copy link
Contributor

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?

Copy link
Contributor Author

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] {
Copy link
Contributor

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: ...

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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: ...

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

Copy link
Contributor

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?

Copy link
Contributor Author

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 ?

Copy link
Contributor

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?

Copy link
Contributor Author

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. 😃

Copy link
Contributor

@cloud-fan cloud-fan left a 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

@SparkQA
Copy link

SparkQA commented Dec 7, 2021

Test build #145971 has finished for PR 34819 at commit 3970d4d.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 7, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50455/

@SparkQA
Copy link

SparkQA commented Dec 7, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/50455/

@SparkQA
Copy link

SparkQA commented Dec 7, 2021

Test build #145980 has finished for PR 34819 at commit 980e2be.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in f6e2e65 Dec 7, 2021
@dchvn
Copy link
Contributor Author

dchvn commented Dec 8, 2021

Thank you!

cloud-fan pushed a commit that referenced this pull request Dec 30, 2021
### 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants