Fix MySQL parsing of GRANT, REVOKE, and CREATE VIEW (#1538)

This commit is contained in:
Michael Victor Zink 2025-01-09 15:31:06 -08:00 committed by GitHub
parent 687ce2d5f4
commit 4fdf5e1b30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 590 additions and 68 deletions

View file

@ -7192,6 +7192,7 @@ fn parse_create_view() {
if_not_exists,
temporary,
to,
params,
} => {
assert_eq!("myschema.myview", name.to_string());
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
@ -7204,7 +7205,8 @@ fn parse_create_view() {
assert!(!late_binding);
assert!(!if_not_exists);
assert!(!temporary);
assert!(to.is_none())
assert!(to.is_none());
assert!(params.is_none());
}
_ => unreachable!(),
}
@ -7252,6 +7254,7 @@ fn parse_create_view_with_columns() {
if_not_exists,
temporary,
to,
params,
} => {
assert_eq!("v", name.to_string());
assert_eq!(
@ -7274,7 +7277,8 @@ fn parse_create_view_with_columns() {
assert!(!late_binding);
assert!(!if_not_exists);
assert!(!temporary);
assert!(to.is_none())
assert!(to.is_none());
assert!(params.is_none());
}
_ => unreachable!(),
}
@ -7297,6 +7301,7 @@ fn parse_create_view_temporary() {
if_not_exists,
temporary,
to,
params,
} => {
assert_eq!("myschema.myview", name.to_string());
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
@ -7309,7 +7314,8 @@ fn parse_create_view_temporary() {
assert!(!late_binding);
assert!(!if_not_exists);
assert!(temporary);
assert!(to.is_none())
assert!(to.is_none());
assert!(params.is_none());
}
_ => unreachable!(),
}
@ -7332,6 +7338,7 @@ fn parse_create_or_replace_view() {
if_not_exists,
temporary,
to,
params,
} => {
assert_eq!("v", name.to_string());
assert_eq!(columns, vec![]);
@ -7344,7 +7351,8 @@ fn parse_create_or_replace_view() {
assert!(!late_binding);
assert!(!if_not_exists);
assert!(!temporary);
assert!(to.is_none())
assert!(to.is_none());
assert!(params.is_none());
}
_ => unreachable!(),
}
@ -7371,6 +7379,7 @@ fn parse_create_or_replace_materialized_view() {
if_not_exists,
temporary,
to,
params,
} => {
assert_eq!("v", name.to_string());
assert_eq!(columns, vec![]);
@ -7383,7 +7392,8 @@ fn parse_create_or_replace_materialized_view() {
assert!(!late_binding);
assert!(!if_not_exists);
assert!(!temporary);
assert!(to.is_none())
assert!(to.is_none());
assert!(params.is_none());
}
_ => unreachable!(),
}
@ -7406,6 +7416,7 @@ fn parse_create_materialized_view() {
if_not_exists,
temporary,
to,
params,
} => {
assert_eq!("myschema.myview", name.to_string());
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
@ -7418,7 +7429,8 @@ fn parse_create_materialized_view() {
assert!(!late_binding);
assert!(!if_not_exists);
assert!(!temporary);
assert!(to.is_none())
assert!(to.is_none());
assert!(params.is_none());
}
_ => unreachable!(),
}
@ -7441,6 +7453,7 @@ fn parse_create_materialized_view_with_cluster_by() {
if_not_exists,
temporary,
to,
params,
} => {
assert_eq!("myschema.myview", name.to_string());
assert_eq!(Vec::<ViewColumnDef>::new(), columns);
@ -7453,7 +7466,8 @@ fn parse_create_materialized_view_with_cluster_by() {
assert!(!late_binding);
assert!(!if_not_exists);
assert!(!temporary);
assert!(to.is_none())
assert!(to.is_none());
assert!(params.is_none());
}
_ => unreachable!(),
}
@ -8574,14 +8588,14 @@ fn parse_grant() {
#[test]
fn test_revoke() {
let sql = "REVOKE ALL PRIVILEGES ON users, auth FROM analyst CASCADE";
let sql = "REVOKE ALL PRIVILEGES ON users, auth FROM analyst";
match verified_stmt(sql) {
Statement::Revoke {
privileges,
objects: GrantObjects::Tables(tables),
grantees,
cascade,
granted_by,
cascade,
} => {
assert_eq!(
Privileges::All {
@ -8591,7 +8605,33 @@ fn test_revoke() {
);
assert_eq_vec(&["users", "auth"], &tables);
assert_eq_vec(&["analyst"], &grantees);
assert!(cascade);
assert_eq!(cascade, None);
assert_eq!(None, granted_by);
}
_ => unreachable!(),
}
}
#[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) {
Statement::Revoke {
privileges,
objects: GrantObjects::Tables(tables),
grantees,
granted_by,
cascade,
} => {
assert_eq!(
Privileges::All {
with_privileges_keyword: true
},
privileges
);
assert_eq_vec(&["users", "auth"], &tables);
assert_eq_vec(&["analyst"], &grantees);
assert_eq!(cascade, Some(CascadeOption::Cascade));
assert_eq!(None, granted_by);
}
_ => unreachable!(),