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
[SPARK-36841][SQL] Add ansi syntax set catalog xxx
to change the current catalog
#34096
Conversation
Can one of the admins verify this patch? |
@cloud-fan @imback82 Could you take a look ? Thank you. |
@@ -120,6 +120,7 @@ class CatalogManager( | |||
def setCurrentCatalog(catalogName: String): Unit = synchronized { | |||
// `setCurrentCatalog` is noop if it doesn't switch to a different catalog. | |||
if (currentCatalog.name() != catalogName) { | |||
catalog(catalogName) |
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.
Here I just want to check the catalogName is exist and catalog is configed.
@@ -107,6 +107,7 @@ statement | |||
: query #statementDefault | |||
| ctes? dmlStatementNoWith #dmlStatement | |||
| USE NAMESPACE? multipartIdentifier #use | |||
| SET CATALOG multipartIdentifier #setCatalog |
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.
multipartIdentifier? I think it should be identifier | STRING
, so that people can write SET CATALOG abc
or SET CATALOG '_ 56'
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.
+1
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.
Thank you. I get it.
@@ -2916,6 +2916,22 @@ class DataSourceV2SQLSuite | |||
} | |||
} | |||
|
|||
test("SPARK-36481: Test for SET CATALOG statement") { |
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 add UT in DDLParserSuite
?
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.
ok.
21a9454
to
330a35a
Compare
/** | ||
* A SetCatalog statement, as parsed from SQL. | ||
*/ | ||
case class SetCatalogStatement(nameParts: Option[String]) extends LeafParsedStatement |
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't we just make this nameParts: String
without Option
?
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.
Thank you for your advice. Done
330a35a
to
3183b4c
Compare
|
ok. Thank you for the reminder. |
8d29466
to
7d24ab7
Compare
@@ -107,6 +107,7 @@ statement | |||
: query #statementDefault | |||
| ctes? dmlStatementNoWith #dmlStatement | |||
| USE NAMESPACE? multipartIdentifier #use | |||
| SET CATALOG catalogIdentifier #setCatalog |
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.
is it simpler to do SET CATALOG identifier | 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.
ok
} else if (ctx.catalogIdentifier.STRING() != null) { | ||
string(ctx.catalogIdentifier().STRING()) | ||
} else { | ||
ctx.catalogIdentifier().getText |
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 should never hit here. How about throw IllegalStateException
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.
OK, How about QueryParsingErrors.invalidCatalogNameError(ctx)
with ParseException
?
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.
It's not a user-facing error, so we shouldn't use QueryParsingErrors
sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLParserSuite.scala
Show resolved
Hide resolved
7d24ab7
to
1fbe12a
Compare
@cloud-fan A little off-topic: I also think |
Yes thanks! |
thanks, merging to master! |
What changes were proposed in this pull request?
1、Add the statement of
set catalog xxx
to change the current catalog2、Retain the
USE
statement to change the current catalog3、Forcible loading the new catalog when change the new catalog.
Why are the changes needed?
Ansi SQL use
SET CATALOG XXX
statement to change the catalog.DISCUSS
Does this PR introduce any user-facing change?
Yes, User can use
SET CATALOG XXX
to change the current catalogHow was this patch tested?
Add ut testcase