@@ -432,20 +432,20 @@ pub enum Statement {
432
432
for_columns : bool ,
433
433
cache_metadata : bool ,
434
434
noscan : bool ,
435
- compute_statistics : bool
435
+ compute_statistics : bool ,
436
436
} ,
437
437
/// Truncate (Hive)
438
438
Truncate {
439
439
table_name : ObjectName ,
440
- partitions : Option < Vec < Expr > >
440
+ partitions : Option < Vec < Expr > > ,
441
441
} ,
442
442
/// Msck (Hive)
443
443
Msck {
444
444
table_name : ObjectName ,
445
445
repair : bool ,
446
446
add_partitions : bool ,
447
447
drop_partitions : bool ,
448
- sync_partitions : bool
448
+ sync_partitions : bool ,
449
449
} ,
450
450
/// SELECT
451
451
Query ( Box < Query > ) ,
@@ -460,7 +460,7 @@ pub enum Statement {
460
460
/// A SQL query that specifies what to insert
461
461
source : Box < Query > ,
462
462
/// partitioned insert (Hive)
463
- partitioned : Option < Vec < Expr > >
463
+ partitioned : Option < Vec < Expr > > ,
464
464
} ,
465
465
Copy {
466
466
/// TABLE
@@ -583,8 +583,9 @@ pub enum Statement {
583
583
/// CREATE DATABASE
584
584
CreateDatabase {
585
585
db_name : ObjectName ,
586
- ine : bool , location : Option < String > ,
587
- managed_location : Option < String >
586
+ ine : bool ,
587
+ location : Option < String > ,
588
+ managed_location : Option < String > ,
588
589
} ,
589
590
/// ASSERT <condition> [AS <message>]
590
591
Assert {
@@ -600,15 +601,43 @@ impl fmt::Display for Statement {
600
601
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
601
602
match self {
602
603
Statement :: Query ( s) => write ! ( f, "{}" , s) ,
603
- Statement :: Msck { table_name, repair, add_partitions, drop_partitions, sync_partitions } => {
604
- write ! ( f, "MSCK {repair}TABLE {table}" , repair = if * repair { "REPAIR " } else { "" } , table = table_name) ?;
605
- write ! ( f, "{add}{drop}{sync}" ,
606
- add = if * add_partitions { " ADD PARTITIONS" } else { "" } ,
607
- drop = if * drop_partitions { " DROP PARTITIONS" } else { "" } ,
608
- sync = if * sync_partitions { " SYNC PARTITIONS" } else { "" }
604
+ Statement :: Msck {
605
+ table_name,
606
+ repair,
607
+ add_partitions,
608
+ drop_partitions,
609
+ sync_partitions,
610
+ } => {
611
+ write ! (
612
+ f,
613
+ "MSCK {repair}TABLE {table}" ,
614
+ repair = if * repair { "REPAIR " } else { "" } ,
615
+ table = table_name
616
+ ) ?;
617
+ write ! (
618
+ f,
619
+ "{add}{drop}{sync}" ,
620
+ add = if * add_partitions {
621
+ " ADD PARTITIONS"
622
+ } else {
623
+ ""
624
+ } ,
625
+ drop = if * drop_partitions {
626
+ " DROP PARTITIONS"
627
+ } else {
628
+ ""
629
+ } ,
630
+ sync = if * sync_partitions {
631
+ " SYNC PARTITIONS"
632
+ } else {
633
+ ""
634
+ }
609
635
)
610
636
}
611
- Statement :: Truncate { table_name, partitions } => {
637
+ Statement :: Truncate {
638
+ table_name,
639
+ partitions,
640
+ } => {
612
641
write ! ( f, "TRUNCATE TABLE {}" , table_name) ?;
613
642
if let Some ( ref parts) = partitions {
614
643
if !parts. is_empty ( ) {
@@ -617,7 +646,14 @@ impl fmt::Display for Statement {
617
646
}
618
647
Ok ( ( ) )
619
648
}
620
- Statement :: Analyze { table_name, partitions, for_columns : _, cache_metadata, noscan, compute_statistics } => {
649
+ Statement :: Analyze {
650
+ table_name,
651
+ partitions,
652
+ for_columns : _,
653
+ cache_metadata,
654
+ noscan,
655
+ compute_statistics,
656
+ } => {
621
657
write ! ( f, "ANALYZE TABLE {}" , table_name) ?;
622
658
if let Some ( ref parts) = partitions {
623
659
if !parts. is_empty ( ) {
@@ -643,7 +679,16 @@ impl fmt::Display for Statement {
643
679
columns,
644
680
source,
645
681
} => {
646
- write ! ( f, "INSERT {act} {table_name} " , table_name = table_name, act = if * overwrite { "OVERWRITE TABLE" } else { "INTO" } ) ?;
682
+ write ! (
683
+ f,
684
+ "INSERT {act} {table_name} " ,
685
+ table_name = table_name,
686
+ act = if * overwrite {
687
+ "OVERWRITE TABLE"
688
+ } else {
689
+ "INTO"
690
+ }
691
+ ) ?;
647
692
if !columns. is_empty ( ) {
648
693
write ! ( f, "({}) " , display_comma_separated( columns) ) ?;
649
694
}
@@ -704,7 +749,12 @@ impl fmt::Display for Statement {
704
749
}
705
750
Ok ( ( ) )
706
751
}
707
- Statement :: CreateDatabase { db_name, ine, location, managed_location } => {
752
+ Statement :: CreateDatabase {
753
+ db_name,
754
+ ine,
755
+ location,
756
+ managed_location,
757
+ } => {
708
758
write ! ( f, "CREATE" ) ?;
709
759
if * ine {
710
760
write ! ( f, " IF NOT EXISTS" ) ?;
@@ -786,8 +836,14 @@ impl fmt::Display for Statement {
786
836
}
787
837
788
838
match hive_distribution {
789
- HiveDistributionStyle :: PARTITIONED { columns } => write ! ( f, " PARTITIONED BY ({})" , display_comma_separated( & columns) ) ?,
790
- HiveDistributionStyle :: CLUSTERED { columns, sorted_by, num_buckets } => {
839
+ HiveDistributionStyle :: PARTITIONED { columns } => {
840
+ write ! ( f, " PARTITIONED BY ({})" , display_comma_separated( & columns) ) ?
841
+ }
842
+ HiveDistributionStyle :: CLUSTERED {
843
+ columns,
844
+ sorted_by,
845
+ num_buckets,
846
+ } => {
791
847
write ! ( f, " CLUSTERED BY ({})" , display_comma_separated( & columns) ) ?;
792
848
if !sorted_by. is_empty ( ) {
793
849
write ! ( f, " SORTED BY ({})" , display_comma_separated( & sorted_by) ) ?;
@@ -796,26 +852,50 @@ impl fmt::Display for Statement {
796
852
write ! ( f, " INTO {} BUCKETS" , num_buckets) ?;
797
853
}
798
854
}
799
- HiveDistributionStyle :: SKEWED { columns, on, stored_as_directories } => {
800
- write ! ( f, " SKEWED BY ({})) ON ({})" , display_comma_separated( & columns) , display_comma_separated( & on) ) ?;
855
+ HiveDistributionStyle :: SKEWED {
856
+ columns,
857
+ on,
858
+ stored_as_directories,
859
+ } => {
860
+ write ! (
861
+ f,
862
+ " SKEWED BY ({})) ON ({})" ,
863
+ display_comma_separated( & columns) ,
864
+ display_comma_separated( & on)
865
+ ) ?;
801
866
if * stored_as_directories {
802
867
write ! ( f, " STORED AS DIRECTORIES" ) ?;
803
868
}
804
- } ,
805
- _ => ( )
869
+ }
870
+ _ => ( ) ,
806
871
}
807
872
808
- if let Some ( HiveFormat { row_format, storage, location } ) = hive_formats {
809
-
873
+ if let Some ( HiveFormat {
874
+ row_format,
875
+ storage,
876
+ location,
877
+ } ) = hive_formats
878
+ {
810
879
match row_format {
811
- Some ( HiveRowFormat :: SERDE { class } ) => write ! ( f, " ROW FORMAT SERDE '{}'" , class) ?,
880
+ Some ( HiveRowFormat :: SERDE { class } ) => {
881
+ write ! ( f, " ROW FORMAT SERDE '{}'" , class) ?
882
+ }
812
883
Some ( HiveRowFormat :: DELIMITED ) => write ! ( f, " ROW FORMAT DELIMITED" ) ?,
813
- None => ( )
884
+ None => ( ) ,
814
885
}
815
886
match storage {
816
- Some ( HiveIOFormat :: IOF { input_format, output_format } ) => write ! ( f, " STORED AS INPUTFORMAT {} OUTPUTFORMAT {}" , input_format, output_format) ?,
817
- Some ( HiveIOFormat :: FileFormat { format } ) => write ! ( f, " STORED AS {}" , format) ?,
818
- None => ( )
887
+ Some ( HiveIOFormat :: IOF {
888
+ input_format,
889
+ output_format,
890
+ } ) => write ! (
891
+ f,
892
+ " STORED AS INPUTFORMAT {} OUTPUTFORMAT {}" ,
893
+ input_format, output_format
894
+ ) ?,
895
+ Some ( HiveIOFormat :: FileFormat { format } ) => {
896
+ write ! ( f, " STORED AS {}" , format) ?
897
+ }
898
+ None => ( ) ,
819
899
}
820
900
if let Some ( loc) = location {
821
901
write ! ( f, " LOCATION '{}'" , loc) ?;
@@ -903,7 +983,13 @@ impl fmt::Display for Statement {
903
983
if * local {
904
984
f. write_str ( "LOCAL " ) ?;
905
985
}
906
- write ! ( f, "{hivevar}{name} = {value}" , hivevar = if * hivevar { "HIVEVAR:" } else { "" } , name = variable, value = display_comma_separated( value) )
986
+ write ! (
987
+ f,
988
+ "{hivevar}{name} = {value}" ,
989
+ hivevar = if * hivevar { "HIVEVAR:" } else { "" } ,
990
+ name = variable,
991
+ value = display_comma_separated( value)
992
+ )
907
993
}
908
994
Statement :: ShowVariable { variable } => write ! ( f, "SHOW {}" , variable) ,
909
995
Statement :: ShowColumns {
@@ -1124,56 +1210,54 @@ impl fmt::Display for ObjectType {
1124
1210
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1125
1211
pub enum HiveDistributionStyle {
1126
1212
PARTITIONED {
1127
- columns : Vec < ColumnDef >
1213
+ columns : Vec < ColumnDef > ,
1128
1214
} ,
1129
1215
CLUSTERED {
1130
1216
columns : Vec < Ident > ,
1131
1217
sorted_by : Vec < ColumnDef > ,
1132
- num_buckets : i32
1218
+ num_buckets : i32 ,
1133
1219
} ,
1134
1220
SKEWED {
1135
1221
columns : Vec < ColumnDef > ,
1136
1222
on : Vec < ColumnDef > ,
1137
- stored_as_directories : bool
1223
+ stored_as_directories : bool ,
1138
1224
} ,
1139
- NONE
1225
+ NONE ,
1140
1226
}
1141
1227
1142
1228
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1143
1229
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1144
1230
pub enum HiveRowFormat {
1145
- SERDE {
1146
- class : String
1147
- } ,
1148
- DELIMITED
1231
+ SERDE { class : String } ,
1232
+ DELIMITED ,
1149
1233
}
1150
1234
1151
1235
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1152
1236
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1153
1237
pub enum HiveIOFormat {
1154
1238
IOF {
1155
- input_format : Expr ,
1156
- output_format : Expr ,
1239
+ input_format : Expr ,
1240
+ output_format : Expr ,
1157
1241
} ,
1158
1242
FileFormat {
1159
- format : FileFormat
1160
- }
1243
+ format : FileFormat ,
1244
+ } ,
1161
1245
}
1162
1246
1163
1247
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1164
1248
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1165
1249
pub struct HiveFormat {
1166
1250
pub row_format : Option < HiveRowFormat > ,
1167
1251
pub storage : Option < HiveIOFormat > ,
1168
- pub location : Option < String >
1252
+ pub location : Option < String > ,
1169
1253
}
1170
1254
1171
1255
impl Default for HiveFormat {
1172
1256
fn default ( ) -> Self {
1173
1257
HiveFormat {
1174
1258
row_format : None ,
1175
1259
location : None ,
1176
- storage : None
1260
+ storage : None ,
1177
1261
}
1178
1262
}
1179
1263
}
0 commit comments