You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "heyihong (via GitHub)" <gi...@apache.org> on 2023/11/22 16:10:07 UTC
[PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
heyihong opened a new pull request, #43959:
URL: https://github.com/apache/spark/pull/43959
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
- Refactor Catalog Database APIs implementation
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
- Less duplicate logics
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
Existing tests
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
No
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403361939
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +516,11 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- // To maintain backwards compatibility, we first treat the input is a simple dbName and check
- // if sessionCatalog contains it. If no, we try to parse it, resolve catalog and namespace,
- // and check if namespace exists in the catalog.
- if (!sessionCatalog.databaseExists(dbName)) {
- val plan = UnresolvedNamespace(parseIdent(dbName))
- sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog: SupportsNamespaces, ns) =>
- catalog.namespaceExists(ns.toArray)
- case _ => true
- }
- } else {
- true
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
+ sparkSession.sessionState.executePlan(plan).analyzed match {
Review Comment:
Originally, I thought `AnalysisException` won't be threw when the database is missing since [spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala](https://github.com/apache/spark/blob/9c21238ce0e6bec676213f4bad4bc1bf4ac16932/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala#L67-L68) only checks whether Catalog exists but I am wrong. There are other cases that may throw an `AnalysisException` and we should handle it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403367499
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -439,12 +439,12 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
Review Comment:
Yes, `UnresolvedNamespace` may not be sufficient for representing the getDatabase method
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -439,12 +439,12 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
Review Comment:
Yes, the resolution logic of`UnresolvedNamespace` may not be sufficient for representing the getDatabase method
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1407611922
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +502,13 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- // To maintain backwards compatibility, we first treat the input is a simple dbName and check
Review Comment:
It seems we can reuse `getDatabase` here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation to use DescribeNamespace [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403470547
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -439,12 +439,12 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog, namespace) =>
+ case DescribeNamespace(ResolvedNamespace(catalog, namespace), _, _) =>
getNamespace(catalog, namespace)
Review Comment:
So we do not fully leverage the logical plan framework yet, as here we still call catalog APIs to get namespace metadata. Shall we add a new logical plan for getting namespace metadata? Then we can use it here and in `DescribeNamespace`.
Or we can add a new boolean flag `fetchMetadata` in `UnresolvedNamespace`, and put the metadata in `ResolvedNamespace` if the flag is true, else put Map.empty
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403367499
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -439,12 +439,12 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
Review Comment:
Yes, [spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala](https://github.com/apache/spark/blob/9c21238ce0e6bec676213f4bad4bc1bf4ac16932/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala#L67-L68) may not be sufficient for representing the getDatabase method
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1407560310
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,35 +408,28 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
- case catalog: SupportsNamespaces =>
- val metadata = catalog.loadNamespaceMetadata(ns.toArray)
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = metadata.get(SupportsNamespaces.PROP_COMMENT),
- locationUri = metadata.get(SupportsNamespaces.PROP_LOCATION))
- // If the catalog doesn't support namespaces, we assume it's an implicit namespace, which always
- // exists but has no metadata.
- case catalog: CatalogPlugin =>
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = null,
- locationUri = null)
- case _ => new Database(name = ns.quoted, description = null, locationUri = null)
- }
-
/**
* Gets the database with the specified name. This throws an `AnalysisException` when no
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ makeDatabase(None, dbName)
+ }
+
+ private def makeDatabase(catalogNameOpt: Option[String], dbName: String): Database = {
+ val idents = catalogNameOpt match {
+ case Some(catalogName) => catalogName +: parseIdent(dbName)
+ case None => resolveNamespace(dbName)
+ }
+ val plan = UnresolvedNamespace(idents, true)
Review Comment:
There are some internal use cases for `UnresolvedNamespace(idents, true)` as well
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1407688658
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,35 +408,28 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
- case catalog: SupportsNamespaces =>
- val metadata = catalog.loadNamespaceMetadata(ns.toArray)
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = metadata.get(SupportsNamespaces.PROP_COMMENT),
- locationUri = metadata.get(SupportsNamespaces.PROP_LOCATION))
- // If the catalog doesn't support namespaces, we assume it's an implicit namespace, which always
- // exists but has no metadata.
- case catalog: CatalogPlugin =>
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = null,
- locationUri = null)
- case _ => new Database(name = ns.quoted, description = null, locationUri = null)
- }
-
/**
* Gets the database with the specified name. This throws an `AnalysisException` when no
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ makeDatabase(None, dbName)
Review Comment:
Yes, it is a new private method
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1406751863
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +502,13 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- // To maintain backwards compatibility, we first treat the input is a simple dbName and check
- // if sessionCatalog contains it. If no, we try to parse it, resolve catalog and namespace,
- // and check if namespace exists in the catalog.
- if (!sessionCatalog.databaseExists(dbName)) {
- val plan = UnresolvedNamespace(parseIdent(dbName))
+ val plan = UnresolvedNamespace(resolveNamespace(dbName), true)
+ try {
sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog: SupportsNamespaces, ns) =>
- catalog.namespaceExists(ns.toArray)
case _ => true
}
- } else {
- true
+ } catch {
+ case _: AnalysisException => false
Review Comment:
shall we catch `NoSuchNamespaceException`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1402942919
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -439,12 +439,12 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
Review Comment:
oh, is it because `UnresolvedNamespace` have special resolution logic depending on where it is?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403359813
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +516,11 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- // To maintain backwards compatibility, we first treat the input is a simple dbName and check
- // if sessionCatalog contains it. If no, we try to parse it, resolve catalog and namespace,
- // and check if namespace exists in the catalog.
- if (!sessionCatalog.databaseExists(dbName)) {
- val plan = UnresolvedNamespace(parseIdent(dbName))
- sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog: SupportsNamespaces, ns) =>
- catalog.namespaceExists(ns.toArray)
- case _ => true
- }
- } else {
- true
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
+ sparkSession.sessionState.executePlan(plan).analyzed match {
+ case DescribeNamespace(ResolvedNamespace(catalog: SupportsNamespaces, ns), _, _) =>
+ catalog.namespaceExists(ns.toArray)
Review Comment:
Without this check (i.e. `catalog.namespaceExists(ns.toArray)`), [this test](https://github.com/apache/spark/blob/master/sql/core/src/test/scala/org/apache/spark/sql/internal/CatalogSuite.scala#L564-L569) will fail
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1406748560
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,35 +408,28 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
- case catalog: SupportsNamespaces =>
- val metadata = catalog.loadNamespaceMetadata(ns.toArray)
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = metadata.get(SupportsNamespaces.PROP_COMMENT),
- locationUri = metadata.get(SupportsNamespaces.PROP_LOCATION))
- // If the catalog doesn't support namespaces, we assume it's an implicit namespace, which always
- // exists but has no metadata.
- case catalog: CatalogPlugin =>
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = null,
- locationUri = null)
- case _ => new Database(name = ns.quoted, description = null, locationUri = null)
- }
-
/**
* Gets the database with the specified name. This throws an `AnalysisException` when no
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ makeDatabase(None, dbName)
+ }
+
+ private def makeDatabase(catalogNameOpt: Option[String], dbName: String): Database = {
+ val idents = catalogNameOpt match {
+ case Some(catalogName) => catalogName +: parseIdent(dbName)
+ case None => resolveNamespace(dbName)
+ }
+ val plan = UnresolvedNamespace(idents, true)
Review Comment:
```suggestion
val plan = UnresolvedNamespace(idents, fetchMetadata = true)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation to use DescribeNamespace [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403554624
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -439,12 +439,12 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog, namespace) =>
+ case DescribeNamespace(ResolvedNamespace(catalog, namespace), _, _) =>
getNamespace(catalog, namespace)
Review Comment:
Good point! I added a new boolean flag `fetchMetadata` in `UnresolvedNamespace`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #43959: [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation
URL: https://github.com/apache/spark/pull/43959
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1406158086
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,14 +408,16 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
+ private def getNamespace(
+ catalog: CatalogPlugin,
+ ns: Seq[String],
+ metadata: Map[String, String]): Database = catalog match {
case catalog: SupportsNamespaces =>
Review Comment:
do we still need to match the catalog with different types?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1407553571
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,35 +408,28 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
- case catalog: SupportsNamespaces =>
- val metadata = catalog.loadNamespaceMetadata(ns.toArray)
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = metadata.get(SupportsNamespaces.PROP_COMMENT),
- locationUri = metadata.get(SupportsNamespaces.PROP_LOCATION))
- // If the catalog doesn't support namespaces, we assume it's an implicit namespace, which always
- // exists but has no metadata.
- case catalog: CatalogPlugin =>
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = null,
- locationUri = null)
- case _ => new Database(name = ns.quoted, description = null, locationUri = null)
- }
-
/**
* Gets the database with the specified name. This throws an `AnalysisException` when no
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ makeDatabase(None, dbName)
Review Comment:
`makeDatabase` is also used in `listDatabasesInternal` so we shall not?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1407611470
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala:
##########
@@ -50,10 +52,18 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
case CurrentNamespace =>
ResolvedNamespace(currentCatalog, catalogManager.currentNamespace.toImmutableArraySeq)
- case UnresolvedNamespace(Seq()) =>
- ResolvedNamespace(currentCatalog, Seq.empty[String])
- case UnresolvedNamespace(CatalogAndNamespace(catalog, ns)) =>
- ResolvedNamespace(catalog, ns)
+ case UnresolvedNamespace(Seq(), _) =>
+ ResolvedNamespace(currentCatalog, Seq.empty[String], Map.empty)
Review Comment:
Good point!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1407560310
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,35 +408,28 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
- case catalog: SupportsNamespaces =>
- val metadata = catalog.loadNamespaceMetadata(ns.toArray)
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = metadata.get(SupportsNamespaces.PROP_COMMENT),
- locationUri = metadata.get(SupportsNamespaces.PROP_LOCATION))
- // If the catalog doesn't support namespaces, we assume it's an implicit namespace, which always
- // exists but has no metadata.
- case catalog: CatalogPlugin =>
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = null,
- locationUri = null)
- case _ => new Database(name = ns.quoted, description = null, locationUri = null)
- }
-
/**
* Gets the database with the specified name. This throws an `AnalysisException` when no
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ makeDatabase(None, dbName)
+ }
+
+ private def makeDatabase(catalogNameOpt: Option[String], dbName: String): Database = {
+ val idents = catalogNameOpt match {
+ case Some(catalogName) => catalogName +: parseIdent(dbName)
+ case None => resolveNamespace(dbName)
+ }
+ val plan = UnresolvedNamespace(idents, true)
Review Comment:
There are some internal use cases for `UnresolvedNamespace(idents, true)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1406744776
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/v2ResolutionPlans.scala:
##########
@@ -37,7 +37,9 @@ import org.apache.spark.util.ArrayImplicits._
* Holds the name of a namespace that has yet to be looked up in a catalog. It will be resolved to
* [[ResolvedNamespace]] during analysis.
*/
-case class UnresolvedNamespace(multipartIdentifier: Seq[String]) extends UnresolvedLeafNode
+case class UnresolvedNamespace(
+ multipartIdentifier: Seq[String],
Review Comment:
nit: 4 spaces indentation
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/v2ResolutionPlans.scala:
##########
@@ -144,7 +146,10 @@ trait LeafNodeWithoutStats extends LeafNode {
/**
* A plan containing resolved namespace.
*/
-case class ResolvedNamespace(catalog: CatalogPlugin, namespace: Seq[String])
+case class ResolvedNamespace(
+ catalog: CatalogPlugin,
Review Comment:
nit: 4 spaces indentation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1402503451
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +516,11 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- // To maintain backwards compatibility, we first treat the input is a simple dbName and check
- // if sessionCatalog contains it. If no, we try to parse it, resolve catalog and namespace,
- // and check if namespace exists in the catalog.
- if (!sessionCatalog.databaseExists(dbName)) {
- val plan = UnresolvedNamespace(parseIdent(dbName))
- sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog: SupportsNamespaces, ns) =>
- catalog.namespaceExists(ns.toArray)
- case _ => true
- }
- } else {
- true
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
+ sparkSession.sessionState.executePlan(plan).analyzed match {
+ case DescribeNamespace(ResolvedNamespace(catalog: SupportsNamespaces, ns), _, _) =>
+ catalog.namespaceExists(ns.toArray)
Review Comment:
Why do we need to do this check? Isn't the analyzed plan sufficient to confirm the database exists?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "hvanhovell (via GitHub)" <gi...@apache.org>.
hvanhovell commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1402504241
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +516,11 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- // To maintain backwards compatibility, we first treat the input is a simple dbName and check
- // if sessionCatalog contains it. If no, we try to parse it, resolve catalog and namespace,
- // and check if namespace exists in the catalog.
- if (!sessionCatalog.databaseExists(dbName)) {
- val plan = UnresolvedNamespace(parseIdent(dbName))
- sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog: SupportsNamespaces, ns) =>
- catalog.namespaceExists(ns.toArray)
- case _ => true
- }
- } else {
- true
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
+ sparkSession.sessionState.executePlan(plan).analyzed match {
Review Comment:
Doesn't this throw an `AnalysisException` if the database is missing?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1402942694
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -439,12 +439,12 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
Review Comment:
why it's necessary to wrap `UnresolvedNamespace` with `DescribeNamespace`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403357813
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +516,11 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- // To maintain backwards compatibility, we first treat the input is a simple dbName and check
- // if sessionCatalog contains it. If no, we try to parse it, resolve catalog and namespace,
- // and check if namespace exists in the catalog.
- if (!sessionCatalog.databaseExists(dbName)) {
- val plan = UnresolvedNamespace(parseIdent(dbName))
- sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog: SupportsNamespaces, ns) =>
- catalog.namespaceExists(ns.toArray)
- case _ => true
- }
- } else {
- true
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
+ sparkSession.sessionState.executePlan(plan).analyzed match {
+ case DescribeNamespace(ResolvedNamespace(catalog: SupportsNamespaces, ns), _, _) =>
+ catalog.namespaceExists(ns.toArray)
Review Comment:
It is because https://github.com/apache/spark/blob/9c21238ce0e6bec676213f4bad4bc1bf4ac16932/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala#L67-L68 only checks whether Catalog exists if I understand correctly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403361939
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +516,11 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- // To maintain backwards compatibility, we first treat the input is a simple dbName and check
- // if sessionCatalog contains it. If no, we try to parse it, resolve catalog and namespace,
- // and check if namespace exists in the catalog.
- if (!sessionCatalog.databaseExists(dbName)) {
- val plan = UnresolvedNamespace(parseIdent(dbName))
- sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog: SupportsNamespaces, ns) =>
- catalog.namespaceExists(ns.toArray)
- case _ => true
- }
- } else {
- true
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
+ sparkSession.sessionState.executePlan(plan).analyzed match {
Review Comment:
Originally, I thought `AnalysisException` won't be threw when the database is missing since https://github.com/apache/spark/blob/9c21238ce0e6bec676213f4bad4bc1bf4ac16932/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala#L67-L68 only checks whether Catalog exists. But I am wrong... There are other cases that may throw an `AnalysisException` and we should handle it
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -439,12 +439,12 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
Review Comment:
Yes, https://github.com/apache/spark/blob/9c21238ce0e6bec676213f4bad4bc1bf4ac16932/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala#L67-L68 may not be sufficient for representing the getDatabase method
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1406742831
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala:
##########
@@ -50,10 +52,18 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
case CurrentNamespace =>
ResolvedNamespace(currentCatalog, catalogManager.currentNamespace.toImmutableArraySeq)
- case UnresolvedNamespace(Seq()) =>
- ResolvedNamespace(currentCatalog, Seq.empty[String])
- case UnresolvedNamespace(CatalogAndNamespace(catalog, ns)) =>
- ResolvedNamespace(catalog, ns)
+ case UnresolvedNamespace(Seq(), _) =>
+ ResolvedNamespace(currentCatalog, Seq.empty[String], Map.empty)
Review Comment:
Let's add a function `def resolveNamespace(catalog: CatalogPlugin, ns: Seq[String]): ResolvedNamespace` and call it here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1406155294
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala:
##########
@@ -17,9 +17,11 @@
package org.apache.spark.sql.catalyst.analysis
+import scala.jdk.CollectionConverters.MapHasAsScala
Review Comment:
```suggestion
import scala.jdk.CollectionConverters._
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1406500680
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,14 +408,16 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
+ private def getNamespace(
+ catalog: CatalogPlugin,
+ ns: Seq[String],
+ metadata: Map[String, String]): Database = catalog match {
case catalog: SupportsNamespaces =>
Review Comment:
Good point, if I understand correctly, catalog should not be null so it should be safe to always call `catalog.name`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1407610544
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,35 +408,28 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
- case catalog: SupportsNamespaces =>
- val metadata = catalog.loadNamespaceMetadata(ns.toArray)
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = metadata.get(SupportsNamespaces.PROP_COMMENT),
- locationUri = metadata.get(SupportsNamespaces.PROP_LOCATION))
- // If the catalog doesn't support namespaces, we assume it's an implicit namespace, which always
- // exists but has no metadata.
- case catalog: CatalogPlugin =>
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = null,
- locationUri = null)
- case _ => new Database(name = ns.quoted, description = null, locationUri = null)
- }
-
/**
* Gets the database with the specified name. This throws an `AnalysisException` when no
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ makeDatabase(None, dbName)
Review Comment:
makeDatabase is a new method?
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,35 +408,28 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
- case catalog: SupportsNamespaces =>
- val metadata = catalog.loadNamespaceMetadata(ns.toArray)
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = metadata.get(SupportsNamespaces.PROP_COMMENT),
- locationUri = metadata.get(SupportsNamespaces.PROP_LOCATION))
- // If the catalog doesn't support namespaces, we assume it's an implicit namespace, which always
- // exists but has no metadata.
- case catalog: CatalogPlugin =>
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = null,
- locationUri = null)
- case _ => new Database(name = ns.quoted, description = null, locationUri = null)
- }
-
/**
* Gets the database with the specified name. This throws an `AnalysisException` when no
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ makeDatabase(None, dbName)
Review Comment:
`makeDatabase` is a new method?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1406743762
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala:
##########
@@ -50,10 +52,18 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
case CurrentNamespace =>
ResolvedNamespace(currentCatalog, catalogManager.currentNamespace.toImmutableArraySeq)
- case UnresolvedNamespace(Seq()) =>
- ResolvedNamespace(currentCatalog, Seq.empty[String])
- case UnresolvedNamespace(CatalogAndNamespace(catalog, ns)) =>
- ResolvedNamespace(catalog, ns)
+ case UnresolvedNamespace(Seq(), _) =>
+ ResolvedNamespace(currentCatalog, Seq.empty[String], Map.empty)
Review Comment:
Nil is also a valid namespace in DS v2.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala:
##########
@@ -50,10 +52,18 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
case CurrentNamespace =>
ResolvedNamespace(currentCatalog, catalogManager.currentNamespace.toImmutableArraySeq)
- case UnresolvedNamespace(Seq()) =>
- ResolvedNamespace(currentCatalog, Seq.empty[String])
- case UnresolvedNamespace(CatalogAndNamespace(catalog, ns)) =>
- ResolvedNamespace(catalog, ns)
+ case UnresolvedNamespace(Seq(), _) =>
+ ResolvedNamespace(currentCatalog, Seq.empty[String], Map.empty)
Review Comment:
Nil (the root namespace) is also a valid namespace in DS v2.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403361939
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +516,11 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- // To maintain backwards compatibility, we first treat the input is a simple dbName and check
- // if sessionCatalog contains it. If no, we try to parse it, resolve catalog and namespace,
- // and check if namespace exists in the catalog.
- if (!sessionCatalog.databaseExists(dbName)) {
- val plan = UnresolvedNamespace(parseIdent(dbName))
- sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog: SupportsNamespaces, ns) =>
- catalog.namespaceExists(ns.toArray)
- case _ => true
- }
- } else {
- true
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
+ sparkSession.sessionState.executePlan(plan).analyzed match {
Review Comment:
Originally, I thought `AnalysisException` won't be threw when the database is missing since [spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala](https://github.com/apache/spark/blob/9c21238ce0e6bec676213f4bad4bc1bf4ac16932/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala#L67-L68) only checks whether Catalog exists. But I am wrong... There are other cases that may throw an `AnalysisException` and we should handle it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation to use DescribeNamespace [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1403361939
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -516,18 +516,11 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- // To maintain backwards compatibility, we first treat the input is a simple dbName and check
- // if sessionCatalog contains it. If no, we try to parse it, resolve catalog and namespace,
- // and check if namespace exists in the catalog.
- if (!sessionCatalog.databaseExists(dbName)) {
- val plan = UnresolvedNamespace(parseIdent(dbName))
- sparkSession.sessionState.executePlan(plan).analyzed match {
- case ResolvedNamespace(catalog: SupportsNamespaces, ns) =>
- catalog.namespaceExists(ns.toArray)
- case _ => true
- }
- } else {
- true
+ val plan = DescribeNamespace(UnresolvedNamespace(resolveNamespace(dbName)), false)
+ sparkSession.sessionState.executePlan(plan).analyzed match {
Review Comment:
Originally, I thought `AnalysisException` won't be threw when the database is missing since https://github.com/apache/spark/blob/9c21238ce0e6bec676213f4bad4bc1bf4ac16932/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogs.scala#L67-L68 only checks whether Catalog exists. But I was wrong... There are other cases that may throw an `AnalysisException` and we should handle it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Refactor Catalog Database APIs implementation [spark]
Posted by "heyihong (via GitHub)" <gi...@apache.org>.
heyihong commented on PR #43959:
URL: https://github.com/apache/spark/pull/43959#issuecomment-1823064421
@cloud-fan @hvanhovell Please take a look when you have time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #43959:
URL: https://github.com/apache/spark/pull/43959#issuecomment-1831000394
thanks, merging to master!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-46055][SQL] Rewrite Catalog Database APIs implementation [spark]
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #43959:
URL: https://github.com/apache/spark/pull/43959#discussion_r1407020765
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,35 +408,28 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
- case catalog: SupportsNamespaces =>
- val metadata = catalog.loadNamespaceMetadata(ns.toArray)
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = metadata.get(SupportsNamespaces.PROP_COMMENT),
- locationUri = metadata.get(SupportsNamespaces.PROP_LOCATION))
- // If the catalog doesn't support namespaces, we assume it's an implicit namespace, which always
- // exists but has no metadata.
- case catalog: CatalogPlugin =>
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = null,
- locationUri = null)
- case _ => new Database(name = ns.quoted, description = null, locationUri = null)
- }
-
/**
* Gets the database with the specified name. This throws an `AnalysisException` when no
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ makeDatabase(None, dbName)
+ }
+
+ private def makeDatabase(catalogNameOpt: Option[String], dbName: String): Database = {
+ val idents = catalogNameOpt match {
+ case Some(catalogName) => catalogName +: parseIdent(dbName)
+ case None => resolveNamespace(dbName)
+ }
+ val plan = UnresolvedNamespace(idents, true)
Review Comment:
It seems the created `UnresolvedNamespace(idents, true)` only used once, it's really worth?
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -415,35 +408,28 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
}
}
- private def getNamespace(catalog: CatalogPlugin, ns: Seq[String]): Database = catalog match {
- case catalog: SupportsNamespaces =>
- val metadata = catalog.loadNamespaceMetadata(ns.toArray)
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = metadata.get(SupportsNamespaces.PROP_COMMENT),
- locationUri = metadata.get(SupportsNamespaces.PROP_LOCATION))
- // If the catalog doesn't support namespaces, we assume it's an implicit namespace, which always
- // exists but has no metadata.
- case catalog: CatalogPlugin =>
- new Database(
- name = ns.quoted,
- catalog = catalog.name,
- description = null,
- locationUri = null)
- case _ => new Database(name = ns.quoted, description = null, locationUri = null)
- }
-
/**
* Gets the database with the specified name. This throws an `AnalysisException` when no
* `Database` can be found.
*/
override def getDatabase(dbName: String): Database = {
- val namespace = resolveNamespace(dbName)
- val plan = UnresolvedNamespace(namespace)
+ makeDatabase(None, dbName)
Review Comment:
Shall we inline `makeDatabase` into `getDatabase`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org