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/24 12:01:56 UTC

(datafusion-sqlparser-rs) 01/01: Print `GRANT` clauses in the order the parser reads them (#2415)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-2415-777a1663c5f9f33ca27f173f74d950544d4930b1
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git

commit 183e083ee87b65ea965fa30dea621f13e81fdd66
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Mon Aug 24 12:01:30 2026 +0000

    Print `GRANT` clauses in the order the parser reads them (#2415)
---
 src/ast/dcl.rs            | 7 ++++---
 tests/sqlparser_common.rs | 4 ++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/ast/dcl.rs b/src/ast/dcl.rs
index 3c50a81c..830fdb2c 100644
--- a/src/ast/dcl.rs
+++ b/src/ast/dcl.rs
@@ -463,12 +463,13 @@ impl fmt::Display for Grant {
             write!(f, " ON {objects}")?;
         }
         write!(f, " TO {}", display_comma_separated(&self.grantees))?;
-        if let Some(ref current_grants) = self.current_grants {
-            write!(f, " {current_grants}")?;
-        }
+        // Printed in the order the parser reads them, so the output re-parses.
         if self.with_grant_option {
             write!(f, " WITH GRANT OPTION")?;
         }
+        if let Some(ref current_grants) = self.current_grants {
+            write!(f, " {current_grants}")?;
+        }
         if let Some(ref as_grantor) = self.as_grantor {
             write!(f, " AS {as_grantor}")?;
         }
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index 6a08caf8..92c31db0 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -10058,6 +10058,10 @@ fn parse_grant() {
     verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
     verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST COPY CURRENT GRANTS");
     verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST REVOKE CURRENT GRANTS");
+    // Printing these the other way round yields output the parser rejects.
+    verified_stmt(
+        "GRANT OWNERSHIP ON ALL TABLES IN SCHEMA s TO ROLE r WITH GRANT OPTION COPY CURRENT GRANTS",
+    );
     verified_stmt("GRANT USAGE ON DATABASE db1 TO ROLE role1");
     verified_stmt("GRANT USAGE ON WAREHOUSE wh1 TO ROLE role1");
     verified_stmt("GRANT OWNERSHIP ON INTEGRATION int1 TO ROLE role1");


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org