mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
truncate: table as optional keyword (#883)
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
This commit is contained in:
parent
097e7ad56e
commit
3be19c7666
3 changed files with 20 additions and 2 deletions
|
@ -1142,6 +1142,8 @@ pub enum Statement {
|
|||
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
|
||||
table_name: ObjectName,
|
||||
partitions: Option<Vec<Expr>>,
|
||||
/// TABLE - optional keyword;
|
||||
table: bool,
|
||||
},
|
||||
/// Msck (Hive)
|
||||
Msck {
|
||||
|
@ -1844,8 +1846,10 @@ impl fmt::Display for Statement {
|
|||
Statement::Truncate {
|
||||
table_name,
|
||||
partitions,
|
||||
table,
|
||||
} => {
|
||||
write!(f, "TRUNCATE TABLE {table_name}")?;
|
||||
let table = if *table { "TABLE " } else { "" };
|
||||
write!(f, "TRUNCATE {table}{table_name}")?;
|
||||
if let Some(ref parts) = partitions {
|
||||
if !parts.is_empty() {
|
||||
write!(f, " PARTITION ({})", display_comma_separated(parts))?;
|
||||
|
|
|
@ -473,7 +473,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
pub fn parse_truncate(&mut self) -> Result<Statement, ParserError> {
|
||||
self.expect_keyword(Keyword::TABLE)?;
|
||||
let table = self.parse_keyword(Keyword::TABLE);
|
||||
let table_name = self.parse_object_name()?;
|
||||
let mut partitions = None;
|
||||
if self.parse_keyword(Keyword::PARTITION) {
|
||||
|
@ -484,6 +484,7 @@ impl<'a> Parser<'a> {
|
|||
Ok(Statement::Truncate {
|
||||
table_name,
|
||||
partitions,
|
||||
table,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -2950,3 +2950,16 @@ fn parse_select_group_by_cube() {
|
|||
select.group_by
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_truncate() {
|
||||
let truncate = pg_and_generic().verified_stmt("TRUNCATE db.table_name");
|
||||
assert_eq!(
|
||||
Statement::Truncate {
|
||||
table_name: ObjectName(vec![Ident::new("db"), Ident::new("table_name")]),
|
||||
partitions: None,
|
||||
table: false
|
||||
},
|
||||
truncate
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue