Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Commit

Permalink
use new query engine to delete all records from table (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-dukhno committed Jan 30, 2021
1 parent 06231a6 commit 34a89ae
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 132 deletions.
5 changes: 5 additions & 0 deletions data/catalog/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,11 @@ impl SqlTable for InMemoryTable {
.collect(),
))
}

fn delete_all(&self) -> usize {
let keys = self.data_table.select().map(|(key, _value)| key).collect();
self.data_table.delete(keys)
}
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions data/catalog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pub trait SqlTable {

fn select(&self) -> (Vec<ColumnDef>, Vec<Vec<Datum>>);
fn select_with_columns(&self, column_names: Vec<String>) -> Result<(Vec<ColumnDef>, Vec<Vec<Datum>>), String>;

fn delete_all(&self) -> usize;
}

pub trait Database {
Expand Down
1 change: 1 addition & 0 deletions data_manipulation/query_result/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use repr::Datum;
#[derive(Debug, PartialEq)]
pub enum QueryExecution {
Inserted(usize),
Deleted(usize),
Selected((Vec<ColumnDef>, Vec<Vec<Datum>>)),
}

Expand Down
6 changes: 6 additions & 0 deletions data_manipulation/typed_queries/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ pub struct InsertQuery {
pub values: Vec<Vec<StaticTypedTree>>,
}

#[derive(Debug, PartialEq)]
pub struct DeleteQuery {
pub full_table_name: FullTableName,
}

#[derive(Debug, PartialEq)]
pub enum TypedWrite {
Insert(InsertQuery),
Delete(DeleteQuery),
}

#[derive(Debug, PartialEq)]
Expand Down
274 changes: 145 additions & 129 deletions server/node/src/query_engine/mod.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions server/node/src/query_engine/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use std::{
};

// TODO: new engine does not handle deletes
// #[cfg(test)]
// mod delete;
#[cfg(test)]
mod delete;
// TODO: new engine does not handle extended query flow
// #[cfg(test)]
// mod extended_query_flow;
Expand Down
5 changes: 4 additions & 1 deletion write_query/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use catalog::{Database, SqlTable};
use data_manipulation_query_result::{QueryExecution, QueryExecutionError};
use data_manipulation_typed_queries::{InsertQuery, TypedWrite};
use data_manipulation_typed_queries::{DeleteQuery, InsertQuery, TypedWrite};
use data_manipulation_typed_tree::StaticTypedTree;
use std::sync::Arc;

Expand Down Expand Up @@ -49,6 +49,9 @@ impl<D: Database> WriteQueryExecutor<D> {
};
Ok(QueryExecution::Inserted(inserted))
}
TypedWrite::Delete(DeleteQuery { full_table_name }) => Ok(QueryExecution::Deleted(
self.database.work_with(&full_table_name, |table| table.delete_all()),
)),
}
}
}
Expand Down

0 comments on commit 34a89ae

Please sign in to comment.