Skip to content

Commit 4862b28

Browse files
Moved the Msck struct outside of Statement enum
1 parent f006125 commit 4862b28

File tree

4 files changed

+55
-32
lines changed

4 files changed

+55
-32
lines changed

src/ast/ddl.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3487,3 +3487,43 @@ impl Spanned for Truncate {
34873487
)
34883488
}
34893489
}
3490+
3491+
/// An `MSCK` statement.
3492+
///
3493+
/// ```sql
3494+
/// MSCK [REPAIR] TABLE table_name [ADD|DROP|SYNC PARTITIONS]
3495+
/// ```
3496+
/// MSCK (Hive) - MetaStore Check command
3497+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3498+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3499+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3500+
pub struct Msck {
3501+
/// Table name to check
3502+
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3503+
pub table_name: ObjectName,
3504+
/// Whether to repair the table
3505+
pub repair: bool,
3506+
/// Partition action (ADD, DROP, or SYNC)
3507+
pub partition_action: Option<super::AddDropSync>,
3508+
}
3509+
3510+
impl fmt::Display for Msck {
3511+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3512+
write!(
3513+
f,
3514+
"MSCK {repair}TABLE {table}",
3515+
repair = if self.repair { "REPAIR " } else { "" },
3516+
table = self.table_name
3517+
)?;
3518+
if let Some(pa) = &self.partition_action {
3519+
write!(f, " {pa}")?;
3520+
}
3521+
Ok(())
3522+
}
3523+
}
3524+
3525+
impl Spanned for Msck {
3526+
fn span(&self) -> Span {
3527+
self.table_name.span()
3528+
}
3529+
}

src/ast/mod.rs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ pub use self::ddl::{
6767
CreateFunction, CreateIndex, CreateTable, CreateTrigger, Deduplicate, DeferrableInitial,
6868
DropBehavior, DropTrigger, GeneratedAs, GeneratedExpressionMode, IdentityParameters,
6969
IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder,
70-
IndexColumn, IndexOption, IndexType, KeyOrIndexDisplay, NullsDistinctOption, Owner, Partition,
71-
ProcedureParam, ReferentialAction, RenameTableNameKind, ReplicaIdentity, TableConstraint,
72-
TagsColumnOption, Truncate, UserDefinedTypeCompositeAttributeDef,
70+
IndexColumn, IndexOption, IndexType, KeyOrIndexDisplay, Msck, NullsDistinctOption, Owner,
71+
Partition, ProcedureParam, ReferentialAction, RenameTableNameKind, ReplicaIdentity,
72+
TableConstraint, TagsColumnOption, Truncate, UserDefinedTypeCompositeAttributeDef,
7373
UserDefinedTypeRepresentation, ViewColumnDef,
7474
};
7575
pub use self::dml::{Delete, Insert};
@@ -3138,12 +3138,7 @@ pub enum Statement {
31383138
/// MSCK
31393139
/// ```
31403140
/// Msck (Hive)
3141-
Msck {
3142-
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3143-
table_name: ObjectName,
3144-
repair: bool,
3145-
partition_action: Option<AddDropSync>,
3146-
},
3141+
Msck(Msck),
31473142
/// ```sql
31483143
/// SELECT
31493144
/// ```
@@ -4363,6 +4358,12 @@ impl From<ddl::Truncate> for Statement {
43634358
}
43644359
}
43654360

4361+
impl From<ddl::Msck> for Statement {
4362+
fn from(msck: ddl::Msck) -> Self {
4363+
Statement::Msck(msck)
4364+
}
4365+
}
4366+
43664367
/// ```sql
43674368
/// {COPY | REVOKE} CURRENT GRANTS
43684369
/// ```
@@ -4563,22 +4564,7 @@ impl fmt::Display for Statement {
45634564
}
45644565
write!(f, " {source}")
45654566
}
4566-
Statement::Msck {
4567-
table_name,
4568-
repair,
4569-
partition_action,
4570-
} => {
4571-
write!(
4572-
f,
4573-
"MSCK {repair}TABLE {table}",
4574-
repair = if *repair { "REPAIR " } else { "" },
4575-
table = table_name
4576-
)?;
4577-
if let Some(pa) = partition_action {
4578-
write!(f, " {pa}")?;
4579-
}
4580-
Ok(())
4581-
}
4567+
Statement::Msck(msck) => msck.fmt(f),
45824568
Statement::Truncate(truncate) => truncate.fmt(f),
45834569
Statement::Case(stmt) => {
45844570
write!(f, "{stmt}")

src/ast/spans.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,7 @@ impl Spanned for Statement {
300300
match self {
301301
Statement::Analyze(analyze) => analyze.span(),
302302
Statement::Truncate(truncate) => truncate.span(),
303-
Statement::Msck {
304-
table_name,
305-
repair: _,
306-
partition_action: _,
307-
} => table_name.span(),
303+
Statement::Msck(msck) => msck.span(),
308304
Statement::Query(query) => query.span(),
309305
Statement::Insert(insert) => insert.span(),
310306
Statement::Install { extension_name } => extension_name.span,

src/parser/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,11 +982,12 @@ impl<'a> Parser<'a> {
982982
Ok(pa)
983983
})?
984984
.unwrap_or_default();
985-
Ok(Statement::Msck {
985+
Ok(Msck {
986986
repair,
987987
table_name,
988988
partition_action,
989-
})
989+
}
990+
.into())
990991
}
991992

992993
pub fn parse_truncate(&mut self) -> Result<Statement, ParserError> {

0 commit comments

Comments
 (0)