diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b7f4a25 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "rust-analyzer.linkedProjects": [ + "./Cargo.toml" + ], + "cSpell.words": [ + "Subquery" + ] +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 5369881..5f80e29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod error; pub mod parser; +pub mod planner; pub mod types; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 27b247a..475ecae 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,12 +1,12 @@ mod column; mod data_type; -mod expression; +pub mod expression; mod keyword; pub mod lexer; mod operation; mod operator; -mod stmt; +pub(crate) mod stmt; pub mod token; use crate::parser::operator::{is_infix_oper, is_prefix_oper}; diff --git a/src/planner/binder.rs b/src/planner/binder.rs new file mode 100644 index 0000000..fd68842 --- /dev/null +++ b/src/planner/binder.rs @@ -0,0 +1,16 @@ +use std::sync::Arc; + +use crate::parser::stmt::Statement; + +use super::logical_operation::LogicalPlan; + +pub struct BoundStatement { + _names: Vec, + plan: Arc, +} + +pub struct Binder {} + +impl Binder { + pub fn create_plan(stmt: Statement) {} +} diff --git a/src/planner/logical_operation.rs b/src/planner/logical_operation.rs new file mode 100644 index 0000000..5e2df58 --- /dev/null +++ b/src/planner/logical_operation.rs @@ -0,0 +1,49 @@ +use core::fmt::Debug; + +use std::sync::Arc; + +use crate::parser::expression::Expression; + +#[derive(PartialEq, Debug, Clone)] +pub enum LogicalPlan { + Projection(Projection), + Filter(Filter), + Aggregate(Aggregate), + Sort, + Join, + Statement, + TableScan, + Subquery, + Limit, + Values, + Explain, + Dml, + Ddl, +} + +/// Evaluates an arbitrary list of expressions (essentially a +/// SELECT with an expression list) on its input. +#[derive(PartialEq, Debug, Clone)] +// mark non_exhaustive to encourage use of try_new/new() +#[non_exhaustive] +pub struct Projection { + /// The list of expressions + pub expr: Vec, + /// The incoming logical plan + pub input: Arc, + /// The schema description of the output + pub schema: Option, +} + +#[derive(PartialEq, Debug, Clone)] +#[non_exhaustive] +pub struct Filter { + /// The predicate expression, which must have Boolean type. + pub predicate: Expression, + /// The incoming logical plan + pub input: Box, +} + +#[derive(PartialEq, Debug, Clone)] +#[non_exhaustive] +pub(crate) struct Aggregate {} diff --git a/src/planner/mod.rs b/src/planner/mod.rs new file mode 100644 index 0000000..50390d9 --- /dev/null +++ b/src/planner/mod.rs @@ -0,0 +1,3 @@ +pub mod binder; +pub mod logical_operation; +pub mod planner; diff --git a/src/planner/planner.rs b/src/planner/planner.rs new file mode 100644 index 0000000..2cbf9c4 --- /dev/null +++ b/src/planner/planner.rs @@ -0,0 +1,13 @@ +use crate::parser::stmt::Statement; + +use super::logical_operation::LogicalPlan; + +pub struct Planner { + logic_plan: Option, +} + +impl Planner { + pub fn create_plan(&mut self, _stmt: Statement) { + self.logic_plan = None; + } +} diff --git a/src/types/schema.rs b/src/types/schema.rs index e69de29..8b13789 100644 --- a/src/types/schema.rs +++ b/src/types/schema.rs @@ -0,0 +1 @@ +