-
Notifications
You must be signed in to change notification settings - Fork 543
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
feat: support different USE statement syntaxes #1387
Conversation
e7690a7
to
984d805
Compare
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.
LGTM! cc @alamb
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 @kacpermuda and @iffyio
This change makes sense to me
Pull Request Test Coverage Report for Build 10509933459Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
🚀 |
I'd like to add support for different syntaxes of the
USE
statement, used to set a default DATABASE/SCHEMA for set of queries.Some implementations are calling their top level structure
CATALOG
(e.g. Databricks, Trino), but most of them stick toDATABASE
so I assumed that we should stick to naming:top-level container = DATABASE
,lower-level container = SCHEMA
. For the full identifier we end up with:DATABASE.SCHEMA.TABLE
.In some implementations
DATABASE
andSCHEMA
are aliases, but usually these implementations have a two-layer structure (DATABASE.TABLE
, withoutSCHEMA
) - in that case we should keepDATABASE
asDATABASE
and leaveSCHEMA
empty.There are different syntaxes of USE statement across dialects, but I implemented it like:
(use syntax => resolved db and schema names)
USE x;
->DATABASE=x; SCHEMA=null;
(Databricks is adjusted toDATABASE=null; SCHEMA=x;
)USE x.y;
->DATABASE=x; SCHEMA=y;
USE DATABASE x;
->DATABASE=x; SCHEMA=null;
(Databricks is adjusted toDATABASE=null; SCHEMA=x;
In DatabricksDATABASE
is an alias forSCHEMA
and they both mean lower level structure while the top level structure is calledCATALOG
)USE SCHEMA y;
->DATABASE=null; SCHEMA=y;
USE SCHEMA x.y;
->DATABASE=x; SCHEMA=y;
(Snowflake specific syntax, SCHEMA keyword is optional and should not influence the parsing of fully qualified name)USE CATALOG x;
->DATABASE=x; SCHEMA=null;
(Databricks-specific keyword:CATALOG
)USE DEFAULT;
->DATABASE=null; SCHEMA=null;
(Hive specific, means going back to default database set - we don't know what it is just by looking at the query.)Docs about USE statement in different dialects:
Some comments: