Skip to content

Print GRANT clauses in the order the parser reads them - #2415

Open
LucaCappelletti94 wants to merge 1 commit into
apache:mainfrom
LucaCappelletti94:grant-print-clause-order
Open

Print GRANT clauses in the order the parser reads them#2415
LucaCappelletti94 wants to merge 1 commit into
apache:mainfrom
LucaCappelletti94:grant-print-clause-order

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

Display for Grant printed CURRENT GRANTS before WITH GRANT OPTION, but parse_grant reads them the other way round. For a statement carrying both, the printer therefore produced text the parser rejects.

Swapping the two blocks in the printer fixes it.

@LucaCappelletti94
LucaCappelletti94 marked this pull request as ready for review July 30, 2026 18:30

@ting-hong-shieh ting-hong-shieh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against main at 30d0836b. Feeding main's own output back into main's parser fails:

input:   GRANT OWNERSHIP ON ALL TABLES IN SCHEMA s TO ROLE r WITH GRANT OPTION COPY CURRENT GRANTS
main:    GRANT OWNERSHIP ON ALL TABLES IN SCHEMA s TO ROLE r COPY CURRENT GRANTS WITH GRANT OPTION
reparse: Expected: end of statement, found: WITH at Line: 1, Column: 73

With this PR the statement round-trips unchanged.

The comment says the clauses are printed in the order the parser reads them, and after the swap that holds for all four trailing clauses, not only the pair being moved. On main, parse_grant reads WITH GRANT OPTION (src/parser/mod.rs:17723), CURRENT GRANTS (17726), AS (17734), GRANTED BY (17740) — exactly the new Display order. A test carrying all four would lock that property rather than just the pair:

verified_stmt(
    "GRANT OWNERSHIP ON ALL TABLES IN SCHEMA s TO ROLE r WITH GRANT OPTION COPY CURRENT GRANTS AS g GRANTED BY b",
);

I added that assertion to parse_grant on this branch and it passes across all dialects; on main the same statement prints COPY CURRENT GRANTS WITH GRANT OPTION AS g GRANTED BY b.

cargo test --all-features at 2ee726d3: 1584 passed, 0 failed. cargo fmt --all -- --check and cargo clippy --all-targets --all-features -- -D warnings both clean.

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.

2 participants