mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-23 07:24:10 +00:00
Support DROP TEMPORARY TABLE
, MySQL syntax (#916)
This commit is contained in:
parent
10a6ec5637
commit
eb4be98980
4 changed files with 40 additions and 1 deletions
|
@ -1401,6 +1401,8 @@ pub enum Statement {
|
|||
/// Hive allows you specify whether the table's stored data will be
|
||||
/// deleted along with the dropped table
|
||||
purge: bool,
|
||||
/// MySQL-specific "TEMPORARY" keyword
|
||||
temporary: bool,
|
||||
},
|
||||
/// DROP Function
|
||||
DropFunction {
|
||||
|
@ -2572,9 +2574,11 @@ impl fmt::Display for Statement {
|
|||
cascade,
|
||||
restrict,
|
||||
purge,
|
||||
temporary,
|
||||
} => write!(
|
||||
f,
|
||||
"DROP {}{} {}{}{}{}",
|
||||
"DROP {}{}{} {}{}{}{}",
|
||||
if *temporary { "TEMPORARY " } else { "" },
|
||||
object_type,
|
||||
if *if_exists { " IF EXISTS" } else { "" },
|
||||
display_comma_separated(names),
|
||||
|
|
|
@ -3127,6 +3127,10 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
pub fn parse_drop(&mut self) -> Result<Statement, ParserError> {
|
||||
// MySQL dialect supports `TEMPORARY`
|
||||
let temporary = dialect_of!(self is MySqlDialect | GenericDialect)
|
||||
&& self.parse_keyword(Keyword::TEMPORARY);
|
||||
|
||||
let object_type = if self.parse_keyword(Keyword::TABLE) {
|
||||
ObjectType::Table
|
||||
} else if self.parse_keyword(Keyword::VIEW) {
|
||||
|
@ -3169,6 +3173,7 @@ impl<'a> Parser<'a> {
|
|||
cascade,
|
||||
restrict,
|
||||
purge,
|
||||
temporary,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -5432,6 +5432,7 @@ fn parse_drop_table() {
|
|||
names,
|
||||
cascade,
|
||||
purge: _,
|
||||
temporary,
|
||||
..
|
||||
} => {
|
||||
assert!(!if_exists);
|
||||
|
@ -5441,6 +5442,7 @@ fn parse_drop_table() {
|
|||
names.iter().map(ToString::to_string).collect::<Vec<_>>()
|
||||
);
|
||||
assert!(!cascade);
|
||||
assert!(!temporary);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
@ -5453,6 +5455,7 @@ fn parse_drop_table() {
|
|||
names,
|
||||
cascade,
|
||||
purge: _,
|
||||
temporary,
|
||||
..
|
||||
} => {
|
||||
assert!(if_exists);
|
||||
|
@ -5462,6 +5465,7 @@ fn parse_drop_table() {
|
|||
names.iter().map(ToString::to_string).collect::<Vec<_>>()
|
||||
);
|
||||
assert!(cascade);
|
||||
assert!(!temporary);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
|
@ -1597,3 +1597,29 @@ fn parse_string_introducers() {
|
|||
fn parse_div_infix() {
|
||||
mysql().verified_stmt(r#"SELECT 5 DIV 2"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_drop_temporary_table() {
|
||||
let sql = "DROP TEMPORARY TABLE foo";
|
||||
match mysql().verified_stmt(sql) {
|
||||
Statement::Drop {
|
||||
object_type,
|
||||
if_exists,
|
||||
names,
|
||||
cascade,
|
||||
purge: _,
|
||||
temporary,
|
||||
..
|
||||
} => {
|
||||
assert!(!if_exists);
|
||||
assert_eq!(ObjectType::Table, object_type);
|
||||
assert_eq!(
|
||||
vec!["foo"],
|
||||
names.iter().map(ToString::to_string).collect::<Vec<_>>()
|
||||
);
|
||||
assert!(!cascade);
|
||||
assert!(temporary);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue