Skip to content

Conversation

@imback82
Copy link
Contributor

What changes were proposed in this pull request?

This PR exposes USE CATALOG/USE SQL commands as described in this SPIP

It also exposes currentCatalog in CatalogManager.

Finally, it changes SHOW NAMESPACES and SHOW TABLES to use the current catalog if no catalog is specified (instead of default catalog).

Why are the changes needed?

There is currently no mechanism to change current catalog/namespace thru SQL commands.

Does this PR introduce any user-facing change?

Yes, you can perform the following:

// Sets the current catalog to 'testcat'
spark.sql("USE CATALOG testcat")

// Sets the current catalog to 'testcat' and current namespace to 'ns1.ns2'.
spark.sql("USE ns1.ns2 IN testcat")

// Now, the following will use 'testcat' as the current catalog and 'ns1.ns2' as the current namespace.
spark.sql("SHOW NAMESPACES")

How was this patch tested?

Added new unit tests.

@imback82
Copy link
Contributor Author

cc: @cloud-fan @rdblue

@imback82
Copy link
Contributor Author

@cloud-fan / @rdblue This will probably be refactored after #25747 is merged, but I wanted to send this out to get some feedback on the usage of current catalog.

@SparkQA
Copy link

SparkQA commented Sep 12, 2019

Test build #110501 has finished for PR 25771 at commit 0d5246d.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.


test("UseCatalog: use catalog with v2 catalog") {
val catalogManager = spark.sessionState.catalogManager
assert(catalogManager.currentCatalog.name() == "session")
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 needs to be updated to "spark_session" right?

Copy link
Contributor Author

@imback82 imback82 left a comment

Choose a reason for hiding this comment

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

I will update this when #25747 is merged.

@SparkQA
Copy link

SparkQA commented Sep 17, 2019

Test build #110708 has finished for PR 25771 at commit 12685e0.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • public abstract class DelegatingCatalogExtension implements BaseSessionCatalog
  • class CatalogManager(conf: SQLConf, defaultSessionCatalog: BaseSessionCatalog) extends Logging

@SparkQA
Copy link

SparkQA commented Sep 17, 2019

Test build #110797 has started for PR 25771 at commit ad08096.

@shaneknapp
Copy link
Contributor

test this please

@SparkQA
Copy link

SparkQA commented Sep 17, 2019

Test build #110806 has finished for PR 25771 at commit ad08096.

  • This patch fails Java style tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • public abstract class DelegatingCatalogExtension implements CatalogExtension

@SparkQA
Copy link

SparkQA commented Sep 17, 2019

Test build #110822 has finished for PR 25771 at commit 1fb5751.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

assert(catalogManager.currentCatalog.name() == "session")
assert(catalogManager.currentNamespace === Array("default"))

// The following implicitly creates namespaces.
Copy link
Contributor

Choose a reason for hiding this comment

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

this reminds that we should have a CREATE NAMESPACE command. We can do it in followup.

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, I intend to do it right after this.

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 created a JIRA to track this along with SHOW CURRENT CATALOG and SHOW CURRENT NAMESPACE as you suggested.

@SparkQA
Copy link

SparkQA commented Sep 27, 2019

Test build #111474 has finished for PR 25771 at commit 1579f97.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Sep 28, 2019

Test build #111498 has finished for PR 25771 at commit b7c1e79.

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

@SparkQA
Copy link

SparkQA commented Sep 28, 2019

Test build #111519 has finished for PR 25771 at commit 2534baf.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • class SimpleTestOptimizer extends Optimizer(

@imback82
Copy link
Contributor Author

@cloud-fan this is ready for another round of review. Thanks!

namespace: Option[Seq[String]]): Unit = {
namespace.map { ns =>
val nsArray = ns.toArray
if (!catalog.asNamespaceCatalog.namespaceExists(nsArray)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This means that we can't set current namespace for a v2 catalog that doesn't implement SupportsNamespace.

This is a little counter-intuitive as TableCatalog.loadTable does accept a namespace parameter. Maybe we shouldn't do the namespace check when setting 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.

I removed this check. For V1, database check will be performed in SessionCatalog.setCurrentDatabase (so the behavior remains the same) and for V2, there will be no checks performed.

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, only a few minor comments

@SparkQA
Copy link

SparkQA commented Sep 30, 2019

Test build #111609 has started for PR 25771 at commit 3f2e1c1.

@cloud-fan
Copy link
Contributor

I think it's ready to go. @imback82 can you fix the conflict? thanks!

@imback82
Copy link
Contributor Author

imback82 commented Oct 2, 2019

I just resolved the conflicts. Thanks @cloud-fan!

@SparkQA
Copy link

SparkQA commented Oct 2, 2019

Test build #111670 has finished for PR 25771 at commit 88872ea.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Oct 2, 2019

Test build #111681 has finished for PR 25771 at commit 8485619.

  • 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 f2ead4d Oct 2, 2019
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.

5 participants