Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

[package]
name = "sqlparser-dsql"
description = "SQL parser fork with Aurora DSQL extensions (CREATE INDEX ASYNC, ALTER TABLE ASYNC, PostgreSQL constraint syntax, ALTER COLUMN DROP IDENTITY/EXPRESSION, ALTER COLUMN SET STORAGE, order-independent CREATE SEQUENCE, INCLUDE on table constraints). Based on sqlparser 0.62.0."
version = "0.62.8"
description = "SQL parser fork with Aurora DSQL extensions and DSQL-supported PostgreSQL syntax. Based on sqlparser 0.62.0."
version = "0.62.9"
authors = [
"Apache DataFusion <[email protected]>",
"Amazon Web Services",
Expand Down
70 changes: 70 additions & 0 deletions src/ast/dcl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,76 @@ impl From<Grant> for crate::ast::Statement {
}
}

/// An `ALTER DEFAULT PRIVILEGES` operation.
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum AlterDefaultPrivilegesOperation {
/// Grant default privileges on future tables.
Grant {
/// Privileges being granted.
privileges: Privileges,
/// Grantees receiving the privileges.
grantees: Vec<Grantee>,
/// Whether `WITH GRANT OPTION` is present.
with_grant_option: bool,
},
/// Revoke default privileges on future tables.
Revoke {
/// Whether `GRANT OPTION FOR` is present.
grant_option_for: bool,
/// Privileges being revoked.
privileges: Privileges,
/// Grantees losing the privileges.
grantees: Vec<Grantee>,
/// Optional `CASCADE`/`RESTRICT` behavior.
cascade: Option<CascadeOption>,
},
}

impl fmt::Display for AlterDefaultPrivilegesOperation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Grant {
privileges,
grantees,
with_grant_option,
} => {
write!(
f,
"GRANT {privileges} ON TABLES TO {}",
display_comma_separated(grantees)
)?;
if *with_grant_option {
write!(f, " WITH GRANT OPTION")?;
}
Ok(())
}
Self::Revoke {
grant_option_for,
privileges,
grantees,
cascade,
} => {
write!(
f,
"REVOKE {}{privileges} ON TABLES FROM {}",
if *grant_option_for {
"GRANT OPTION FOR "
} else {
""
},
display_comma_separated(grantees)
)?;
if let Some(cascade) = cascade {
write!(f, " {cascade}")?;
}
Ok(())
}
}
}
}

/// REVOKE privileges ON objects FROM grantees
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down
5 changes: 4 additions & 1 deletion src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5546,13 +5546,16 @@ pub enum AlterFunctionKind {
Function,
/// `AGGREGATE`
Aggregate,
/// `ROUTINE`
Routine,
}

impl fmt::Display for AlterFunctionKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Function => write!(f, "FUNCTION"),
Self::Aggregate => write!(f, "AGGREGATE"),
Self::Routine => write!(f, "ROUTINE"),
}
}
}
Expand Down Expand Up @@ -5627,7 +5630,7 @@ impl fmt::Display for AlterFunction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ALTER {} ", self.kind)?;
match self.kind {
AlterFunctionKind::Function => {
AlterFunctionKind::Function | AlterFunctionKind::Routine => {
write!(f, "{} ", self.function)?;
}
AlterFunctionKind::Aggregate => {
Expand Down
91 changes: 88 additions & 3 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pub use self::data_type::{
ExactNumberInfo, IntervalFields, StructBracketKind, TimezoneInfo,
};
pub use self::dcl::{
AlterRoleOperation, CreateRole, Grant, ResetConfig, Revoke, RoleOption, SecondaryRoles,
SetConfigValue, Use,
AlterDefaultPrivilegesOperation, AlterRoleOperation, CreateRole, Grant, ResetConfig, Revoke,
RoleOption, SecondaryRoles, SetConfigValue, Use,
};
pub use self::ddl::{
Alignment, AlterCollation, AlterCollationOperation, AlterColumnOperation, AlterColumnStorage,
Expand Down Expand Up @@ -3956,6 +3956,17 @@ pub enum Statement {
/// ```
DropFunction(DropFunction),
/// ```sql
/// DROP ROUTINE
/// ```
DropRoutine {
/// `true` when `IF EXISTS` was present.
if_exists: bool,
/// One or more routines to drop.
routine_desc: Vec<FunctionDesc>,
/// Optional drop behavior (`CASCADE` or `RESTRICT`).
drop_behavior: Option<DropBehavior>,
},
/// ```sql
/// DROP DOMAIN
/// ```
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-dropdomain.html)
Expand Down Expand Up @@ -4319,6 +4330,24 @@ pub enum Statement {
/// See <https://docs.snowflake.com/en/sql-reference/sql/comment>
if_exists: bool,
},
/// PostgreSQL `COMMENT ON ROUTINE`.
CommentRoutine {
/// Routine signature.
routine: FunctionDesc,
/// Comment text, or `NULL` to remove it.
comment: Option<String>,
/// `true` when `IF EXISTS` was present.
if_exists: bool,
},
/// PostgreSQL `ALTER DEFAULT PRIVILEGES`.
AlterDefaultPrivileges {
/// Optional roles whose default privileges are changed.
target_roles: Vec<ObjectName>,
/// Optional schemas limiting the change.
schemas: Vec<ObjectName>,
/// Grant or revoke operation.
operation: AlterDefaultPrivilegesOperation,
},
/// ```sql
/// COMMIT [ TRANSACTION | WORK ] [ AND [ NO ] CHAIN ]
/// ```
Expand Down Expand Up @@ -4385,6 +4414,8 @@ pub enum Statement {
///
/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/create-clone#databases-schemas)
clone: Option<ObjectName>,
/// Statements contained in the schema definition.
statements: Vec<Statement>,
},
/// ```sql
/// CREATE DATABASE
Expand Down Expand Up @@ -5676,6 +5707,22 @@ impl fmt::Display for Statement {
Ok(())
}
Statement::DropFunction(drop_function) => write!(f, "{drop_function}"),
Statement::DropRoutine {
if_exists,
routine_desc,
drop_behavior,
} => {
write!(
f,
"DROP ROUTINE{} {}",
if *if_exists { " IF EXISTS" } else { "" },
display_comma_separated(routine_desc),
)?;
if let Some(op) = drop_behavior {
write!(f, " {op}")?;
}
Ok(())
}
Statement::DropDomain(DropDomain {
if_exists,
name,
Expand Down Expand Up @@ -5984,6 +6031,7 @@ impl fmt::Display for Statement {
options,
default_collate_spec,
clone,
statements,
} => {
write!(
f,
Expand All @@ -6007,6 +6055,11 @@ impl fmt::Display for Statement {
if let Some(clone) = clone {
write!(f, " CLONE {clone}")?;
}

for statement in statements {
write!(f, " {statement}")?;
}

Ok(())
}
Statement::Assert { condition, message } => {
Expand Down Expand Up @@ -6197,6 +6250,35 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::CommentRoutine {
routine,
comment,
if_exists,
} => {
write!(
f,
"COMMENT{} ON ROUTINE {routine} IS {}",
if *if_exists { " IF EXISTS" } else { "" },
comment
.as_ref()
.map(|c| format!("'{}'", value::escape_single_quote_string(c)))
.unwrap_or_else(|| "NULL".to_string())
)
}
Statement::AlterDefaultPrivileges {
target_roles,
schemas,
operation,
} => {
write!(f, "ALTER DEFAULT PRIVILEGES")?;
if !target_roles.is_empty() {
write!(f, " FOR ROLE {}", display_comma_separated(target_roles))?;
}
if !schemas.is_empty() {
write!(f, " IN SCHEMA {}", display_comma_separated(schemas))?;
}
write!(f, " {operation}")
}
Statement::CopyIntoSnowflake {
kind,
into,
Expand Down Expand Up @@ -7450,7 +7532,7 @@ impl fmt::Display for Grantee {
write!(f, "GROUP ")?;
}
GranteesType::Public => {
write!(f, "PUBLIC ")?;
write!(f, "PUBLIC{}", if self.name.is_some() { " " } else { "" })?;
}
GranteesType::DatabaseRole => {
write!(f, "DATABASE ROLE ")?;
Expand Down Expand Up @@ -7638,6 +7720,8 @@ pub enum GrantObjects {
/// Optional argument types for overloaded functions.
arg_types: Vec<DataType>,
},
/// Grant privileges on a routine.
Routine(FunctionDesc),
}

impl fmt::Display for GrantObjects {
Expand Down Expand Up @@ -7783,6 +7867,7 @@ impl fmt::Display for GrantObjects {
}
Ok(())
}
GrantObjects::Routine(routine) => write!(f, "ROUTINE {routine}"),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3561,6 +3561,8 @@ impl fmt::Display for LockClause {
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
/// The lock type used in `FOR <lock>` clauses (e.g. `FOR SHARE`, `FOR UPDATE`).
pub enum LockType {
/// `KEY SHARE` lock.
KeyShare,
/// `SHARE` lock (shared lock).
Share,
/// `UPDATE` lock (exclusive/update lock).
Expand All @@ -3570,6 +3572,7 @@ pub enum LockType {
impl fmt::Display for LockType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let select_lock = match self {
LockType::KeyShare => "KEY SHARE",
LockType::Share => "SHARE",
LockType::Update => "UPDATE",
};
Expand Down
3 changes: 3 additions & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ impl Spanned for Statement {
Statement::DetachDuckDBDatabase { .. } => Span::empty(),
Statement::Drop { .. } => Span::empty(),
Statement::DropFunction(drop_function) => drop_function.span(),
Statement::DropRoutine { .. } => Span::empty(),
Statement::DropDomain { .. } => Span::empty(),
Statement::DropProcedure { .. } => Span::empty(),
Statement::DropSecret { .. } => Span::empty(),
Expand All @@ -446,6 +447,8 @@ impl Spanned for Statement {
Statement::Use(u) => u.span(),
Statement::StartTransaction { .. } => Span::empty(),
Statement::Comment { .. } => Span::empty(),
Statement::CommentRoutine { .. } => Span::empty(),
Statement::AlterDefaultPrivileges { .. } => Span::empty(),
Statement::Commit { .. } => Span::empty(),
Statement::Rollback { .. } => Span::empty(),
Statement::CreateSchema { .. } => Span::empty(),
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ define_keywords!(
ROLLBACK,
ROLLUP,
ROOT,
ROUTINE,
ROW,
ROWGROUPSIZE,
ROWID,
Expand Down
Loading
Loading