Skip to content

Commit 3ed6502

Browse files
committed
style: remove field redundancy of create_table and insert
1 parent c5fe1eb commit 3ed6502

9 files changed

Lines changed: 21 additions & 36 deletions

File tree

src/binder/create_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::Binder;
66
use crate::binder::{lower_case_name, split_name};
77
use crate::catalog::ColumnCatalog;
88
use crate::planner::logical_create_table_plan::LogicalCreateTablePlan;
9-
use crate::planner::operator::create_table::CreateOperator;
9+
use crate::planner::operator::create_table::CreateTableOperator;
1010

1111
impl Binder {
1212
pub(crate) fn bind_create_table(
@@ -35,7 +35,7 @@ impl Binder {
3535
.collect();
3636

3737
let plan = LogicalCreateTablePlan {
38-
operator: CreateOperator {
38+
operator: CreateTableOperator {
3939
table_name: table_name.to_string(),
4040
columns
4141
},
@@ -60,7 +60,7 @@ mod tests {
6060
let plan1 = binder.bind(&stmt[0]).unwrap();
6161

6262
let plan2 = LogicalPlan::CreateTable(LogicalCreateTablePlan {
63-
operator: CreateOperator {
63+
operator: CreateTableOperator {
6464
table_name: "t1".to_string(),
6565
columns: vec![
6666
ColumnCatalog::new(

src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ mod test {
174174
})
175175
}
176176
#[test]
177-
fn test_sql() -> anyhow::Result<()> {
177+
fn test_crud_sql() -> anyhow::Result<()> {
178178
let database = Database::new_on_mem();
179179

180180
tokio_test::block_on(async move {
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
use crate::catalog::ColumnCatalog;
1+
use crate::planner::operator::create_table::CreateTableOperator;
22

33
#[derive(Debug)]
44
pub struct PhysicalCreateTable {
5-
/// Table name to insert to
6-
pub table_name: String,
7-
/// List of columns of the table
8-
pub columns: Vec<ColumnCatalog>,
5+
pub op: CreateTableOperator
96
}
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
use crate::expression::ScalarExpression;
2-
use crate::types::ColumnIdx;
1+
use crate::planner::operator::insert::InsertOperator;
32

43
#[derive(Debug)]
54
pub struct PhysicalInsert {
6-
/// Table name to insert to
7-
pub table_name: String,
8-
9-
pub col_idxs: Vec<ColumnIdx>,
10-
/// List of columns of the table
11-
pub cols: Vec<Vec<ScalarExpression>>
5+
pub op: InsertOperator
126
}

src/execution_v1/physical_plan/physical_plan_builder.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use anyhow::anyhow;
1111
use anyhow::Result;
1212
use crate::execution_v1::physical_plan::physical_insert::PhysicalInsert;
1313
use crate::planner::logical_insert_plan::LogicalInsertPlan;
14-
use crate::planner::operator::insert::InsertOperator;
1514
use crate::planner::operator::project::ProjectOperator;
1615

1716
pub struct PhysicalPlanBuilder {
@@ -44,13 +43,9 @@ impl PhysicalPlanBuilder {
4443
&mut self,
4544
plan: &LogicalInsertPlan,
4645
) -> PhysicalOperator {
47-
let InsertOperator { table, col_idxs, cols: rows } = plan.operator.clone();
48-
4946
PhysicalOperator::Insert(
5047
PhysicalInsert {
51-
table_name: table,
52-
col_idxs,
53-
cols: rows,
48+
op: plan.operator.clone()
5449
}
5550
)
5651
}
@@ -59,12 +54,9 @@ impl PhysicalPlanBuilder {
5954
&mut self,
6055
plan: &LogicalCreateTablePlan,
6156
) -> PhysicalOperator {
62-
let operator = &plan.operator;
63-
6457
PhysicalOperator::CreateTable(
6558
PhysicalCreateTable {
66-
table_name: operator.table_name.to_string(),
67-
columns: operator.columns.clone(),
59+
op: plan.operator.clone(),
6860
}
6961
)
7062
}

src/execution_v1/volcano_executor/create_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::execution_v1::ExecutorError;
33
use crate::storage::Storage;
44
use crate::catalog::ColumnCatalog;
55
use std::sync::Arc;
6-
use itertools::Itertools;
76
use arrow::datatypes::Schema;
7+
use itertools::Itertools;
88
use arrow::record_batch::RecordBatch;
99
use futures_async_stream::try_stream;
1010

@@ -13,14 +13,14 @@ pub struct CreateTable {}
1313
impl CreateTable {
1414
#[try_stream(boxed, ok = RecordBatch, error = ExecutorError)]
1515
pub async fn execute(plan: PhysicalCreateTable, storage: impl Storage) {
16-
let fields = plan.columns
16+
let fields = plan.op.columns
1717
.iter()
1818
.map(ColumnCatalog::to_field)
1919
.collect_vec();
2020
let schema = Arc::new(Schema::new(fields));
2121

2222
let _ = storage.create_table(
23-
plan.table_name.as_str(),
23+
plan.op.table_name.as_str(),
2424
vec![RecordBatch::new_empty(schema)]
2525
);
2626
}

src/execution_v1/volcano_executor/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::storage::StorageImpl;
1313
use arrow::record_batch::RecordBatch;
1414
use futures::stream::BoxStream;
1515
use futures::TryStreamExt;
16-
use crate::execution_v1::physical_plan::physical_insert::PhysicalInsert;
1716
use crate::execution_v1::volcano_executor::insert::Insert;
17+
use crate::planner::operator::insert::InsertOperator;
1818

1919
pub type BoxedExecutor = BoxStream<'static, Result<RecordBatch, ExecutorError>>;
2020

@@ -41,10 +41,12 @@ impl VolcanoExecutor {
4141
PhysicalOperator::CreateTable(op) => match &self.storage {
4242
StorageImpl::InMemoryStorage(storage) => CreateTable::execute(op, storage.clone()),
4343
},
44-
PhysicalOperator::Insert(PhysicalInsert { table_name, col_idxs, cols, }) => {
44+
PhysicalOperator::Insert(op) => {
45+
let InsertOperator { table, col_idxs, cols } = op.op;
46+
4547
match &self.storage {
4648
StorageImpl::InMemoryStorage(storage) =>
47-
Insert::execute(table_name, col_idxs, cols, storage.clone()),
49+
Insert::execute(table, col_idxs, cols, storage.clone()),
4850
}
4951
}
5052
}

src/planner/logical_create_table_plan.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::planner::operator::create_table::CreateOperator;
1+
use crate::planner::operator::create_table::CreateTableOperator;
22

33
#[derive(Debug, PartialEq, Clone)]
44
pub struct LogicalCreateTablePlan {
5-
pub operator: CreateOperator
5+
pub operator: CreateTableOperator
66
}
77

88
// use sqlparser::ast::{ColumnDef, ColumnOption, Statement};

src/planner/operator/create_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::catalog::ColumnCatalog;
22

33
#[derive(Debug, PartialEq, Clone)]
4-
pub struct CreateOperator {
4+
pub struct CreateTableOperator {
55
/// Table name to insert to
66
pub table_name: String,
77
/// List of columns of the table

0 commit comments

Comments
 (0)