@@ -33,7 +33,7 @@ pub use self::data_type::{
3333pub use self :: dcl:: { AlterRoleOperation , ResetConfig , RoleOption , SetConfigValue } ;
3434pub use self :: ddl:: {
3535 AlterColumnOperation , AlterIndexOperation , AlterTableOperation , ColumnDef , ColumnOption ,
36- ColumnOptionDef , ConstraintCharacteristics , DeferrableInitial , GeneratedAs ,
36+ ColumnOptionDef , ConstraintCharacteristics , Deduplicate , DeferrableInitial , GeneratedAs ,
3737 GeneratedExpressionMode , IndexOption , IndexType , KeyOrIndexDisplay , Owner , Partition ,
3838 ProcedureParam , ReferentialAction , TableConstraint , UserDefinedTypeCompositeAttributeDef ,
3939 UserDefinedTypeRepresentation , ViewColumnDef ,
@@ -2831,6 +2831,18 @@ pub enum Statement {
28312831 to : Ident ,
28322832 with : Vec < SqlOption > ,
28332833 } ,
2834+ /// ```sql
2835+ /// OPTIMIZE TABLE [db.]name [ON CLUSTER cluster] [PARTITION partition | PARTITION ID 'partition_id'] [FINAL] [DEDUPLICATE [BY expression]]
2836+ /// ```
2837+ ///
2838+ /// See ClickHouse <https://clickhouse.com/docs/en/sql-reference/statements/optimize>
2839+ OptimizeTable {
2840+ name : ObjectName ,
2841+ on_cluster : Option < Ident > ,
2842+ partition : Option < Partition > ,
2843+ include_final : bool ,
2844+ deduplicate : Option < Deduplicate > ,
2845+ } ,
28342846}
28352847
28362848impl fmt:: Display for Statement {
@@ -4283,6 +4295,28 @@ impl fmt::Display for Statement {
42834295
42844296 Ok ( ( ) )
42854297 }
4298+ Statement :: OptimizeTable {
4299+ name,
4300+ on_cluster,
4301+ partition,
4302+ include_final,
4303+ deduplicate,
4304+ } => {
4305+ write ! ( f, "OPTIMIZE TABLE {name}" ) ?;
4306+ if let Some ( on_cluster) = on_cluster {
4307+ write ! ( f, " ON CLUSTER {on_cluster}" , on_cluster = on_cluster) ?;
4308+ }
4309+ if let Some ( partition) = partition {
4310+ write ! ( f, " {partition}" , partition = partition) ?;
4311+ }
4312+ if * include_final {
4313+ write ! ( f, " FINAL" ) ?;
4314+ }
4315+ if let Some ( deduplicate) = deduplicate {
4316+ write ! ( f, " {deduplicate}" ) ?;
4317+ }
4318+ Ok ( ( ) )
4319+ }
42864320 }
42874321 }
42884322}
0 commit comments