Skip to content

Commit 88d7b69

Browse files
committed
cargo fmt
1 parent 9733e2e commit 88d7b69

File tree

8 files changed

+202
-82
lines changed

8 files changed

+202
-82
lines changed

examples/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $ cargo run --feature json_example --example cli FILENAME.sql [--dialectname]
3939
"--ansi" => Box::new(AnsiDialect {}),
4040
"--postgres" => Box::new(PostgreSqlDialect {}),
4141
"--ms" => Box::new(MsSqlDialect {}),
42-
"--hive" => Box::new(HiveDialect{}),
42+
"--hive" => Box::new(HiveDialect {}),
4343
"--generic" | "" => Box::new(GenericDialect {}),
4444
s => panic!("Unexpected parameter: {}", s),
4545
};

src/ast/mod.rs

Lines changed: 128 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -432,20 +432,20 @@ pub enum Statement {
432432
for_columns: bool,
433433
cache_metadata: bool,
434434
noscan: bool,
435-
compute_statistics: bool
435+
compute_statistics: bool,
436436
},
437437
/// Truncate (Hive)
438438
Truncate {
439439
table_name: ObjectName,
440-
partitions: Option<Vec<Expr>>
440+
partitions: Option<Vec<Expr>>,
441441
},
442442
/// Msck (Hive)
443443
Msck {
444444
table_name: ObjectName,
445445
repair: bool,
446446
add_partitions: bool,
447447
drop_partitions: bool,
448-
sync_partitions: bool
448+
sync_partitions: bool,
449449
},
450450
/// SELECT
451451
Query(Box<Query>),
@@ -460,7 +460,7 @@ pub enum Statement {
460460
/// A SQL query that specifies what to insert
461461
source: Box<Query>,
462462
/// partitioned insert (Hive)
463-
partitioned: Option<Vec<Expr>>
463+
partitioned: Option<Vec<Expr>>,
464464
},
465465
Copy {
466466
/// TABLE
@@ -585,8 +585,9 @@ pub enum Statement {
585585
/// CREATE DATABASE
586586
CreateDatabase {
587587
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>,
590591
},
591592
/// ASSERT <condition> [AS <message>]
592593
Assert {
@@ -602,15 +603,43 @@ impl fmt::Display for Statement {
602603
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
603604
match self {
604605
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+
}
611637
)
612638
}
613-
Statement::Truncate { table_name, partitions } => {
639+
Statement::Truncate {
640+
table_name,
641+
partitions,
642+
} => {
614643
write!(f, "TRUNCATE TABLE {}", table_name)?;
615644
if let Some(ref parts) = partitions {
616645
if !parts.is_empty() {
@@ -619,7 +648,14 @@ impl fmt::Display for Statement {
619648
}
620649
Ok(())
621650
}
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+
} => {
623659
write!(f, "ANALYZE TABLE {}", table_name)?;
624660
if let Some(ref parts) = partitions {
625661
if !parts.is_empty() {
@@ -645,7 +681,16 @@ impl fmt::Display for Statement {
645681
columns,
646682
source,
647683
} => {
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+
)?;
649694
if !columns.is_empty() {
650695
write!(f, "({}) ", display_comma_separated(columns))?;
651696
}
@@ -706,7 +751,12 @@ impl fmt::Display for Statement {
706751
}
707752
Ok(())
708753
}
709-
Statement::CreateDatabase { db_name, ine, location, managed_location } => {
754+
Statement::CreateDatabase {
755+
db_name,
756+
ine,
757+
location,
758+
managed_location,
759+
} => {
710760
write!(f, "CREATE")?;
711761
if *ine {
712762
write!(f, " IF NOT EXISTS")?;
@@ -796,8 +846,14 @@ impl fmt::Display for Statement {
796846
}
797847

798848
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+
} => {
801857
write!(f, " CLUSTERED BY ({})", display_comma_separated(&columns))?;
802858
if !sorted_by.is_empty() {
803859
write!(f, " SORTED BY ({})", display_comma_separated(&sorted_by))?;
@@ -806,26 +862,50 @@ impl fmt::Display for Statement {
806862
write!(f, " INTO {} BUCKETS", num_buckets)?;
807863
}
808864
}
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+
)?;
811876
if *stored_as_directories {
812877
write!(f, " STORED AS DIRECTORIES")?;
813878
}
814-
},
815-
_ => ()
879+
}
880+
_ => (),
816881
}
817882

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+
{
820889
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+
}
822893
Some(HiveRowFormat::DELIMITED) => write!(f, " ROW FORMAT DELIMITED")?,
823-
None => ()
894+
None => (),
824895
}
825896
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 => (),
829909
}
830910
if let Some(loc) = location {
831911
write!(f, " LOCATION '{}'", loc)?;
@@ -913,7 +993,13 @@ impl fmt::Display for Statement {
913993
if *local {
914994
f.write_str("LOCAL ")?;
915995
}
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+
)
9171003
}
9181004
Statement::ShowVariable { variable } => write!(f, "SHOW {}", variable),
9191005
Statement::ShowColumns {
@@ -1134,56 +1220,54 @@ impl fmt::Display for ObjectType {
11341220
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11351221
pub enum HiveDistributionStyle {
11361222
PARTITIONED {
1137-
columns: Vec<ColumnDef>
1223+
columns: Vec<ColumnDef>,
11381224
},
11391225
CLUSTERED {
11401226
columns: Vec<Ident>,
11411227
sorted_by: Vec<ColumnDef>,
1142-
num_buckets: i32
1228+
num_buckets: i32,
11431229
},
11441230
SKEWED {
11451231
columns: Vec<ColumnDef>,
11461232
on: Vec<ColumnDef>,
1147-
stored_as_directories: bool
1233+
stored_as_directories: bool,
11481234
},
1149-
NONE
1235+
NONE,
11501236
}
11511237

11521238
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11531239
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11541240
pub enum HiveRowFormat {
1155-
SERDE {
1156-
class: String
1157-
},
1158-
DELIMITED
1241+
SERDE { class: String },
1242+
DELIMITED,
11591243
}
11601244

11611245
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11621246
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11631247
pub enum HiveIOFormat {
11641248
IOF {
1165-
input_format: Expr,
1166-
output_format: Expr,
1249+
input_format: Expr,
1250+
output_format: Expr,
11671251
},
11681252
FileFormat {
1169-
format: FileFormat
1170-
}
1253+
format: FileFormat,
1254+
},
11711255
}
11721256

11731257
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11741258
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11751259
pub struct HiveFormat {
11761260
pub row_format: Option<HiveRowFormat>,
11771261
pub storage: Option<HiveIOFormat>,
1178-
pub location: Option<String>
1262+
pub location: Option<String>,
11791263
}
11801264

11811265
impl Default for HiveFormat {
11821266
fn default() -> Self {
11831267
HiveFormat {
11841268
row_format: None,
11851269
location: None,
1186-
storage: None
1270+
storage: None,
11871271
}
11881272
}
11891273
}

src/dialect/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212

1313
mod ansi;
1414
mod generic;
15+
mod hive;
1516
pub mod keywords;
1617
mod mssql;
1718
mod mysql;
1819
mod postgresql;
19-
mod hive;
2020

2121
use std::fmt::Debug;
2222

2323
pub use self::ansi::AnsiDialect;
2424
pub use self::generic::GenericDialect;
25+
pub use self::hive::HiveDialect;
2526
pub use self::mssql::MsSqlDialect;
2627
pub use self::mysql::MySqlDialect;
2728
pub use self::postgresql::PostgreSqlDialect;
28-
pub use self::hive::HiveDialect;
2929

3030
pub trait Dialect: Debug {
3131
/// Determine if a character starts a quoted identifier. The default

0 commit comments

Comments
 (0)