Skip to content

Commit 83a6f5a

Browse files
committed
Address some PR changes
1 parent 2e85bbf commit 83a6f5a

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>),
@@ -589,7 +605,7 @@ pub enum Statement {
589605
/// CREATE DATABASE
590606
CreateDatabase {
591607
db_name: ObjectName,
592-
ine: bool,
608+
if_not_exists: bool,
593609
location: Option<String>,
594610
managed_location: Option<String>,
595611
},
@@ -610,35 +626,18 @@ impl fmt::Display for Statement {
610626
Statement::Msck {
611627
table_name,
612628
repair,
613-
add_partitions,
614-
drop_partitions,
615-
sync_partitions,
629+
partition_action,
616630
} => {
617631
write!(
618632
f,
619633
"MSCK {repair}TABLE {table}",
620634
repair = if *repair { "REPAIR " } else { "" },
621635
table = table_name
622636
)?;
623-
write!(
624-
f,
625-
"{add}{drop}{sync}",
626-
add = if *add_partitions {
627-
" ADD PARTITIONS"
628-
} else {
629-
""
630-
},
631-
drop = if *drop_partitions {
632-
" DROP PARTITIONS"
633-
} else {
634-
""
635-
},
636-
sync = if *sync_partitions {
637-
" SYNC PARTITIONS"
638-
} else {
639-
""
640-
}
641-
)
637+
if let Some(pa) = partition_action {
638+
write!(f, " {}", pa)?;
639+
}
640+
Ok(())
642641
}
643642
Statement::Truncate {
644643
table_name,
@@ -755,12 +754,12 @@ impl fmt::Display for Statement {
755754
}
756755
Statement::CreateDatabase {
757756
db_name,
758-
ine,
757+
if_not_exists,
759758
location,
760759
managed_location,
761760
} => {
762761
write!(f, "CREATE")?;
763-
if *ine {
762+
if *if_not_exists {
764763
write!(f, " IF NOT EXISTS")?;
765764
}
766765
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

@@ -1153,7 +1145,7 @@ impl Parser {
11531145
}
11541146
Ok(Statement::CreateDatabase {
11551147
db_name,
1156-
ine,
1148+
if_not_exists: ine,
11571149
location,
11581150
managed_location,
11591151
})

0 commit comments

Comments
 (0)