Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/query/ast/src/ast/statements/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ pub enum Statement {
TruncateTable(TruncateTableStmt),
OptimizeTable(OptimizeTableStmt),
VacuumTable(VacuumTableStmt),
VacuumTables(VacuumTablesStmt),
VacuumAll(VacuumAllStmt),
VacuumDropTable(VacuumDropTableStmt),
VacuumTemporaryFiles(VacuumTemporaryFiles),
VacuumVirtualColumn(VacuumVirtualColumnStmt),
Expand Down Expand Up @@ -565,6 +567,8 @@ impl Statement {
| Statement::ShowDropTables(..)
| Statement::OptimizeTable(..)
| Statement::VacuumTable(..)
| Statement::VacuumTables(..)
| Statement::VacuumAll(..)
| Statement::VacuumDropTable(..)
| Statement::VacuumTemporaryFiles(..)
| Statement::VacuumVirtualColumn(..)
Expand Down Expand Up @@ -956,6 +960,8 @@ impl Display for Statement {
Statement::TruncateTable(stmt) => write!(f, "{stmt}")?,
Statement::OptimizeTable(stmt) => write!(f, "{stmt}")?,
Statement::VacuumTable(stmt) => write!(f, "{stmt}")?,
Statement::VacuumTables(stmt) => write!(f, "{stmt}")?,
Statement::VacuumAll(stmt) => write!(f, "{stmt}")?,
Statement::VacuumDropTable(stmt) => write!(f, "{stmt}")?,
Statement::VacuumTemporaryFiles(stmt) => write!(f, "{stmt}")?,
Statement::VacuumVirtualColumn(stmt) => write!(f, "{stmt}")?,
Expand Down
110 changes: 30 additions & 80 deletions src/query/ast/src/ast/statements/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,45 +736,52 @@ impl Display for TruncateTableStmt {

#[derive(Debug, Clone, PartialEq, Drive, DriveMut, Walk, WalkMut)]
pub struct VacuumTableStmt {
pub catalog: Option<Identifier>,
pub database: Option<Identifier>,
pub table: Identifier,
pub option: VacuumTableOption,
}

impl Display for VacuumTableStmt {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "VACUUM TABLE ")?;
write_dot_separated_list(
f,
self.catalog
.iter()
.chain(&self.database)
.chain(Some(&self.table)),
)?;
write!(f, " {}", &self.option)?;
write_dot_separated_list(f, self.database.iter().chain(Some(&self.table)))
}
}

#[derive(Debug, Clone, PartialEq, Drive, DriveMut, Walk, WalkMut)]
pub struct VacuumTablesStmt {
pub database: Option<Identifier>,
}

impl Display for VacuumTablesStmt {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "VACUUM TABLES")?;
if let Some(database) = &self.database {
write!(f, " FROM {database}")?;
}
Ok(())
}
}

#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub struct VacuumAllStmt;

impl Display for VacuumAllStmt {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "VACUUM ALL")
}
}

#[derive(Debug, Clone, PartialEq, Drive, DriveMut, Walk, WalkMut)]
pub struct VacuumDropTableStmt {
pub catalog: Option<Identifier>,
pub database: Option<Identifier>,
pub option: VacuumDropTableOption,
}

impl Display for VacuumDropTableStmt {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "VACUUM DROP TABLE ")?;
if self.catalog.is_some() || self.database.is_some() {
write!(f, "FROM ")?;
write_dot_separated_list(f, self.catalog.iter().chain(&self.database))?;
write!(f, " ")?;
write!(f, "VACUUM DROP TABLE")?;
if let Some(database) = &self.database {
write!(f, " FROM {database}")?;
}
write!(f, "{}", &self.option)?;

Ok(())
}
}
Expand Down Expand Up @@ -962,75 +969,18 @@ pub enum CompactTarget {
Segment,
}

#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub struct VacuumTableOption {
// Some(true) means dry run with summary option
pub dry_run: Option<bool>,
}

impl Display for VacuumTableOption {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let Some(summary) = self.dry_run {
write!(f, "DRY RUN")?;
if summary {
write!(f, " SUMMARY")?;
}
}
Ok(())
}
}

#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub struct VacuumDropTableOption {
// Some(true) means dry run with summary option
pub dry_run: Option<bool>,
pub limit: Option<usize>,
}

impl Display for VacuumDropTableOption {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let Some(summary) = self.dry_run {
write!(f, "DRY RUN")?;
if summary {
write!(f, " SUMMARY")?;
}
}
if let Some(limit) = self.limit {
write!(f, " LIMIT {}", limit)?;
}
Ok(())
}
}

#[derive(Debug, Clone, PartialEq, Drive, DriveMut, Walk, WalkMut)]
pub enum OptimizeTableAction {
All,
Purge { before: Option<TimeTravelPoint> },
Compact { target: CompactTarget },
}

impl Display for OptimizeTableAction {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
OptimizeTableAction::All => write!(f, "ALL"),
OptimizeTableAction::Purge { before } => {
write!(f, "PURGE")?;
if let Some(point) = before {
write!(f, " BEFORE {}", point)?;
}
Ok(())
}
OptimizeTableAction::Compact { target } => {
match target {
CompactTarget::Block => {
write!(f, "COMPACT")?;
}
CompactTarget::Segment => {
write!(f, "COMPACT SEGMENT")?;
}
}
Ok(())
}
OptimizeTableAction::Compact { target } => match target {
CompactTarget::Block => write!(f, "COMPACT"),
CompactTarget::Segment => write!(f, "COMPACT SEGMENT"),
},
}
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/query/ast/src/parser/error_suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ const PATTERNS: &[&str] = &[
"SHOW STATISTICS",
"SHOW WORKLOAD GROUPS",
"SHOW ONLINE NODES",
"VACUUM TABLE",
"VACUUM TABLES",
"VACUUM ALL",
"VACUUM DROP TABLE",
"VACUUM DROPPED OBJECTS",
"VACUUM TEMPORARY FILES",
"VACUUM TEMPORARY TABLES",
"VACUUM VIRTUAL COLUMN",
];

Expand Down Expand Up @@ -264,10 +267,9 @@ mod tests {
Some("Did you mean `SHOW TABLE_FUNCTIONS` or `SHOW TABLES`?".to_string())
);

// Multiple suggestions when scores are very close
assert_eq!(
suggest_correction("vacuum temp"),
Some("Did you mean `VACUUM TEMPORARY FILES` or `VACUUM TEMPORARY TABLES`?".to_string())
Some("Did you mean `VACUUM TEMPORARY FILES`?".to_string())
);
}

Expand All @@ -276,10 +278,7 @@ mod tests {
// Single word prefixes should get context help
assert_eq!(
suggest_correction("vacuum"),
Some(
"Try: `VACUUM DROP TABLE`, `VACUUM TEMPORARY FILES`, or `VACUUM TEMPORARY TABLES`"
.to_string()
)
Some("Try: `VACUUM TABLE`, `VACUUM TABLES`, or `VACUUM ALL`".to_string())
);

let result = suggest_correction("show").unwrap();
Expand Down Expand Up @@ -366,7 +365,7 @@ mod tests {
);
assert_eq!(
suggest_correction("vacuum temp"),
Some("Did you mean `VACUUM TEMPORARY FILES` or `VACUUM TEMPORARY TABLES`?".to_string())
Some("Did you mean `VACUUM TEMPORARY FILES`?".to_string())
);

// Should not recognize invalid starts
Expand Down
Loading
Loading