Skip to content

Commit

Permalink
Add empty physical node
Browse files Browse the repository at this point in the history
  • Loading branch information
lewiszlw committed Feb 1, 2024
1 parent 8c31f27 commit 7a26d7b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
1 change: 0 additions & 1 deletion bustubx/src/planner/operator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub mod values;

#[derive(Debug, Clone)]
pub enum LogicalOperator {
Dummy,
CreateTable(LogicalCreateTableOperator),
CreateIndex(LogicalCreateIndexOperator),
// Aggregate(AggregateOperator),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<Tuple>> {
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")
}
}
14 changes: 7 additions & 7 deletions bustubx/src/planner/physical_plan/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod create_index;
mod create_table;
mod dummy;
mod empty;
mod filter;
mod insert;
mod limit;
Expand All @@ -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;
Expand All @@ -31,7 +31,7 @@ use crate::{

#[derive(Debug)]
pub enum PhysicalPlan {
Dummy(Dummy),
Empty(Empty),
CreateTable(PhysicalCreateTable),
CreateIndex(PhysicalCreateIndex),
Project(PhysicalProject),
Expand All @@ -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),
Expand All @@ -63,7 +63,7 @@ impl VolcanoExecutor for PhysicalPlan {

fn next(&self, context: &mut ExecutionContext) -> BustubxResult<Option<Tuple>> {
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),
Expand All @@ -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(),
Expand All @@ -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}"),
Expand Down
4 changes: 2 additions & 2 deletions bustubx/src/planner/physical_planner/physical_planner.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::catalog::Schema;
use std::sync::Arc;

use crate::planner::logical_plan::LogicalPlan;
Expand All @@ -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;

Expand All @@ -30,7 +31,6 @@ impl PhysicalPlanner {

pub fn build_plan(logical_plan: Arc<LogicalPlan>) -> 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(),
Expand Down

0 comments on commit 7a26d7b

Please sign in to comment.