mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-26 23:49:10 +00:00
feat: support postgres alter schema (#2038)
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
This commit is contained in:
parent
ea7f9026f7
commit
0b723147b6
4 changed files with 87 additions and 1 deletions
|
@ -3084,6 +3084,7 @@ impl fmt::Display for CreateConnector {
|
||||||
/// An `ALTER SCHEMA` (`Statement::AlterSchema`) operation.
|
/// An `ALTER SCHEMA` (`Statement::AlterSchema`) operation.
|
||||||
///
|
///
|
||||||
/// See [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#alter_schema_collate_statement)
|
/// See [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#alter_schema_collate_statement)
|
||||||
|
/// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-alterschema.html)
|
||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||||
|
@ -3101,6 +3102,12 @@ pub enum AlterSchemaOperation {
|
||||||
SetOptionsParens {
|
SetOptionsParens {
|
||||||
options: Vec<SqlOption>,
|
options: Vec<SqlOption>,
|
||||||
},
|
},
|
||||||
|
Rename {
|
||||||
|
name: ObjectName,
|
||||||
|
},
|
||||||
|
OwnerTo {
|
||||||
|
owner: Owner,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for AlterSchemaOperation {
|
impl fmt::Display for AlterSchemaOperation {
|
||||||
|
@ -3120,6 +3127,8 @@ impl fmt::Display for AlterSchemaOperation {
|
||||||
AlterSchemaOperation::SetOptionsParens { options } => {
|
AlterSchemaOperation::SetOptionsParens { options } => {
|
||||||
write!(f, "SET OPTIONS ({})", display_comma_separated(options))
|
write!(f, "SET OPTIONS ({})", display_comma_separated(options))
|
||||||
}
|
}
|
||||||
|
AlterSchemaOperation::Rename { name } => write!(f, "RENAME TO {name}"),
|
||||||
|
AlterSchemaOperation::OwnerTo { owner } => write!(f, "OWNER TO {owner}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
use crate::ast::{
|
use crate::ast::{
|
||||||
ddl::AlterSchema, query::SelectItemQualifiedWildcardKind, AlterSchemaOperation, ColumnOptions,
|
ddl::AlterSchema, query::SelectItemQualifiedWildcardKind, AlterSchemaOperation, ColumnOptions,
|
||||||
ExportData, TypedString,
|
ExportData, Owner, TypedString,
|
||||||
};
|
};
|
||||||
use core::iter;
|
use core::iter;
|
||||||
|
|
||||||
|
@ -2424,6 +2424,14 @@ impl Spanned for AlterSchemaOperation {
|
||||||
AlterSchemaOperation::SetOptionsParens { options } => {
|
AlterSchemaOperation::SetOptionsParens { options } => {
|
||||||
union_spans(options.iter().map(|i| i.span()))
|
union_spans(options.iter().map(|i| i.span()))
|
||||||
}
|
}
|
||||||
|
AlterSchemaOperation::Rename { name } => name.span(),
|
||||||
|
AlterSchemaOperation::OwnerTo { owner } => {
|
||||||
|
if let Owner::Ident(ident) = owner {
|
||||||
|
ident.span
|
||||||
|
} else {
|
||||||
|
Span::empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9444,6 +9444,12 @@ impl<'a> Parser<'a> {
|
||||||
} else if self.parse_keywords(&[Keyword::DROP, Keyword::REPLICA]) {
|
} else if self.parse_keywords(&[Keyword::DROP, Keyword::REPLICA]) {
|
||||||
let replica = self.parse_identifier()?;
|
let replica = self.parse_identifier()?;
|
||||||
AlterSchemaOperation::DropReplica { replica }
|
AlterSchemaOperation::DropReplica { replica }
|
||||||
|
} else if self.parse_keywords(&[Keyword::RENAME, Keyword::TO]) {
|
||||||
|
let new_name = self.parse_object_name(false)?;
|
||||||
|
AlterSchemaOperation::Rename { name: new_name }
|
||||||
|
} else if self.parse_keywords(&[Keyword::OWNER, Keyword::TO]) {
|
||||||
|
let owner = self.parse_owner()?;
|
||||||
|
AlterSchemaOperation::OwnerTo { owner }
|
||||||
} else {
|
} else {
|
||||||
return self.expected_ref("ALTER SCHEMA operation", self.peek_token_ref());
|
return self.expected_ref("ALTER SCHEMA operation", self.peek_token_ref());
|
||||||
};
|
};
|
||||||
|
|
|
@ -6576,3 +6576,66 @@ fn parse_create_server() {
|
||||||
assert_eq!(stmt, expected);
|
assert_eq!(stmt, expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_alter_schema() {
|
||||||
|
match pg_and_generic().verified_stmt("ALTER SCHEMA foo RENAME TO bar") {
|
||||||
|
Statement::AlterSchema(AlterSchema { operations, .. }) => {
|
||||||
|
assert_eq!(
|
||||||
|
operations,
|
||||||
|
vec![AlterSchemaOperation::Rename {
|
||||||
|
name: ObjectName::from(vec!["bar".into()])
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
|
||||||
|
match pg_and_generic().verified_stmt("ALTER SCHEMA foo OWNER TO bar") {
|
||||||
|
Statement::AlterSchema(AlterSchema { operations, .. }) => {
|
||||||
|
assert_eq!(
|
||||||
|
operations,
|
||||||
|
vec![AlterSchemaOperation::OwnerTo {
|
||||||
|
owner: Owner::Ident("bar".into())
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
|
||||||
|
match pg_and_generic().verified_stmt("ALTER SCHEMA foo OWNER TO CURRENT_ROLE") {
|
||||||
|
Statement::AlterSchema(AlterSchema { operations, .. }) => {
|
||||||
|
assert_eq!(
|
||||||
|
operations,
|
||||||
|
vec![AlterSchemaOperation::OwnerTo {
|
||||||
|
owner: Owner::CurrentRole
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
|
||||||
|
match pg_and_generic().verified_stmt("ALTER SCHEMA foo OWNER TO CURRENT_USER") {
|
||||||
|
Statement::AlterSchema(AlterSchema { operations, .. }) => {
|
||||||
|
assert_eq!(
|
||||||
|
operations,
|
||||||
|
vec![AlterSchemaOperation::OwnerTo {
|
||||||
|
owner: Owner::CurrentUser
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
|
||||||
|
match pg_and_generic().verified_stmt("ALTER SCHEMA foo OWNER TO SESSION_USER") {
|
||||||
|
Statement::AlterSchema(AlterSchema { operations, .. }) => {
|
||||||
|
assert_eq!(
|
||||||
|
operations,
|
||||||
|
vec![AlterSchemaOperation::OwnerTo {
|
||||||
|
owner: Owner::SessionUser
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue