mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-21 21:22:28 +00:00
Allow to use ON CLUSTER cluster_name in TRUNCATE syntax (#1428)
This commit is contained in:
parent
246838a69f
commit
1c505ce736
4 changed files with 38 additions and 2 deletions
|
@ -2172,6 +2172,11 @@ pub enum Statement {
|
|||
/// Postgres-specific option
|
||||
/// [ CASCADE | RESTRICT ]
|
||||
cascade: Option<TruncateCascadeOption>,
|
||||
/// ClickHouse-specific option
|
||||
/// [ ON CLUSTER cluster_name ]
|
||||
///
|
||||
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/truncate/)
|
||||
on_cluster: Option<Ident>,
|
||||
},
|
||||
/// ```sql
|
||||
/// MSCK
|
||||
|
@ -3293,6 +3298,7 @@ impl fmt::Display for Statement {
|
|||
only,
|
||||
identity,
|
||||
cascade,
|
||||
on_cluster,
|
||||
} => {
|
||||
let table = if *table { "TABLE " } else { "" };
|
||||
let only = if *only { "ONLY " } else { "" };
|
||||
|
@ -3321,6 +3327,9 @@ impl fmt::Display for Statement {
|
|||
write!(f, " PARTITION ({})", display_comma_separated(parts))?;
|
||||
}
|
||||
}
|
||||
if let Some(on_cluster) = on_cluster {
|
||||
write!(f, " ON CLUSTER {on_cluster}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Statement::AttachDatabase {
|
||||
|
|
|
@ -708,6 +708,8 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
};
|
||||
|
||||
let on_cluster = self.parse_optional_on_cluster()?;
|
||||
|
||||
Ok(Statement::Truncate {
|
||||
table_names,
|
||||
partitions,
|
||||
|
@ -715,6 +717,7 @@ impl<'a> Parser<'a> {
|
|||
only,
|
||||
identity,
|
||||
cascade,
|
||||
on_cluster,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -10804,3 +10804,24 @@ fn test_extract_seconds_single_quote_err() {
|
|||
"sql parser error: Expected: date/time field, found: 'seconds'"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_truncate_table_with_on_cluster() {
|
||||
let sql = "TRUNCATE TABLE t ON CLUSTER cluster_name";
|
||||
match all_dialects().verified_stmt(sql) {
|
||||
Statement::Truncate { on_cluster, .. } => {
|
||||
assert_eq!(on_cluster, Some(Ident::new("cluster_name")));
|
||||
}
|
||||
_ => panic!("Expected: TRUNCATE TABLE statement"),
|
||||
}
|
||||
|
||||
// Omit ON CLUSTER is allowed
|
||||
all_dialects().verified_stmt("TRUNCATE TABLE t");
|
||||
|
||||
assert_eq!(
|
||||
ParserError::ParserError("Expected: identifier, found: EOF".to_string()),
|
||||
all_dialects()
|
||||
.parse_sql_statements("TRUNCATE TABLE t ON CLUSTER")
|
||||
.unwrap_err()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4010,6 +4010,7 @@ fn parse_truncate() {
|
|||
only: false,
|
||||
identity: None,
|
||||
cascade: None,
|
||||
on_cluster: None,
|
||||
},
|
||||
truncate
|
||||
);
|
||||
|
@ -4032,7 +4033,8 @@ fn parse_truncate_with_options() {
|
|||
table: true,
|
||||
only: true,
|
||||
identity: Some(TruncateIdentityOption::Restart),
|
||||
cascade: Some(TruncateCascadeOption::Cascade)
|
||||
cascade: Some(TruncateCascadeOption::Cascade),
|
||||
on_cluster: None,
|
||||
},
|
||||
truncate
|
||||
);
|
||||
|
@ -4063,7 +4065,8 @@ fn parse_truncate_with_table_list() {
|
|||
table: true,
|
||||
only: false,
|
||||
identity: Some(TruncateIdentityOption::Restart),
|
||||
cascade: Some(TruncateCascadeOption::Cascade)
|
||||
cascade: Some(TruncateCascadeOption::Cascade),
|
||||
on_cluster: None,
|
||||
},
|
||||
truncate
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue