-
Notifications
You must be signed in to change notification settings - Fork 969
feat!: add support for REVOKE DDL #5703
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
Conversation
7514640
to
fc60f37
Compare
fc60f37
to
c321fda
Compare
@@ -1498,3 +1498,78 @@ def test_locks(self): | |||
for key_type in ("FOR SHARE", "FOR UPDATE", "FOR NO KEY UPDATE", "FOR KEY SHARE"): | |||
with self.subTest(f"Test lock type {key_type}"): | |||
self.validate_identity(f"SELECT 1 FROM foo AS x {key_type} OF x") | |||
|
|||
def test_grant(self): |
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.
These were not in the original PR, so I added them.
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 taking this PR on @newtonapple! My main comment has to do with code duplication as these 2 statements look identical from what I see.
sqlglot/expressions.py
Outdated
arg_types = { | ||
"privileges": True, | ||
"kind": False, | ||
"securable": True, | ||
"principals": True, | ||
"grant_option": False, | ||
"cascade": False, | ||
} |
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.
All of these except cascade
are identical to GRANT
, right? I wonder whether we could abstract them a way in a new node such as:
class DCL(Expression):
arg_types = {
...
}
class Grant(DCL):
pass
class Revoke(DCL):
pass
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.
You could extract the dictionary itself out instead of introducing a new common node, perhaps? Until a need arises for it, like DDL
etc.
grant_cmds = [ | ||
"GRANT SELECT ON TABLE users TO role1", | ||
"GRANT INSERT, DELETE ON TABLE orders TO user1", | ||
"GRANT SELECT ON employees TO manager WITH GRANT OPTION", | ||
"GRANT USAGE ON SCHEMA finance TO user2", | ||
"GRANT ALL PRIVILEGES ON DATABASE mydb TO PUBLIC", |
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.
Ditto about these tests, could we merge them such as:
dcl_cmds = [
"SELECT ON TABLE users TO role1",
...
]
for sql in dcl_cmds:
with self.subTest(f"Testing PostgreSQL's GRANT statement: {sql}"):
self.validate_identity(f"GRANT {sql}")
with self.subTest(f"Testing PostgreSQL's REVOKE statement: {sql}"):
self.validate_identity(f"REVOKE {sql}")
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.
I did a round a refactoring on these basically doing string substitution for TO
& FROM
, then I realized it made the tests much harder to read. Yes, it did DRY up the tests a bit. But, I think for testing, it's much better to see the test cases exactly as they are instead of having to trace through the code just to see what the test cases are. So, a little bit of duplications is probably ok here.
@VaggelisD @georgesittas what do you think? If you guys really want to keep these test cases DRY, I can finish the refactoring.
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.
I'm good either way. Happy to just get this in to unblock you.
generator logics into a shared method
Co-authored-by: Jo <[email protected]>
The intention of this PR is similar to the original Grant DDL PR: it's to layout initial / foundational work for
REVOKE
DDL support.Docs
Databricks | Snowflake | Presto | Trino | MySQL | Postgres | T-SQL | Clickhouse | Oracle | Redshift | Redshift REVOKE examples