Skip to content

Commit 60ddf01

Browse files
committed
Revert "feat(insert): support sql insert simple syntax"
This reverts commit d540169.
1 parent d540169 commit 60ddf01

22 files changed

Lines changed: 72 additions & 304 deletions

File tree

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
use std::collections::HashSet;
2+
23
use anyhow::Result;
34
use sqlparser::ast::{ColumnDef, ObjectName};
45

56
use super::Binder;
67
use crate::binder::{lower_case_name, split_name};
78
use crate::catalog::ColumnCatalog;
89
use crate::planner::logical_create_table_plan::LogicalCreateTablePlan;
9-
use crate::planner::operator::create_table::CreateOperator;
1010

1111
impl Binder {
1212
pub(crate) fn bind_create_table(
1313
&mut self,
14-
name: &ObjectName,
14+
name: ObjectName,
1515
columns: &[ColumnDef],
1616
) -> Result<LogicalCreateTablePlan> {
1717
let name = lower_case_name(&name);
18+
1819
let (_, table_name) = split_name(&name)?;
1920

2021
// check duplicated column names
2122
let mut set = HashSet::new();
2223
for col in columns.iter() {
23-
let col_name = &col.name.value;
24-
if !set.insert(col_name.clone()) {
24+
if !set.insert(col.name.value.clone()) {
2525
return Err(anyhow::Error::msg(format!(
2626
"bind duplicated column {}",
27-
col_name
27+
col.name.value.clone()
2828
)));
2929
}
3030
}
@@ -35,10 +35,8 @@ impl Binder {
3535
.collect();
3636

3737
let plan = LogicalCreateTablePlan {
38-
operator: CreateOperator {
39-
table_name: table_name.to_string(),
40-
columns
41-
},
38+
table_name: table_name.to_string(),
39+
columns,
4240
};
4341
Ok(plan)
4442
}
@@ -48,7 +46,7 @@ impl Binder {
4846
mod tests {
4947
use super::*;
5048
use crate::binder::BinderContext;
51-
use crate::catalog::{ColumnCatalog, ColumnDesc, RootCatalog};
49+
use crate::catalog::{ColumnDesc, RootCatalog};
5250
use crate::planner::LogicalPlan;
5351
use crate::types::LogicalType;
5452

@@ -60,21 +58,19 @@ mod tests {
6058
let plan1 = binder.bind(&stmt[0]).unwrap();
6159

6260
let plan2 = LogicalPlan::CreateTable(LogicalCreateTablePlan {
63-
operator: CreateOperator {
64-
table_name: "t1".to_string(),
65-
columns: vec![
66-
ColumnCatalog::new(
67-
"id".to_string(),
68-
false,
69-
ColumnDesc::new(LogicalType::Integer, false)
70-
),
71-
ColumnCatalog::new(
72-
"name".to_string(),
73-
false,
74-
ColumnDesc::new(LogicalType::Varchar, false)
75-
)
76-
],
77-
},
61+
table_name: "t1".to_string(),
62+
columns: vec![
63+
ColumnCatalog::new(
64+
"id".to_string(),
65+
false,
66+
ColumnDesc::new(LogicalType::Integer, false)
67+
),
68+
ColumnCatalog::new(
69+
"name".to_string(),
70+
false,
71+
ColumnDesc::new(LogicalType::Varchar, false)
72+
)
73+
],
7874
});
7975

8076
assert_eq!(plan1, plan2);

src/binder/insert.rs

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/binder/mod.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
pub mod aggregate;
2-
mod create_table;
2+
mod create;
33
pub mod expr;
44
mod select;
5-
mod insert;
65

76
use std::collections::HashMap;
87

98
use anyhow::Result;
10-
use sqlparser::ast::{Ident, ObjectName, SetExpr, Statement};
9+
use sqlparser::ast::{Ident, ObjectName, Statement};
1110

1211
use crate::catalog::{RootCatalog, DEFAULT_SCHEMA_NAME, CatalogError};
1312
use crate::expression::ScalarExpression;
@@ -60,24 +59,15 @@ impl Binder {
6059
}
6160

6261
pub fn bind(mut self, stmt: &Statement) -> Result<LogicalPlan> {
63-
println!("{:#?}", stmt);
6462
let plan = match stmt {
6563
Statement::Query(query) => {
6664
let plan = self.bind_query(query)?;
6765
LogicalPlan::Select(plan)
6866
}
6967
Statement::CreateTable { name, columns, .. } => {
70-
let plan = self.bind_create_table(name, &columns)?;
68+
let plan = self.bind_create_table(name.to_owned(), &columns)?;
7169
LogicalPlan::CreateTable(plan)
7270
}
73-
Statement::Insert { table_name, columns, source, .. } => {
74-
if let SetExpr::Values(values) = source.body.as_ref() {
75-
let plan = self.bind_insert(table_name.to_owned(), columns, &values.rows)?;
76-
LogicalPlan::Insert(plan)
77-
} else {
78-
todo!()
79-
}
80-
}
8171
_ => unimplemented!(),
8272
};
8373
Ok(plan)

src/binder/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl Binder {
200200
let mut exprs = vec![];
201201
for ref_id in self.context.bind_table.values().cloned().collect_vec() {
202202
let table = self.context.catalog.get_table(ref_id).unwrap();
203-
for (col_id, col) in &table.all_columns() {
203+
for (col_id, col) in &table.get_all_columns() {
204204
let column_ref_id = ColumnRefId::from_table(ref_id, *col_id);
205205
// self.record_regular_table_column(
206206
// &table.name(),

src/catalog/column.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ impl ColumnDesc {
7575
}
7676
}
7777

78+
pub(crate) fn is_primary(&self) -> bool {
79+
self.is_primary
80+
}
81+
7882
pub(crate) fn get_datatype(&self) -> LogicalType {
7983
self.column_datatype.clone()
8084
}

src/catalog/table.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use std::collections::HashMap;
2-
use std::sync::Arc;
3-
use arrow::datatypes::{Schema, SchemaRef};
42

53
use itertools::Itertools;
64

75
use crate::catalog::{CatalogError, ColumnCatalog};
86
use crate::types::{ColumnIdx, IdGenerator, TableIdx};
9-
#[derive(Debug, Clone, PartialEq)]
7+
#[derive(Debug, Clone)]
108
pub struct TableCatalog {
119
pub id: Option<TableIdx>,
1210
pub name: String,
@@ -17,10 +15,6 @@ pub struct TableCatalog {
1715
}
1816

1917
impl TableCatalog {
20-
pub(crate) fn columns_len(&self) -> usize {
21-
self.columns.len()
22-
}
23-
2418
pub(crate) fn get_column_by_id(&self, id: ColumnIdx) -> Option<&ColumnCatalog> {
2519
self.columns.get(id)
2620
}
@@ -38,21 +32,13 @@ impl TableCatalog {
3832
self.column_idxs.contains_key(name)
3933
}
4034

41-
pub(crate) fn all_columns(&self) -> Vec<(ColumnIdx, &ColumnCatalog)> {
35+
pub(crate) fn get_all_columns(&self) -> Vec<(ColumnIdx, &ColumnCatalog)> {
4236
self.columns
4337
.iter()
4438
.enumerate()
4539
.collect_vec()
4640
}
4741

48-
// TODO: 缓存schema
49-
pub(crate) fn schema(&self) -> SchemaRef {
50-
let fields = self.columns.iter()
51-
.map(ColumnCatalog::to_field)
52-
.collect_vec();
53-
Arc::new(Schema::new(fields))
54-
}
55-
5642
/// Add a column to the table catalog.
5743
pub(crate) fn add_column(
5844
&mut self,

src/db.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ pub enum DatabaseError {
123123
mod test {
124124
use std::sync::Arc;
125125
use arrow::array::{BooleanArray, Int32Array};
126-
use arrow::compute::concat_batches;
127126
use arrow::datatypes::Schema;
128127
use arrow::record_batch::RecordBatch;
129128
use itertools::Itertools;
@@ -178,14 +177,9 @@ mod test {
178177
let database = Database::new_on_mem();
179178

180179
tokio_test::block_on(async move {
181-
let _ = database.run("create table t1 (a int, b boolean)").await?;
182-
let _ = database.run("insert into t1 values (1, true), (2, false)").await?;
183-
let vec_batch = database.run("select * from t1").await?;
184-
185-
let table = database.storage
186-
.get_catalog()
187-
.get_table(0).unwrap().clone();
188-
println!("{:#?}", concat_batches(&table.schema(), &vec_batch));
180+
let _batch = database.run("create table t1 (a int, b int)").await?;
181+
let batch = database.run("select * from t1").await?;
182+
println!("{:#?}", batch);
189183

190184
Ok(())
191185
})

src/execution/physical/physical_plan_builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ impl PhysicalPlanBuilder {
3030
match plan {
3131
LogicalPlan::Select(select) => self.build_select_logical_plan(select),
3232
LogicalPlan::CreateTable(_) => todo!(),
33-
LogicalPlan::Insert(_) => todo!(),
3433
}
3534
}
3635

src/execution_v1/physical_plan/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
use crate::execution_v1::physical_plan::physical_create_table::PhysicalCreateTable;
2-
use crate::execution_v1::physical_plan::physical_insert::PhysicalInsert;
32
use crate::execution_v1::physical_plan::physical_projection::PhysicalProjection;
43
use crate::execution_v1::physical_plan::physical_table_scan::PhysicalTableScan;
54

65
pub(crate) mod physical_create_table;
76
pub(crate) mod physical_plan_builder;
87
pub(crate) mod physical_projection;
98
pub(crate) mod physical_table_scan;
10-
pub(crate) mod physical_insert;
119

1210
#[derive(Debug)]
1311
pub enum PhysicalOperator {
14-
Insert(PhysicalInsert),
1512
CreateTable(PhysicalCreateTable),
1613
TableScan(PhysicalTableScan),
1714
Projection(PhysicalProjection),

src/execution_v1/physical_plan/physical_insert.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)