Skip to content

Commit 96c4e5a

Browse files
authored
sql: pluralize the object type in abbreviated grants (#38438)
1 parent 24cd10b commit 96c4e5a

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/sql-parser/src/ast/defs/statement.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5836,8 +5836,8 @@ impl<T: AstInfo> AstDisplay for AbbreviatedGrantStatement<T> {
58365836
f.write_str("GRANT ");
58375837
f.write_node(&self.privileges);
58385838
f.write_str(" ON ");
5839-
f.write_node(&self.object_type);
5840-
f.write_str("S TO ");
5839+
write_grant_object_type_plural(f, &self.object_type);
5840+
f.write_str(" TO ");
58415841
f.write_node(&display::comma_separated(&self.grantees));
58425842
}
58435843
}
@@ -5860,8 +5860,8 @@ impl<T: AstInfo> AstDisplay for AbbreviatedRevokeStatement<T> {
58605860
f.write_str("REVOKE ");
58615861
f.write_node(&self.privileges);
58625862
f.write_str(" ON ");
5863-
f.write_node(&self.object_type);
5864-
f.write_str("S FROM ");
5863+
write_grant_object_type_plural(f, &self.object_type);
5864+
f.write_str(" FROM ");
58655865
f.write_node(&display::comma_separated(&self.revokees));
58665866
}
58675867
}

src/sql-parser/tests/sqlparser_common.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,27 @@ fn test_grant_revoke_all_policies_roundtrips() {
377377
}
378378
}
379379

380+
#[mz_ore::test]
381+
fn test_alter_default_privileges_policies_roundtrips() {
382+
for sql in [
383+
"ALTER DEFAULT PRIVILEGES FOR ROLE owner GRANT USAGE ON POLICIES TO j",
384+
"ALTER DEFAULT PRIVILEGES FOR ROLE owner REVOKE USAGE ON POLICIES FROM j",
385+
] {
386+
let displayed = parse_statements(sql)
387+
.unwrap_or_else(|e| panic!("{sql:?} should parse: {e}"))
388+
.into_iter()
389+
.next()
390+
.unwrap()
391+
.ast
392+
.to_ast_string_simple();
393+
assert!(
394+
displayed.contains("ON POLICIES") && !displayed.contains("POLICYS"),
395+
"{sql:?} mis-pluralized network policies: {displayed:?}"
396+
);
397+
assert_display_roundtrips(sql);
398+
}
399+
}
400+
380401
#[mz_ore::test]
381402
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `rust_psm_stack_pointer` on OS `linux`
382403
fn test_negated_cast_display_roundtrip() {

0 commit comments

Comments
 (0)