File tree 4 files changed +38
-2
lines changed
4 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -2172,6 +2172,11 @@ pub enum Statement {
2172
2172
/// Postgres-specific option
2173
2173
/// [ CASCADE | RESTRICT ]
2174
2174
cascade : Option < TruncateCascadeOption > ,
2175
+ /// ClickHouse-specific option
2176
+ /// [ ON CLUSTER cluster_name ]
2177
+ ///
2178
+ /// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/truncate/)
2179
+ on_cluster : Option < Ident > ,
2175
2180
} ,
2176
2181
/// ```sql
2177
2182
/// MSCK
@@ -3293,6 +3298,7 @@ impl fmt::Display for Statement {
3293
3298
only,
3294
3299
identity,
3295
3300
cascade,
3301
+ on_cluster,
3296
3302
} => {
3297
3303
let table = if * table { "TABLE " } else { "" } ;
3298
3304
let only = if * only { "ONLY " } else { "" } ;
@@ -3321,6 +3327,9 @@ impl fmt::Display for Statement {
3321
3327
write ! ( f, " PARTITION ({})" , display_comma_separated( parts) ) ?;
3322
3328
}
3323
3329
}
3330
+ if let Some ( on_cluster) = on_cluster {
3331
+ write ! ( f, " ON CLUSTER {on_cluster}" ) ?;
3332
+ }
3324
3333
Ok ( ( ) )
3325
3334
}
3326
3335
Statement :: AttachDatabase {
Original file line number Diff line number Diff line change @@ -708,13 +708,16 @@ impl<'a> Parser<'a> {
708
708
} ;
709
709
} ;
710
710
711
+ let on_cluster = self . parse_optional_on_cluster ( ) ?;
712
+
711
713
Ok ( Statement :: Truncate {
712
714
table_names,
713
715
partitions,
714
716
table,
715
717
only,
716
718
identity,
717
719
cascade,
720
+ on_cluster,
718
721
} )
719
722
}
720
723
Original file line number Diff line number Diff line change @@ -10804,3 +10804,24 @@ fn test_extract_seconds_single_quote_err() {
10804
10804
"sql parser error: Expected: date/time field, found: 'seconds'"
10805
10805
) ;
10806
10806
}
10807
+
10808
+ #[ test]
10809
+ fn test_truncate_table_with_on_cluster ( ) {
10810
+ let sql = "TRUNCATE TABLE t ON CLUSTER cluster_name" ;
10811
+ match all_dialects ( ) . verified_stmt ( sql) {
10812
+ Statement :: Truncate { on_cluster, .. } => {
10813
+ assert_eq ! ( on_cluster, Some ( Ident :: new( "cluster_name" ) ) ) ;
10814
+ }
10815
+ _ => panic ! ( "Expected: TRUNCATE TABLE statement" ) ,
10816
+ }
10817
+
10818
+ // Omit ON CLUSTER is allowed
10819
+ all_dialects ( ) . verified_stmt ( "TRUNCATE TABLE t" ) ;
10820
+
10821
+ assert_eq ! (
10822
+ ParserError :: ParserError ( "Expected: identifier, found: EOF" . to_string( ) ) ,
10823
+ all_dialects( )
10824
+ . parse_sql_statements( "TRUNCATE TABLE t ON CLUSTER" )
10825
+ . unwrap_err( )
10826
+ ) ;
10827
+ }
Original file line number Diff line number Diff line change @@ -4010,6 +4010,7 @@ fn parse_truncate() {
4010
4010
only: false ,
4011
4011
identity: None ,
4012
4012
cascade: None ,
4013
+ on_cluster: None ,
4013
4014
} ,
4014
4015
truncate
4015
4016
) ;
@@ -4032,7 +4033,8 @@ fn parse_truncate_with_options() {
4032
4033
table: true ,
4033
4034
only: true ,
4034
4035
identity: Some ( TruncateIdentityOption :: Restart ) ,
4035
- cascade: Some ( TruncateCascadeOption :: Cascade )
4036
+ cascade: Some ( TruncateCascadeOption :: Cascade ) ,
4037
+ on_cluster: None ,
4036
4038
} ,
4037
4039
truncate
4038
4040
) ;
@@ -4063,7 +4065,8 @@ fn parse_truncate_with_table_list() {
4063
4065
table: true ,
4064
4066
only: false ,
4065
4067
identity: Some ( TruncateIdentityOption :: Restart ) ,
4066
- cascade: Some ( TruncateCascadeOption :: Cascade )
4068
+ cascade: Some ( TruncateCascadeOption :: Cascade ) ,
4069
+ on_cluster: None ,
4067
4070
} ,
4068
4071
truncate
4069
4072
) ;
You can’t perform that action at this time.
0 commit comments