@@ -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
@@ -585,8 +585,9 @@ pub enum Statement {
585
585
/// CREATE DATABASE
586
586
CreateDatabase {
587
587
db_name : ObjectName ,
588
- ine : bool , location : Option < String > ,
589
- managed_location : Option < String >
588
+ ine : bool ,
589
+ location : Option < String > ,
590
+ managed_location : Option < String > ,
590
591
} ,
591
592
/// ASSERT <condition> [AS <message>]
592
593
Assert {
@@ -602,15 +603,43 @@ impl fmt::Display for Statement {
602
603
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
603
604
match self {
604
605
Statement :: Query ( s) => write ! ( f, "{}" , s) ,
605
- Statement :: Msck { table_name, repair, add_partitions, drop_partitions, sync_partitions } => {
606
- write ! ( f, "MSCK {repair}TABLE {table}" , repair = if * repair { "REPAIR " } else { "" } , table = table_name) ?;
607
- write ! ( f, "{add}{drop}{sync}" ,
608
- add = if * add_partitions { " ADD PARTITIONS" } else { "" } ,
609
- drop = if * drop_partitions { " DROP PARTITIONS" } else { "" } ,
610
- sync = if * sync_partitions { " SYNC PARTITIONS" } else { "" }
606
+ Statement :: Msck {
607
+ table_name,
608
+ repair,
609
+ add_partitions,
610
+ drop_partitions,
611
+ sync_partitions,
612
+ } => {
613
+ write ! (
614
+ f,
615
+ "MSCK {repair}TABLE {table}" ,
616
+ repair = if * repair { "REPAIR " } else { "" } ,
617
+ table = table_name
618
+ ) ?;
619
+ write ! (
620
+ f,
621
+ "{add}{drop}{sync}" ,
622
+ add = if * add_partitions {
623
+ " ADD PARTITIONS"
624
+ } else {
625
+ ""
626
+ } ,
627
+ drop = if * drop_partitions {
628
+ " DROP PARTITIONS"
629
+ } else {
630
+ ""
631
+ } ,
632
+ sync = if * sync_partitions {
633
+ " SYNC PARTITIONS"
634
+ } else {
635
+ ""
636
+ }
611
637
)
612
638
}
613
- Statement :: Truncate { table_name, partitions } => {
639
+ Statement :: Truncate {
640
+ table_name,
641
+ partitions,
642
+ } => {
614
643
write ! ( f, "TRUNCATE TABLE {}" , table_name) ?;
615
644
if let Some ( ref parts) = partitions {
616
645
if !parts. is_empty ( ) {
@@ -619,7 +648,14 @@ impl fmt::Display for Statement {
619
648
}
620
649
Ok ( ( ) )
621
650
}
622
- Statement :: Analyze { table_name, partitions, for_columns : _, cache_metadata, noscan, compute_statistics } => {
651
+ Statement :: Analyze {
652
+ table_name,
653
+ partitions,
654
+ for_columns : _,
655
+ cache_metadata,
656
+ noscan,
657
+ compute_statistics,
658
+ } => {
623
659
write ! ( f, "ANALYZE TABLE {}" , table_name) ?;
624
660
if let Some ( ref parts) = partitions {
625
661
if !parts. is_empty ( ) {
@@ -645,7 +681,16 @@ impl fmt::Display for Statement {
645
681
columns,
646
682
source,
647
683
} => {
648
- write ! ( f, "INSERT {act} {table_name} " , table_name = table_name, act = if * overwrite { "OVERWRITE TABLE" } else { "INTO" } ) ?;
684
+ write ! (
685
+ f,
686
+ "INSERT {act} {table_name} " ,
687
+ table_name = table_name,
688
+ act = if * overwrite {
689
+ "OVERWRITE TABLE"
690
+ } else {
691
+ "INTO"
692
+ }
693
+ ) ?;
649
694
if !columns. is_empty ( ) {
650
695
write ! ( f, "({}) " , display_comma_separated( columns) ) ?;
651
696
}
@@ -706,7 +751,12 @@ impl fmt::Display for Statement {
706
751
}
707
752
Ok ( ( ) )
708
753
}
709
- Statement :: CreateDatabase { db_name, ine, location, managed_location } => {
754
+ Statement :: CreateDatabase {
755
+ db_name,
756
+ ine,
757
+ location,
758
+ managed_location,
759
+ } => {
710
760
write ! ( f, "CREATE" ) ?;
711
761
if * ine {
712
762
write ! ( f, " IF NOT EXISTS" ) ?;
@@ -796,8 +846,14 @@ impl fmt::Display for Statement {
796
846
}
797
847
798
848
match hive_distribution {
799
- HiveDistributionStyle :: PARTITIONED { columns } => write ! ( f, " PARTITIONED BY ({})" , display_comma_separated( & columns) ) ?,
800
- HiveDistributionStyle :: CLUSTERED { columns, sorted_by, num_buckets } => {
849
+ HiveDistributionStyle :: PARTITIONED { columns } => {
850
+ write ! ( f, " PARTITIONED BY ({})" , display_comma_separated( & columns) ) ?
851
+ }
852
+ HiveDistributionStyle :: CLUSTERED {
853
+ columns,
854
+ sorted_by,
855
+ num_buckets,
856
+ } => {
801
857
write ! ( f, " CLUSTERED BY ({})" , display_comma_separated( & columns) ) ?;
802
858
if !sorted_by. is_empty ( ) {
803
859
write ! ( f, " SORTED BY ({})" , display_comma_separated( & sorted_by) ) ?;
@@ -806,26 +862,50 @@ impl fmt::Display for Statement {
806
862
write ! ( f, " INTO {} BUCKETS" , num_buckets) ?;
807
863
}
808
864
}
809
- HiveDistributionStyle :: SKEWED { columns, on, stored_as_directories } => {
810
- write ! ( f, " SKEWED BY ({})) ON ({})" , display_comma_separated( & columns) , display_comma_separated( & on) ) ?;
865
+ HiveDistributionStyle :: SKEWED {
866
+ columns,
867
+ on,
868
+ stored_as_directories,
869
+ } => {
870
+ write ! (
871
+ f,
872
+ " SKEWED BY ({})) ON ({})" ,
873
+ display_comma_separated( & columns) ,
874
+ display_comma_separated( & on)
875
+ ) ?;
811
876
if * stored_as_directories {
812
877
write ! ( f, " STORED AS DIRECTORIES" ) ?;
813
878
}
814
- } ,
815
- _ => ( )
879
+ }
880
+ _ => ( ) ,
816
881
}
817
882
818
- if let Some ( HiveFormat { row_format, storage, location } ) = hive_formats {
819
-
883
+ if let Some ( HiveFormat {
884
+ row_format,
885
+ storage,
886
+ location,
887
+ } ) = hive_formats
888
+ {
820
889
match row_format {
821
- Some ( HiveRowFormat :: SERDE { class } ) => write ! ( f, " ROW FORMAT SERDE '{}'" , class) ?,
890
+ Some ( HiveRowFormat :: SERDE { class } ) => {
891
+ write ! ( f, " ROW FORMAT SERDE '{}'" , class) ?
892
+ }
822
893
Some ( HiveRowFormat :: DELIMITED ) => write ! ( f, " ROW FORMAT DELIMITED" ) ?,
823
- None => ( )
894
+ None => ( ) ,
824
895
}
825
896
match storage {
826
- Some ( HiveIOFormat :: IOF { input_format, output_format } ) => write ! ( f, " STORED AS INPUTFORMAT {} OUTPUTFORMAT {}" , input_format, output_format) ?,
827
- Some ( HiveIOFormat :: FileFormat { format } ) => write ! ( f, " STORED AS {}" , format) ?,
828
- None => ( )
897
+ Some ( HiveIOFormat :: IOF {
898
+ input_format,
899
+ output_format,
900
+ } ) => write ! (
901
+ f,
902
+ " STORED AS INPUTFORMAT {} OUTPUTFORMAT {}" ,
903
+ input_format, output_format
904
+ ) ?,
905
+ Some ( HiveIOFormat :: FileFormat { format } ) => {
906
+ write ! ( f, " STORED AS {}" , format) ?
907
+ }
908
+ None => ( ) ,
829
909
}
830
910
if let Some ( loc) = location {
831
911
write ! ( f, " LOCATION '{}'" , loc) ?;
@@ -913,7 +993,13 @@ impl fmt::Display for Statement {
913
993
if * local {
914
994
f. write_str ( "LOCAL " ) ?;
915
995
}
916
- write ! ( f, "{hivevar}{name} = {value}" , hivevar = if * hivevar { "HIVEVAR:" } else { "" } , name = variable, value = display_comma_separated( value) )
996
+ write ! (
997
+ f,
998
+ "{hivevar}{name} = {value}" ,
999
+ hivevar = if * hivevar { "HIVEVAR:" } else { "" } ,
1000
+ name = variable,
1001
+ value = display_comma_separated( value)
1002
+ )
917
1003
}
918
1004
Statement :: ShowVariable { variable } => write ! ( f, "SHOW {}" , variable) ,
919
1005
Statement :: ShowColumns {
@@ -1134,56 +1220,54 @@ impl fmt::Display for ObjectType {
1134
1220
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1135
1221
pub enum HiveDistributionStyle {
1136
1222
PARTITIONED {
1137
- columns : Vec < ColumnDef >
1223
+ columns : Vec < ColumnDef > ,
1138
1224
} ,
1139
1225
CLUSTERED {
1140
1226
columns : Vec < Ident > ,
1141
1227
sorted_by : Vec < ColumnDef > ,
1142
- num_buckets : i32
1228
+ num_buckets : i32 ,
1143
1229
} ,
1144
1230
SKEWED {
1145
1231
columns : Vec < ColumnDef > ,
1146
1232
on : Vec < ColumnDef > ,
1147
- stored_as_directories : bool
1233
+ stored_as_directories : bool ,
1148
1234
} ,
1149
- NONE
1235
+ NONE ,
1150
1236
}
1151
1237
1152
1238
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1153
1239
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1154
1240
pub enum HiveRowFormat {
1155
- SERDE {
1156
- class : String
1157
- } ,
1158
- DELIMITED
1241
+ SERDE { class : String } ,
1242
+ DELIMITED ,
1159
1243
}
1160
1244
1161
1245
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1162
1246
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1163
1247
pub enum HiveIOFormat {
1164
1248
IOF {
1165
- input_format : Expr ,
1166
- output_format : Expr ,
1249
+ input_format : Expr ,
1250
+ output_format : Expr ,
1167
1251
} ,
1168
1252
FileFormat {
1169
- format : FileFormat
1170
- }
1253
+ format : FileFormat ,
1254
+ } ,
1171
1255
}
1172
1256
1173
1257
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1174
1258
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1175
1259
pub struct HiveFormat {
1176
1260
pub row_format : Option < HiveRowFormat > ,
1177
1261
pub storage : Option < HiveIOFormat > ,
1178
- pub location : Option < String >
1262
+ pub location : Option < String > ,
1179
1263
}
1180
1264
1181
1265
impl Default for HiveFormat {
1182
1266
fn default ( ) -> Self {
1183
1267
HiveFormat {
1184
1268
row_format : None ,
1185
1269
location : None ,
1186
- storage : None
1270
+ storage : None ,
1187
1271
}
1188
1272
}
1189
1273
}
0 commit comments