mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-26 15:39:12 +00:00
Rename AlterOperation -> AlterTableOperation
Since other ALTER statements will have separate sub-commands.
This commit is contained in:
parent
aab0c36443
commit
8569a61fd0
4 changed files with 9 additions and 9 deletions
|
@ -4,18 +4,18 @@ use super::{ASTNode, SQLIdent, SQLObjectName};
|
||||||
|
|
||||||
/// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation
|
/// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum AlterOperation {
|
pub enum AlterTableOperation {
|
||||||
/// `ADD <table_constraint>`
|
/// `ADD <table_constraint>`
|
||||||
AddConstraint(TableConstraint),
|
AddConstraint(TableConstraint),
|
||||||
/// TODO: implement `DROP CONSTRAINT name`
|
/// TODO: implement `DROP CONSTRAINT <name>`
|
||||||
DropConstraint { name: SQLIdent },
|
DropConstraint { name: SQLIdent },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for AlterOperation {
|
impl ToString for AlterTableOperation {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
AlterOperation::AddConstraint(constraint) => format!("ADD {}", constraint.to_string()),
|
AlterTableOperation::AddConstraint(c) => format!("ADD {}", c.to_string()),
|
||||||
AlterOperation::DropConstraint { name } => format!("DROP CONSTRAINT {}", name),
|
AlterTableOperation::DropConstraint { name } => format!("DROP CONSTRAINT {}", name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ mod sql_operator;
|
||||||
mod sqltype;
|
mod sqltype;
|
||||||
mod value;
|
mod value;
|
||||||
|
|
||||||
pub use self::ddl::{AlterOperation, TableConstraint};
|
pub use self::ddl::{AlterTableOperation, TableConstraint};
|
||||||
pub use self::query::{
|
pub use self::query::{
|
||||||
Cte, Fetch, Join, JoinConstraint, JoinOperator, SQLOrderByExpr, SQLQuery, SQLSelect,
|
Cte, Fetch, Join, JoinConstraint, JoinOperator, SQLOrderByExpr, SQLQuery, SQLSelect,
|
||||||
SQLSelectItem, SQLSetExpr, SQLSetOperator, TableFactor,
|
SQLSelectItem, SQLSetExpr, SQLSetOperator, TableFactor,
|
||||||
|
@ -405,7 +405,7 @@ pub enum SQLStatement {
|
||||||
SQLAlterTable {
|
SQLAlterTable {
|
||||||
/// Table name
|
/// Table name
|
||||||
name: SQLObjectName,
|
name: SQLObjectName,
|
||||||
operation: AlterOperation,
|
operation: AlterTableOperation,
|
||||||
},
|
},
|
||||||
/// DROP TABLE
|
/// DROP TABLE
|
||||||
SQLDrop {
|
SQLDrop {
|
||||||
|
|
|
@ -974,7 +974,7 @@ impl Parser {
|
||||||
let table_name = self.parse_object_name()?;
|
let table_name = self.parse_object_name()?;
|
||||||
let operation = if self.parse_keyword("ADD") {
|
let operation = if self.parse_keyword("ADD") {
|
||||||
if let Some(constraint) = self.parse_optional_table_constraint()? {
|
if let Some(constraint) = self.parse_optional_table_constraint()? {
|
||||||
AlterOperation::AddConstraint(constraint)
|
AlterTableOperation::AddConstraint(constraint)
|
||||||
} else {
|
} else {
|
||||||
return self.expected("a constraint in ALTER TABLE .. ADD", self.peek_token());
|
return self.expected("a constraint in ALTER TABLE .. ADD", self.peek_token());
|
||||||
}
|
}
|
||||||
|
|
|
@ -758,7 +758,7 @@ fn parse_alter_table_constraints() {
|
||||||
match verified_stmt(&format!("ALTER TABLE tab ADD {}", constraint_text)) {
|
match verified_stmt(&format!("ALTER TABLE tab ADD {}", constraint_text)) {
|
||||||
SQLStatement::SQLAlterTable {
|
SQLStatement::SQLAlterTable {
|
||||||
name,
|
name,
|
||||||
operation: AlterOperation::AddConstraint(constraint),
|
operation: AlterTableOperation::AddConstraint(constraint),
|
||||||
} => {
|
} => {
|
||||||
assert_eq!("tab", name.to_string());
|
assert_eq!("tab", name.to_string());
|
||||||
assert_eq!(constraint_text, constraint.to_string());
|
assert_eq!(constraint_text, constraint.to_string());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue