You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/08/25 10:24:42 UTC
(datafusion-sqlparser-rs) branch main updated: Parse `REVOKE GRANT OPTION FOR` (#2431)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 471f1dab Parse `REVOKE GRANT OPTION FOR` (#2431)
471f1dab is described below
commit 471f1dab263a04478dd51825e0f815e653caaefb
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Tue Aug 25 09:30:13 2026 +0000
Parse `REVOKE GRANT OPTION FOR` (#2431)
---
src/ast/dcl.rs | 10 +++++++++-
src/parser/mod.rs | 4 ++++
tests/sqlparser_common.rs | 24 +++++++++++++++++++++++-
tests/sqlparser_mysql.rs | 1 +
4 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/src/ast/dcl.rs b/src/ast/dcl.rs
index 830fdb2c..96b34071 100644
--- a/src/ast/dcl.rs
+++ b/src/ast/dcl.rs
@@ -487,10 +487,14 @@ impl From<Grant> for crate::ast::Statement {
}
/// REVOKE privileges ON objects FROM grantees
+/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-revoke.html)
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct Revoke {
+ /// Whether `GRANT OPTION FOR` is present, withdrawing the right to grant
+ /// the privileges rather than the privileges themselves.
+ pub grant_option_for: bool,
/// Privileges to revoke.
pub privileges: Privileges,
/// Optional objects from which to revoke.
@@ -507,7 +511,11 @@ pub struct Revoke {
impl fmt::Display for Revoke {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "REVOKE {privileges}", privileges = self.privileges)?;
+ write!(f, "REVOKE ")?;
+ if self.grant_option_for {
+ write!(f, "GRANT OPTION FOR ")?;
+ }
+ write!(f, "{}", self.privileges)?;
if let Some(ref objects) = self.objects {
write!(f, " ON {objects}")?;
}
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index b8fb3525..953453a2 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -18366,6 +18366,9 @@ impl<'a> Parser<'a> {
/// Parse a REVOKE statement
pub fn parse_revoke(&mut self) -> Result<Revoke, ParserError> {
+ let grant_option_for =
+ self.parse_keywords(&[Keyword::GRANT, Keyword::OPTION, Keyword::FOR]);
+
let (privileges, objects) = self.parse_grant_deny_revoke_privileges_objects()?;
self.expect_keyword_is(Keyword::FROM)?;
@@ -18380,6 +18383,7 @@ impl<'a> Parser<'a> {
let cascade = self.parse_cascade_option();
Ok(Revoke {
+ grant_option_for,
privileges,
objects,
grantees,
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index 92c31db0..c8a2453a 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -10116,6 +10116,7 @@ fn test_revoke() {
let sql = "REVOKE ALL PRIVILEGES ON users, auth FROM analyst";
match verified_stmt(sql) {
Statement::Revoke(Revoke {
+ grant_option_for: false,
privileges,
objects: Some(GrantObjects::Tables(tables)),
grantees,
@@ -10140,8 +10141,9 @@ fn test_revoke() {
#[test]
fn test_revoke_with_cascade() {
let sql = "REVOKE ALL PRIVILEGES ON users, auth FROM analyst CASCADE";
- match all_dialects_except(|d| d.is::<MySqlDialect>()).verified_stmt(sql) {
+ match verified_stmt(sql) {
Statement::Revoke(Revoke {
+ grant_option_for: false,
privileges,
objects: Some(GrantObjects::Tables(tables)),
grantees,
@@ -10163,6 +10165,26 @@ fn test_revoke_with_cascade() {
}
}
+#[test]
+fn test_revoke_grant_option_for() {
+ let Statement::Revoke(mut revoke) = verified_stmt("REVOKE GRANT OPTION FOR SELECT ON t FROM r")
+ else {
+ unreachable!()
+ };
+ assert!(revoke.grant_option_for);
+
+ // Clearing the flag must yield exactly the plain revoke.
+ revoke.grant_option_for = false;
+ assert_eq!(
+ Statement::Revoke(revoke),
+ verified_stmt("REVOKE SELECT ON t FROM r")
+ );
+
+ verified_stmt("REVOKE GRANT OPTION FOR ALL ON t FROM r");
+ verified_stmt("REVOKE GRANT OPTION FOR SELECT ON t FROM r CASCADE");
+ verified_stmt("REVOKE GRANT OPTION FOR SELECT ON t FROM r RESTRICT");
+}
+
#[test]
fn parse_merge() {
let sql = "MERGE INTO s.bar AS dest USING (SELECT * FROM s.foo) AS stg ON dest.D = stg.D AND dest.E = stg.E WHEN NOT MATCHED THEN INSERT (A, B, C) VALUES (stg.A, stg.B, stg.C) WHEN MATCHED AND dest.A = 'a' THEN UPDATE SET dest.F = stg.F, dest.G = stg.G WHEN MATCHED THEN DELETE";
diff --git a/tests/sqlparser_mysql.rs b/tests/sqlparser_mysql.rs
index 797a1255..0df8393e 100644
--- a/tests/sqlparser_mysql.rs
+++ b/tests/sqlparser_mysql.rs
@@ -4013,6 +4013,7 @@ fn parse_revoke() {
let sql = "REVOKE ALL ON db1.* FROM 'jeffrey'@'%'";
let stmt = mysql_and_generic().verified_stmt(sql);
if let Statement::Revoke(Revoke {
+ grant_option_for: false,
privileges,
objects,
grantees,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org