Skip to content

Conversation

@ulysses-you
Copy link
Contributor

What changes were proposed in this pull request?

V2 catalog support namespace, we should add withNamespace like withDatabase.

Why are the changes needed?

Make test easy.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Add UT.

@ulysses-you ulysses-you changed the title [SPARK-29772][test] Add withNamespace in SQLTestUtils [SPARK-29772][TESTS][SQL] Add withNamespace in SQLTestUtils Nov 6, 2019
@HyukjinKwon
Copy link
Member

ok to test

@HyukjinKwon
Copy link
Member

cc @cloud-fan and @rdblue

@SparkQA
Copy link

SparkQA commented Nov 7, 2019

Test build #113348 has finished for PR 26411 at commit 0d1bdf1.

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

namespaces.foreach { name =>
spark.sql(s"DROP NAMESPACE IF EXISTS $name CASCADE")
}
spark.sql(s"USE default")
Copy link
Contributor

Choose a reason for hiding this comment

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

We should set back to the default namespace of the current catalog. Not sure we have such a command yet, cc @imback82

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can get current catalog and set back like this code.

spark.sessionState.catalogManager.currentCatalog match {
        case supportNamespace: SupportsNamespaces =>
          supportNamespace.asNamespaceCatalog.defaultNamespace() match {
            case Array(name) => spark.sql(s"USE $name")
            case Array(name, _*) => spark.sql(s"USE $name")
            case _ => spark.sql("USE default")
          }
        case _ => spark.sql("USE default")
      }

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove it first, and assume the test code won't switch the current namespace.

Things can get complicated if the test code switches the current catalog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shall we add some doc to remind like this ?

If you will change current catalog, you should use this method carefully. This may be remove the wrong namespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

how about we add doc to remind callers to not switch current 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.

Updated, please take an another review.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should set back to the default namespace of the current catalog. Not sure we have such a command yet, cc @imback82

No, we don't have a such a command yet. Do you think it will be useful to have one?

This also reminds me about the behavior of dropping namespace. If you are trying to drop a namespace, which is set to the current namespace, this shouldn't be allowed right? We don't have a such a check yet, but I can add one if needed.

namespaces.foreach { name =>
spark.sql(s"DROP NAMESPACE IF EXISTS $name CASCADE")
}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
Copy link
Contributor

Choose a reason for hiding this comment

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

let's make it simple and not add complexity before we really need it.

For now all the caller sides do not switch current catalog/namespace. We can just drop the namespace here, with doc saying callers should not switch current catalog/namespace.


/**
* Drops namespace `namespace` after calling `f`.
* Note that, do not switch current catalog in `f`. It may remove the wrong namespace.
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that, if you switch current catalog/namespace in f, you should switch it back manually.

@SparkQA
Copy link

SparkQA commented Nov 7, 2019

Test build #113384 has finished for PR 26411 at commit b65c62d.

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

@SparkQA
Copy link

SparkQA commented Nov 7, 2019

Test build #113390 has finished for PR 26411 at commit 85bcb98.

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

@SparkQA
Copy link

SparkQA commented Nov 8, 2019

Test build #113411 has finished for PR 26411 at commit 9ee448a.

  • 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 7759f71 Nov 8, 2019
@ulysses-you
Copy link
Contributor Author

thanks for merging!

@ulysses-you ulysses-you deleted the Add-test-with-namespace branch July 1, 2022 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants