From 7a26d7bffd777cb65e71d78dfd85bfd2933d5abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9E=97=E4=BC=9F?= Date: Thu, 1 Feb 2024 14:43:16 +0800 Subject: [PATCH] Add empty physical node --- bustubx/src/planner/operator/mod.rs | 1 - .../planner/physical_plan/{dummy.rs => empty.rs} | 12 +++++++----- bustubx/src/planner/physical_plan/mod.rs | 14 +++++++------- .../planner/physical_planner/physical_planner.rs | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) rename bustubx/src/planner/physical_plan/{dummy.rs => empty.rs} (70%) diff --git a/bustubx/src/planner/operator/mod.rs b/bustubx/src/planner/operator/mod.rs index b49392c..27c1ef7 100644 --- a/bustubx/src/planner/operator/mod.rs +++ b/bustubx/src/planner/operator/mod.rs @@ -26,7 +26,6 @@ pub mod values; #[derive(Debug, Clone)] pub enum LogicalOperator { - Dummy, CreateTable(LogicalCreateTableOperator), CreateIndex(LogicalCreateIndexOperator), // Aggregate(AggregateOperator), diff --git a/bustubx/src/planner/physical_plan/dummy.rs b/bustubx/src/planner/physical_plan/empty.rs similarity index 70% rename from bustubx/src/planner/physical_plan/dummy.rs rename to bustubx/src/planner/physical_plan/empty.rs index 107b60d..359989b 100644 --- a/bustubx/src/planner/physical_plan/dummy.rs +++ b/bustubx/src/planner/physical_plan/empty.rs @@ -4,20 +4,22 @@ use crate::{BustubxResult, Tuple}; use std::sync::Arc; #[derive(Debug)] -pub struct Dummy; +pub struct Empty { + pub schema: SchemaRef, +} -impl VolcanoExecutor for Dummy { +impl VolcanoExecutor for Empty { fn next(&self, context: &mut ExecutionContext) -> BustubxResult> { Ok(None) } fn output_schema(&self) -> SchemaRef { - Arc::new(Schema::empty()) + self.schema.clone() } } -impl std::fmt::Display for Dummy { +impl std::fmt::Display for Empty { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Dummy") + write!(f, "Empty") } } diff --git a/bustubx/src/planner/physical_plan/mod.rs b/bustubx/src/planner/physical_plan/mod.rs index c9734e8..14555c4 100644 --- a/bustubx/src/planner/physical_plan/mod.rs +++ b/bustubx/src/planner/physical_plan/mod.rs @@ -1,6 +1,6 @@ mod create_index; mod create_table; -mod dummy; +mod empty; mod filter; mod insert; mod limit; @@ -12,7 +12,7 @@ mod values; pub use create_index::PhysicalCreateIndex; pub use create_table::PhysicalCreateTable; -pub use dummy::Dummy; +pub use empty::Empty; pub use filter::PhysicalFilter; pub use insert::PhysicalInsert; pub use limit::PhysicalLimit; @@ -31,7 +31,7 @@ use crate::{ #[derive(Debug)] pub enum PhysicalPlan { - Dummy(Dummy), + Empty(Empty), CreateTable(PhysicalCreateTable), CreateIndex(PhysicalCreateIndex), Project(PhysicalProject), @@ -47,7 +47,7 @@ pub enum PhysicalPlan { impl VolcanoExecutor for PhysicalPlan { fn init(&self, context: &mut ExecutionContext) -> BustubxResult<()> { match self { - PhysicalPlan::Dummy(op) => op.init(context), + PhysicalPlan::Empty(op) => op.init(context), PhysicalPlan::CreateTable(op) => op.init(context), PhysicalPlan::CreateIndex(op) => op.init(context), PhysicalPlan::Insert(op) => op.init(context), @@ -63,7 +63,7 @@ impl VolcanoExecutor for PhysicalPlan { fn next(&self, context: &mut ExecutionContext) -> BustubxResult> { match self { - PhysicalPlan::Dummy(op) => op.next(context), + PhysicalPlan::Empty(op) => op.next(context), PhysicalPlan::CreateTable(op) => op.next(context), PhysicalPlan::CreateIndex(op) => op.next(context), PhysicalPlan::Insert(op) => op.next(context), @@ -79,7 +79,7 @@ impl VolcanoExecutor for PhysicalPlan { fn output_schema(&self) -> SchemaRef { match self { - Self::Dummy(op) => op.output_schema(), + Self::Empty(op) => op.output_schema(), Self::CreateTable(op) => op.output_schema(), Self::CreateIndex(op) => op.output_schema(), Self::Insert(op) => op.output_schema(), @@ -97,7 +97,7 @@ impl VolcanoExecutor for PhysicalPlan { impl std::fmt::Display for PhysicalPlan { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Dummy(op) => write!(f, "{op}"), + Self::Empty(op) => write!(f, "{op}"), Self::CreateTable(op) => write!(f, "{op}"), Self::CreateIndex(op) => write!(f, "{op}"), Self::Insert(op) => write!(f, "{op}"), diff --git a/bustubx/src/planner/physical_planner/physical_planner.rs b/bustubx/src/planner/physical_planner/physical_planner.rs index af27bec..309b548 100644 --- a/bustubx/src/planner/physical_planner/physical_planner.rs +++ b/bustubx/src/planner/physical_planner/physical_planner.rs @@ -1,3 +1,4 @@ +use crate::catalog::Schema; use std::sync::Arc; use crate::planner::logical_plan::LogicalPlan; @@ -13,7 +14,7 @@ use crate::planner::physical_plan::PhysicalProject; use crate::planner::physical_plan::PhysicalSeqScan; use crate::planner::physical_plan::PhysicalSort; use crate::planner::physical_plan::PhysicalValues; -use crate::planner::physical_plan::{Dummy, PhysicalCreateIndex}; +use crate::planner::physical_plan::{Empty, PhysicalCreateIndex}; pub struct PhysicalPlanner; @@ -30,7 +31,6 @@ impl PhysicalPlanner { pub fn build_plan(logical_plan: Arc) -> PhysicalPlan { let plan = match logical_plan.operator { - LogicalOperator::Dummy => PhysicalPlan::Dummy(Dummy {}), LogicalOperator::CreateTable(ref logic_create_table) => { PhysicalPlan::CreateTable(PhysicalCreateTable::new( logic_create_table.table_name.clone(),