mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-23 07:24:10 +00:00
Replace ReferentialAction
enum in DROP
statements (#1648)
This commit is contained in:
parent
62bcaa1c98
commit
397bceb241
5 changed files with 53 additions and 33 deletions
|
@ -1786,6 +1786,26 @@ impl fmt::Display for ReferentialAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `<drop behavior> ::= CASCADE | RESTRICT`.
|
||||||
|
///
|
||||||
|
/// Used in `DROP` statements.
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
|
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||||
|
pub enum DropBehavior {
|
||||||
|
Restrict,
|
||||||
|
Cascade,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for DropBehavior {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
DropBehavior::Restrict => "RESTRICT",
|
||||||
|
DropBehavior::Cascade => "CASCADE",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// SQL user defined type definition
|
/// SQL user defined type definition
|
||||||
#[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))]
|
||||||
|
|
|
@ -49,12 +49,12 @@ pub use self::dcl::{
|
||||||
pub use self::ddl::{
|
pub use self::ddl::{
|
||||||
AlterColumnOperation, AlterIndexOperation, AlterPolicyOperation, AlterTableOperation,
|
AlterColumnOperation, AlterIndexOperation, AlterPolicyOperation, AlterTableOperation,
|
||||||
ClusteredBy, ColumnDef, ColumnOption, ColumnOptionDef, ColumnPolicy, ColumnPolicyProperty,
|
ClusteredBy, ColumnDef, ColumnOption, ColumnOptionDef, ColumnPolicy, ColumnPolicyProperty,
|
||||||
ConstraintCharacteristics, CreateFunction, Deduplicate, DeferrableInitial, GeneratedAs,
|
ConstraintCharacteristics, CreateFunction, Deduplicate, DeferrableInitial, DropBehavior,
|
||||||
GeneratedExpressionMode, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
|
GeneratedAs, GeneratedExpressionMode, IdentityParameters, IdentityProperty,
|
||||||
IdentityPropertyKind, IdentityPropertyOrder, IndexOption, IndexType, KeyOrIndexDisplay,
|
IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder, IndexOption,
|
||||||
NullsDistinctOption, Owner, Partition, ProcedureParam, ReferentialAction, TableConstraint,
|
IndexType, KeyOrIndexDisplay, NullsDistinctOption, Owner, Partition, ProcedureParam,
|
||||||
TagsColumnOption, UserDefinedTypeCompositeAttributeDef, UserDefinedTypeRepresentation,
|
ReferentialAction, TableConstraint, TagsColumnOption, UserDefinedTypeCompositeAttributeDef,
|
||||||
ViewColumnDef,
|
UserDefinedTypeRepresentation, ViewColumnDef,
|
||||||
};
|
};
|
||||||
pub use self::dml::{CreateIndex, CreateTable, Delete, Insert};
|
pub use self::dml::{CreateIndex, CreateTable, Delete, Insert};
|
||||||
pub use self::operator::{BinaryOperator, UnaryOperator};
|
pub use self::operator::{BinaryOperator, UnaryOperator};
|
||||||
|
@ -2700,7 +2700,7 @@ pub enum Statement {
|
||||||
/// One or more function to drop
|
/// One or more function to drop
|
||||||
func_desc: Vec<FunctionDesc>,
|
func_desc: Vec<FunctionDesc>,
|
||||||
/// `CASCADE` or `RESTRICT`
|
/// `CASCADE` or `RESTRICT`
|
||||||
option: Option<ReferentialAction>,
|
drop_behavior: Option<DropBehavior>,
|
||||||
},
|
},
|
||||||
/// ```sql
|
/// ```sql
|
||||||
/// DROP PROCEDURE
|
/// DROP PROCEDURE
|
||||||
|
@ -2710,7 +2710,7 @@ pub enum Statement {
|
||||||
/// One or more function to drop
|
/// One or more function to drop
|
||||||
proc_desc: Vec<FunctionDesc>,
|
proc_desc: Vec<FunctionDesc>,
|
||||||
/// `CASCADE` or `RESTRICT`
|
/// `CASCADE` or `RESTRICT`
|
||||||
option: Option<ReferentialAction>,
|
drop_behavior: Option<DropBehavior>,
|
||||||
},
|
},
|
||||||
/// ```sql
|
/// ```sql
|
||||||
/// DROP SECRET
|
/// DROP SECRET
|
||||||
|
@ -2729,7 +2729,7 @@ pub enum Statement {
|
||||||
if_exists: bool,
|
if_exists: bool,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
table_name: ObjectName,
|
table_name: ObjectName,
|
||||||
option: Option<ReferentialAction>,
|
drop_behavior: Option<DropBehavior>,
|
||||||
},
|
},
|
||||||
/// ```sql
|
/// ```sql
|
||||||
/// DECLARE
|
/// DECLARE
|
||||||
|
@ -4317,7 +4317,7 @@ impl fmt::Display for Statement {
|
||||||
Statement::DropFunction {
|
Statement::DropFunction {
|
||||||
if_exists,
|
if_exists,
|
||||||
func_desc,
|
func_desc,
|
||||||
option,
|
drop_behavior,
|
||||||
} => {
|
} => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
@ -4325,7 +4325,7 @@ impl fmt::Display for Statement {
|
||||||
if *if_exists { " IF EXISTS" } else { "" },
|
if *if_exists { " IF EXISTS" } else { "" },
|
||||||
display_comma_separated(func_desc),
|
display_comma_separated(func_desc),
|
||||||
)?;
|
)?;
|
||||||
if let Some(op) = option {
|
if let Some(op) = drop_behavior {
|
||||||
write!(f, " {op}")?;
|
write!(f, " {op}")?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -4333,7 +4333,7 @@ impl fmt::Display for Statement {
|
||||||
Statement::DropProcedure {
|
Statement::DropProcedure {
|
||||||
if_exists,
|
if_exists,
|
||||||
proc_desc,
|
proc_desc,
|
||||||
option,
|
drop_behavior,
|
||||||
} => {
|
} => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
@ -4341,7 +4341,7 @@ impl fmt::Display for Statement {
|
||||||
if *if_exists { " IF EXISTS" } else { "" },
|
if *if_exists { " IF EXISTS" } else { "" },
|
||||||
display_comma_separated(proc_desc),
|
display_comma_separated(proc_desc),
|
||||||
)?;
|
)?;
|
||||||
if let Some(op) = option {
|
if let Some(op) = drop_behavior {
|
||||||
write!(f, " {op}")?;
|
write!(f, " {op}")?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -4370,15 +4370,15 @@ impl fmt::Display for Statement {
|
||||||
if_exists,
|
if_exists,
|
||||||
name,
|
name,
|
||||||
table_name,
|
table_name,
|
||||||
option,
|
drop_behavior,
|
||||||
} => {
|
} => {
|
||||||
write!(f, "DROP POLICY")?;
|
write!(f, "DROP POLICY")?;
|
||||||
if *if_exists {
|
if *if_exists {
|
||||||
write!(f, " IF EXISTS")?;
|
write!(f, " IF EXISTS")?;
|
||||||
}
|
}
|
||||||
write!(f, " {name} ON {table_name}")?;
|
write!(f, " {name} ON {table_name}")?;
|
||||||
if let Some(option) = option {
|
if let Some(drop_behavior) = drop_behavior {
|
||||||
write!(f, " {option}")?;
|
write!(f, " {drop_behavior}")?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5514,10 +5514,10 @@ impl<'a> Parser<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_optional_referential_action(&mut self) -> Option<ReferentialAction> {
|
fn parse_optional_drop_behavior(&mut self) -> Option<DropBehavior> {
|
||||||
match self.parse_one_of_keywords(&[Keyword::CASCADE, Keyword::RESTRICT]) {
|
match self.parse_one_of_keywords(&[Keyword::CASCADE, Keyword::RESTRICT]) {
|
||||||
Some(Keyword::CASCADE) => Some(ReferentialAction::Cascade),
|
Some(Keyword::CASCADE) => Some(DropBehavior::Cascade),
|
||||||
Some(Keyword::RESTRICT) => Some(ReferentialAction::Restrict),
|
Some(Keyword::RESTRICT) => Some(DropBehavior::Restrict),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5529,11 +5529,11 @@ impl<'a> Parser<'a> {
|
||||||
fn parse_drop_function(&mut self) -> Result<Statement, ParserError> {
|
fn parse_drop_function(&mut self) -> Result<Statement, ParserError> {
|
||||||
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
|
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
|
||||||
let func_desc = self.parse_comma_separated(Parser::parse_function_desc)?;
|
let func_desc = self.parse_comma_separated(Parser::parse_function_desc)?;
|
||||||
let option = self.parse_optional_referential_action();
|
let drop_behavior = self.parse_optional_drop_behavior();
|
||||||
Ok(Statement::DropFunction {
|
Ok(Statement::DropFunction {
|
||||||
if_exists,
|
if_exists,
|
||||||
func_desc,
|
func_desc,
|
||||||
option,
|
drop_behavior,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5547,12 +5547,12 @@ impl<'a> Parser<'a> {
|
||||||
let name = self.parse_identifier()?;
|
let name = self.parse_identifier()?;
|
||||||
self.expect_keyword_is(Keyword::ON)?;
|
self.expect_keyword_is(Keyword::ON)?;
|
||||||
let table_name = self.parse_object_name(false)?;
|
let table_name = self.parse_object_name(false)?;
|
||||||
let option = self.parse_optional_referential_action();
|
let drop_behavior = self.parse_optional_drop_behavior();
|
||||||
Ok(Statement::DropPolicy {
|
Ok(Statement::DropPolicy {
|
||||||
if_exists,
|
if_exists,
|
||||||
name,
|
name,
|
||||||
table_name,
|
table_name,
|
||||||
option,
|
drop_behavior,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5563,11 +5563,11 @@ impl<'a> Parser<'a> {
|
||||||
fn parse_drop_procedure(&mut self) -> Result<Statement, ParserError> {
|
fn parse_drop_procedure(&mut self) -> Result<Statement, ParserError> {
|
||||||
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
|
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
|
||||||
let proc_desc = self.parse_comma_separated(Parser::parse_function_desc)?;
|
let proc_desc = self.parse_comma_separated(Parser::parse_function_desc)?;
|
||||||
let option = self.parse_optional_referential_action();
|
let drop_behavior = self.parse_optional_drop_behavior();
|
||||||
Ok(Statement::DropProcedure {
|
Ok(Statement::DropProcedure {
|
||||||
if_exists,
|
if_exists,
|
||||||
proc_desc,
|
proc_desc,
|
||||||
option,
|
drop_behavior,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11760,12 +11760,12 @@ fn test_drop_policy() {
|
||||||
if_exists,
|
if_exists,
|
||||||
name,
|
name,
|
||||||
table_name,
|
table_name,
|
||||||
option,
|
drop_behavior,
|
||||||
} => {
|
} => {
|
||||||
assert_eq!(if_exists, true);
|
assert_eq!(if_exists, true);
|
||||||
assert_eq!(name.to_string(), "my_policy");
|
assert_eq!(name.to_string(), "my_policy");
|
||||||
assert_eq!(table_name.to_string(), "my_table");
|
assert_eq!(table_name.to_string(), "my_table");
|
||||||
assert_eq!(option, Some(ReferentialAction::Restrict));
|
assert_eq!(drop_behavior, Some(DropBehavior::Restrict));
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -3805,7 +3805,7 @@ fn parse_drop_function() {
|
||||||
}]),
|
}]),
|
||||||
args: None
|
args: None
|
||||||
}],
|
}],
|
||||||
option: None
|
drop_behavior: None
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3830,7 +3830,7 @@ fn parse_drop_function() {
|
||||||
}
|
}
|
||||||
]),
|
]),
|
||||||
}],
|
}],
|
||||||
option: None
|
drop_behavior: None
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3879,7 +3879,7 @@ fn parse_drop_function() {
|
||||||
]),
|
]),
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
option: None
|
drop_behavior: None
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3899,7 +3899,7 @@ fn parse_drop_procedure() {
|
||||||
}]),
|
}]),
|
||||||
args: None
|
args: None
|
||||||
}],
|
}],
|
||||||
option: None
|
drop_behavior: None
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3924,7 +3924,7 @@ fn parse_drop_procedure() {
|
||||||
}
|
}
|
||||||
]),
|
]),
|
||||||
}],
|
}],
|
||||||
option: None
|
drop_behavior: None
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3973,7 +3973,7 @@ fn parse_drop_procedure() {
|
||||||
]),
|
]),
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
option: None
|
drop_behavior: None
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue