Skip to content

Conversation

newtonapple
Copy link
Contributor

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

@@ -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):
Copy link
Contributor Author

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.

Copy link
Collaborator

@VaggelisD VaggelisD left a 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.

Comment on lines 2472 to 2479
arg_types = {
"privileges": True,
"kind": False,
"securable": True,
"principals": True,
"grant_option": False,
"cascade": False,
}
Copy link
Collaborator

@VaggelisD VaggelisD Aug 28, 2025

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

Copy link
Collaborator

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.

Comment on lines +1503 to +1508
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",
Copy link
Collaborator

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}")

Copy link
Contributor Author

@newtonapple newtonapple Aug 28, 2025

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.

Copy link
Collaborator

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.

@georgesittas georgesittas changed the title feat: add support for REVOKE DDL feat!: add support for REVOKE DDL Aug 28, 2025
@georgesittas georgesittas merged commit 727bf83 into tobymao:main Aug 28, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants