Skip to content

Commit 77092e6

Browse files
committed
Address some PR changes
1 parent 18050aa commit 77092e6

File tree

3 files changed

+37
-46
lines changed

3 files changed

+37
-46
lines changed

src/ast/data_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub enum DataType {
6161
Regclass,
6262
/// Text
6363
Text,
64-
/// String (Hive)
64+
/// String
6565
String,
6666
/// Bytea
6767
Bytea,

src/ast/mod.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,24 @@ impl fmt::Display for WindowFrameBound {
420420
}
421421
}
422422

423+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
424+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
425+
pub enum PartitionAction {
426+
ADD,
427+
DROP,
428+
SYNC,
429+
}
430+
431+
impl fmt::Display for PartitionAction {
432+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
433+
match self {
434+
PartitionAction::SYNC => f.write_str("SYNC PARTITIONS"),
435+
PartitionAction::DROP => f.write_str("DROP PARTITIONS"),
436+
PartitionAction::ADD => f.write_str("ADD PARTITIONS"),
437+
}
438+
}
439+
}
440+
423441
/// A top-level statement (SELECT, INSERT, CREATE, etc.)
424442
#[allow(clippy::large_enum_variant)]
425443
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -443,9 +461,7 @@ pub enum Statement {
443461
Msck {
444462
table_name: ObjectName,
445463
repair: bool,
446-
add_partitions: bool,
447-
drop_partitions: bool,
448-
sync_partitions: bool,
464+
partition_action: Option<PartitionAction>,
449465
},
450466
/// SELECT
451467
Query(Box<Query>),
@@ -591,7 +607,7 @@ pub enum Statement {
591607
/// CREATE DATABASE
592608
CreateDatabase {
593609
db_name: ObjectName,
594-
ine: bool,
610+
if_not_exists: bool,
595611
location: Option<String>,
596612
managed_location: Option<String>,
597613
},
@@ -612,35 +628,18 @@ impl fmt::Display for Statement {
612628
Statement::Msck {
613629
table_name,
614630
repair,
615-
add_partitions,
616-
drop_partitions,
617-
sync_partitions,
631+
partition_action,
618632
} => {
619633
write!(
620634
f,
621635
"MSCK {repair}TABLE {table}",
622636
repair = if *repair { "REPAIR " } else { "" },
623637
table = table_name
624638
)?;
625-
write!(
626-
f,
627-
"{add}{drop}{sync}",
628-
add = if *add_partitions {
629-
" ADD PARTITIONS"
630-
} else {
631-
""
632-
},
633-
drop = if *drop_partitions {
634-
" DROP PARTITIONS"
635-
} else {
636-
""
637-
},
638-
sync = if *sync_partitions {
639-
" SYNC PARTITIONS"
640-
} else {
641-
""
642-
}
643-
)
639+
if let Some(pa) = partition_action {
640+
write!(f, " {}", pa)?;
641+
}
642+
Ok(())
644643
}
645644
Statement::Truncate {
646645
table_name,
@@ -757,12 +756,12 @@ impl fmt::Display for Statement {
757756
}
758757
Statement::CreateDatabase {
759758
db_name,
760-
ine,
759+
if_not_exists,
761760
location,
762761
managed_location,
763762
} => {
764763
write!(f, "CREATE")?;
765-
if *ine {
764+
if *if_not_exists {
766765
write!(f, " IF NOT EXISTS")?;
767766
}
768767
write!(f, " {}", db_name)?;

src/parser.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,18 @@ impl Parser {
166166
let repair = self.parse_keyword(Keyword::REPAIR);
167167
self.expect_keyword(Keyword::TABLE)?;
168168
let table_name = self.parse_object_name()?;
169-
let (mut add, mut drop, mut sync) = (false, false, false);
170-
match self.parse_one_of_keywords(&[Keyword::ADD, Keyword::DROP, Keyword::SYNC]) {
171-
Some(Keyword::ADD) => {
172-
add = true;
173-
}
174-
Some(Keyword::DROP) => {
175-
drop = true;
176-
}
177-
Some(Keyword::SYNC) => {
178-
sync = true;
179-
}
180-
_ => (),
181-
}
169+
let partition_action =
170+
match self.parse_one_of_keywords(&[Keyword::ADD, Keyword::DROP, Keyword::SYNC]) {
171+
Some(Keyword::ADD) => Some(PartitionAction::ADD),
172+
Some(Keyword::DROP) => Some(PartitionAction::DROP),
173+
Some(Keyword::SYNC) => Some(PartitionAction::SYNC),
174+
_ => None,
175+
};
182176
self.expect_keyword(Keyword::PARTITIONS)?;
183177
Ok(Statement::Msck {
184178
repair,
185179
table_name,
186-
add_partitions: add,
187-
drop_partitions: drop,
188-
sync_partitions: sync,
180+
partition_action,
189181
})
190182
}
191183

@@ -1158,7 +1150,7 @@ impl Parser {
11581150
}
11591151
Ok(Statement::CreateDatabase {
11601152
db_name,
1161-
ine,
1153+
if_not_exists: ine,
11621154
location,
11631155
managed_location,
11641156
})

0 commit comments

Comments
 (0)