Skip to content

Commit ac6ae2f

Browse files
committed
cargo fmt
1 parent 5e5a9fc commit ac6ae2f

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
@@ -583,8 +583,9 @@ pub enum Statement {
583583
/// CREATE DATABASE
584584
CreateDatabase {
585585
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>,
588589
},
589590
/// ASSERT <condition> [AS <message>]
590591
Assert {
@@ -600,15 +601,43 @@ impl fmt::Display for Statement {
600601
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
601602
match self {
602603
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+
}
609635
)
610636
}
611-
Statement::Truncate { table_name, partitions } => {
637+
Statement::Truncate {
638+
table_name,
639+
partitions,
640+
} => {
612641
write!(f, "TRUNCATE TABLE {}", table_name)?;
613642
if let Some(ref parts) = partitions {
614643
if !parts.is_empty() {
@@ -617,7 +646,14 @@ impl fmt::Display for Statement {
617646
}
618647
Ok(())
619648
}
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+
} => {
621657
write!(f, "ANALYZE TABLE {}", table_name)?;
622658
if let Some(ref parts) = partitions {
623659
if !parts.is_empty() {
@@ -643,7 +679,16 @@ impl fmt::Display for Statement {
643679
columns,
644680
source,
645681
} => {
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+
)?;
647692
if !columns.is_empty() {
648693
write!(f, "({}) ", display_comma_separated(columns))?;
649694
}
@@ -704,7 +749,12 @@ impl fmt::Display for Statement {
704749
}
705750
Ok(())
706751
}
707-
Statement::CreateDatabase { db_name, ine, location, managed_location } => {
752+
Statement::CreateDatabase {
753+
db_name,
754+
ine,
755+
location,
756+
managed_location,
757+
} => {
708758
write!(f, "CREATE")?;
709759
if *ine {
710760
write!(f, " IF NOT EXISTS")?;
@@ -786,8 +836,14 @@ impl fmt::Display for Statement {
786836
}
787837

788838
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+
} => {
791847
write!(f, " CLUSTERED BY ({})", display_comma_separated(&columns))?;
792848
if !sorted_by.is_empty() {
793849
write!(f, " SORTED BY ({})", display_comma_separated(&sorted_by))?;
@@ -796,26 +852,50 @@ impl fmt::Display for Statement {
796852
write!(f, " INTO {} BUCKETS", num_buckets)?;
797853
}
798854
}
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+
)?;
801866
if *stored_as_directories {
802867
write!(f, " STORED AS DIRECTORIES")?;
803868
}
804-
},
805-
_ => ()
869+
}
870+
_ => (),
806871
}
807872

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+
{
810879
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+
}
812883
Some(HiveRowFormat::DELIMITED) => write!(f, " ROW FORMAT DELIMITED")?,
813-
None => ()
884+
None => (),
814885
}
815886
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 => (),
819899
}
820900
if let Some(loc) = location {
821901
write!(f, " LOCATION '{}'", loc)?;
@@ -903,7 +983,13 @@ impl fmt::Display for Statement {
903983
if *local {
904984
f.write_str("LOCAL ")?;
905985
}
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+
)
907993
}
908994
Statement::ShowVariable { variable } => write!(f, "SHOW {}", variable),
909995
Statement::ShowColumns {
@@ -1124,56 +1210,54 @@ impl fmt::Display for ObjectType {
11241210
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11251211
pub enum HiveDistributionStyle {
11261212
PARTITIONED {
1127-
columns: Vec<ColumnDef>
1213+
columns: Vec<ColumnDef>,
11281214
},
11291215
CLUSTERED {
11301216
columns: Vec<Ident>,
11311217
sorted_by: Vec<ColumnDef>,
1132-
num_buckets: i32
1218+
num_buckets: i32,
11331219
},
11341220
SKEWED {
11351221
columns: Vec<ColumnDef>,
11361222
on: Vec<ColumnDef>,
1137-
stored_as_directories: bool
1223+
stored_as_directories: bool,
11381224
},
1139-
NONE
1225+
NONE,
11401226
}
11411227

11421228
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11431229
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11441230
pub enum HiveRowFormat {
1145-
SERDE {
1146-
class: String
1147-
},
1148-
DELIMITED
1231+
SERDE { class: String },
1232+
DELIMITED,
11491233
}
11501234

11511235
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11521236
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11531237
pub enum HiveIOFormat {
11541238
IOF {
1155-
input_format: Expr,
1156-
output_format: Expr,
1239+
input_format: Expr,
1240+
output_format: Expr,
11571241
},
11581242
FileFormat {
1159-
format: FileFormat
1160-
}
1243+
format: FileFormat,
1244+
},
11611245
}
11621246

11631247
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11641248
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11651249
pub struct HiveFormat {
11661250
pub row_format: Option<HiveRowFormat>,
11671251
pub storage: Option<HiveIOFormat>,
1168-
pub location: Option<String>
1252+
pub location: Option<String>,
11691253
}
11701254

11711255
impl Default for HiveFormat {
11721256
fn default() -> Self {
11731257
HiveFormat {
11741258
row_format: None,
11751259
location: None,
1176-
storage: None
1260+
storage: None,
11771261
}
11781262
}
11791263
}

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)