Skip to content

Commit

Permalink
Remove v2 suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
lewiszlw committed Feb 1, 2024
1 parent 46b606e commit e44cd5f
Show file tree
Hide file tree
Showing 27 changed files with 122 additions and 125 deletions.
4 changes: 2 additions & 2 deletions bustubx/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;
use tempfile::TempDir;

use crate::error::{BustubxError, BustubxResult};
use crate::planner::logical_plan_v2::LogicalPlanV2;
use crate::planner::logical_plan::LogicalPlan;
use crate::planner::PhysicalPlanner;
use crate::{
buffer::BufferPoolManager,
Expand Down Expand Up @@ -66,7 +66,7 @@ impl Database {
Ok(tuples)
}

pub fn build_logical_plan(&mut self, sql: &str) -> BustubxResult<LogicalPlanV2> {
pub fn build_logical_plan(&mut self, sql: &str) -> BustubxResult<LogicalPlan> {
// sql -> ast
let stmts = crate::parser::parse_sql(sql)?;
if stmts.len() != 1 {
Expand Down
8 changes: 4 additions & 4 deletions bustubx/src/optimizer/logical_optimizer.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::error::BustubxResult;
use crate::optimizer::rule::PushDownLimit;
use crate::planner::logical_plan_v2::LogicalPlanV2;
use crate::planner::logical_plan::LogicalPlan;
use std::sync::Arc;

/// `LogicalOptimizerRule` transforms one [`LogicalPlanV2`] into another which
/// `LogicalOptimizerRule` transforms one [`LogicalPlan`] into another which
/// computes the same results, but in a potentially more efficient
/// way. If there are no suitable transformations for the input plan,
/// the optimizer can simply return it as is.
pub trait LogicalOptimizerRule {
/// Try and rewrite `plan` to an optimized form, returning None if the plan cannot be
/// optimized by this rule.
fn try_optimize(&self, plan: &LogicalPlanV2) -> BustubxResult<Option<LogicalPlanV2>>;
fn try_optimize(&self, plan: &LogicalPlan) -> BustubxResult<Option<LogicalPlan>>;

/// A human readable name for this optimizer rule
fn name(&self) -> &str;
Expand Down Expand Up @@ -42,7 +42,7 @@ impl LogicalOptimizer {
Self { rules }
}

pub fn optimize(&self, plan: &LogicalPlanV2) -> BustubxResult<LogicalPlanV2> {
pub fn optimize(&self, plan: &LogicalPlan) -> BustubxResult<LogicalPlan> {
todo!()
}
}
4 changes: 2 additions & 2 deletions bustubx/src/optimizer/rule/push_down_limit.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::error::BustubxResult;
use crate::optimizer::LogicalOptimizerRule;
use crate::planner::logical_plan_v2::LogicalPlanV2;
use crate::planner::logical_plan::LogicalPlan;

pub struct PushDownLimit;

impl LogicalOptimizerRule for PushDownLimit {
fn try_optimize(&self, plan: &LogicalPlanV2) -> BustubxResult<Option<LogicalPlanV2>> {
fn try_optimize(&self, plan: &LogicalPlan) -> BustubxResult<Option<LogicalPlan>> {
todo!()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::catalog::SchemaRef;
use crate::common::table_ref::TableReference;
use crate::planner::logical_plan_v2::OrderByExpr;
use crate::planner::logical_plan::OrderByExpr;

#[derive(derive_new::new, Debug, Clone)]
pub struct CreateIndex {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::expression::Expr;
use crate::planner::logical_plan_v2::LogicalPlanV2;
use crate::planner::logical_plan::LogicalPlan;
use std::sync::Arc;

#[derive(derive_new::new, Debug, Clone)]
pub struct Filter {
/// The predicate expression, which must have Boolean type.
pub predicate: Expr,
/// The incoming logical plan
pub input: Arc<LogicalPlanV2>,
pub input: Arc<LogicalPlan>,
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::catalog::SchemaRef;

Check warning on line 1 in bustubx/src/planner/logical_plan/insert.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `crate::catalog::SchemaRef`
use crate::common::table_ref::TableReference;
use crate::planner::logical_plan_v2::LogicalPlanV2;
use crate::planner::logical_plan::LogicalPlan;
use std::sync::Arc;

#[derive(derive_new::new, Debug, Clone)]
pub struct Insert {
pub table: TableReference,
pub columns: Vec<String>,
pub input: Arc<LogicalPlanV2>,
pub input: Arc<LogicalPlan>,
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::catalog::SchemaRef;
use crate::expression::Expr;
use crate::planner::logical_plan_v2::LogicalPlanV2;
use crate::planner::logical_plan::LogicalPlan;
use std::sync::Arc;

#[derive(derive_new::new, Debug, Clone)]
pub struct Join {
/// Left input
pub left: Arc<LogicalPlanV2>,
pub left: Arc<LogicalPlan>,
/// Right input
pub right: Arc<LogicalPlanV2>,
pub right: Arc<LogicalPlan>,
pub join_type: JoinType,
pub condition: Option<Expr>,
pub schema: SchemaRef,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::planner::logical_plan_v2::LogicalPlanV2;
use crate::planner::logical_plan::LogicalPlan;
use std::sync::Arc;

#[derive(derive_new::new, Debug, Clone)]
pub struct Limit {
pub limit: Option<usize>,
pub offset: usize,
pub input: Arc<LogicalPlanV2>,
pub input: Arc<LogicalPlan>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use util::*;
pub use values::Values;

#[derive(Debug, Clone)]
pub enum LogicalPlanV2 {
pub enum LogicalPlan {
CreateTable(CreateTable),
CreateIndex(CreateIndex),
Filter(Filter),
Expand All @@ -40,23 +40,23 @@ pub enum LogicalPlanV2 {
EmptyRelation(EmptyRelation),
}

impl LogicalPlanV2 {
impl LogicalPlan {
pub fn schema(&self) -> &SchemaRef {
match self {
LogicalPlanV2::CreateTable(_) => todo!(),
LogicalPlanV2::CreateIndex(_) => todo!(),
LogicalPlanV2::Filter(Filter { input, .. }) => input.schema(),
LogicalPlanV2::Insert(_) => todo!(),
LogicalPlanV2::Join(Join { schema, .. }) => schema,
LogicalPlanV2::Limit(Limit { input, .. }) => input.schema(),
LogicalPlanV2::Project(Project { schema, .. }) => schema,
LogicalPlanV2::TableScan(TableScan {
LogicalPlan::CreateTable(_) => todo!(),
LogicalPlan::CreateIndex(_) => todo!(),
LogicalPlan::Filter(Filter { input, .. }) => input.schema(),
LogicalPlan::Insert(_) => todo!(),
LogicalPlan::Join(Join { schema, .. }) => schema,
LogicalPlan::Limit(Limit { input, .. }) => input.schema(),
LogicalPlan::Project(Project { schema, .. }) => schema,
LogicalPlan::TableScan(TableScan {
table_schema: schema,
..
}) => schema,
LogicalPlanV2::Sort(Sort { input, .. }) => input.schema(),
LogicalPlanV2::Values(Values { schema, .. }) => schema,
LogicalPlanV2::EmptyRelation(EmptyRelation { schema, .. }) => schema,
LogicalPlan::Sort(Sort { input, .. }) => input.schema(),
LogicalPlan::Values(Values { schema, .. }) => schema,
LogicalPlan::EmptyRelation(EmptyRelation { schema, .. }) => schema,
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::catalog::SchemaRef;
use crate::expression::Expr;
use crate::planner::logical_plan_v2::LogicalPlanV2;
use crate::planner::logical_plan::LogicalPlan;
use std::sync::Arc;

#[derive(derive_new::new, Debug, Clone)]
pub struct Project {
pub exprs: Vec<Expr>,
pub input: Arc<LogicalPlanV2>,
pub input: Arc<LogicalPlan>,
pub schema: SchemaRef,
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::expression::Expr;
use crate::planner::logical_plan_v2::LogicalPlanV2;
use crate::planner::logical_plan::LogicalPlan;
use std::sync::Arc;

#[derive(derive_new::new, Debug, Clone)]
pub struct Sort {
pub expr: Vec<OrderByExpr>,
pub input: Arc<LogicalPlanV2>,
pub input: Arc<LogicalPlan>,
pub limit: Option<usize>,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::catalog::{ColumnRef, Schema};
use crate::expression::{Expr, ExprTrait};
use crate::planner::logical_plan_v2::JoinType;
use crate::planner::logical_plan_v2::LogicalPlanV2;
use crate::planner::logical_plan::JoinType;
use crate::planner::logical_plan::LogicalPlan;
use crate::BustubxResult;
use std::sync::Arc;

Expand Down Expand Up @@ -43,7 +43,7 @@ pub fn build_join_schema(
Ok(Schema { columns })
}

pub fn project_schema(input: &LogicalPlanV2, exprs: &[Expr]) -> BustubxResult<Schema> {
pub fn project_schema(input: &LogicalPlan, exprs: &[Expr]) -> BustubxResult<Schema> {
let input_schema = &input.schema();
let mut columns = vec![];
for expr in exprs {
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions bustubx/src/planner/logical_planner/logical_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{BustubxError, BustubxResult};

use crate::catalog::Catalog;
use crate::common::table_ref::TableReference;
use crate::planner::logical_plan_v2::{LogicalPlanV2, OrderByExpr};
use crate::planner::logical_plan::{LogicalPlan, OrderByExpr};

pub struct PlannerContext<'a> {
pub catalog: &'a Catalog,
Expand All @@ -12,24 +12,24 @@ pub struct LogicalPlanner<'a> {
pub context: PlannerContext<'a>,
}
impl<'a> LogicalPlanner<'a> {
pub fn plan(&mut self, stmt: &sqlparser::ast::Statement) -> BustubxResult<LogicalPlanV2> {
pub fn plan(&mut self, stmt: &sqlparser::ast::Statement) -> BustubxResult<LogicalPlan> {
match stmt {
sqlparser::ast::Statement::CreateTable { name, columns, .. } => {
self.plan_create_table_v2(name, columns)
self.plan_create_table(name, columns)
}
sqlparser::ast::Statement::CreateIndex {
name,
table_name,
columns,
..
} => self.plan_create_index_v2(name, table_name, columns),
sqlparser::ast::Statement::Query(query) => self.plan_query_v2(query),
} => self.plan_create_index(name, table_name, columns),
sqlparser::ast::Statement::Query(query) => self.plan_query(query),
sqlparser::ast::Statement::Insert {
table_name,
columns,
source,
..
} => self.plan_insert_v2(table_name, columns, source),
} => self.plan_insert(table_name, columns, source),
_ => unimplemented!(),
}
}
Expand Down
8 changes: 4 additions & 4 deletions bustubx/src/planner/logical_planner/plan_create_index.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::planner::logical_plan_v2::{CreateIndex, LogicalPlanV2};
use crate::planner::logical_plan::{CreateIndex, LogicalPlan};
use crate::{BustubxError, BustubxResult};

use super::LogicalPlanner;

impl<'a> LogicalPlanner<'a> {
pub fn plan_create_index_v2(
pub fn plan_create_index(
&self,
index_name: &sqlparser::ast::ObjectName,
table_name: &sqlparser::ast::ObjectName,
columns: &Vec<sqlparser::ast::OrderByExpr>,
) -> BustubxResult<LogicalPlanV2> {
) -> BustubxResult<LogicalPlan> {
let index_name = index_name
.0
.get(0)
Expand All @@ -30,7 +30,7 @@ impl<'a> LogicalPlanner<'a> {
Err(BustubxError::Plan(format!("table {} not found", table))),
|info| Ok(info.schema.clone()),
)?;
Ok(LogicalPlanV2::CreateIndex(CreateIndex {
Ok(LogicalPlan::CreateIndex(CreateIndex {
index_name,
table,
table_schema,
Expand Down
8 changes: 4 additions & 4 deletions bustubx/src/planner/logical_planner/plan_create_table.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::BustubxResult;

use crate::catalog::Column;
use crate::planner::logical_plan_v2::{CreateTable, LogicalPlanV2};
use crate::planner::logical_plan::{CreateTable, LogicalPlan};

use super::LogicalPlanner;

impl<'a> LogicalPlanner<'a> {
pub fn plan_create_table_v2(
pub fn plan_create_table(
&self,
name: &sqlparser::ast::ObjectName,
column_defs: &Vec<sqlparser::ast::ColumnDef>,
) -> BustubxResult<LogicalPlanV2> {
) -> BustubxResult<LogicalPlan> {
let name = self.plan_table_name(name)?;
let mut columns = vec![];
for col_def in column_defs {
Expand All @@ -19,6 +19,6 @@ impl<'a> LogicalPlanner<'a> {
(&col_def.data_type).try_into()?,
))
}
Ok(LogicalPlanV2::CreateTable(CreateTable { name, columns }))
Ok(LogicalPlan::CreateTable(CreateTable { name, columns }))
}
}
8 changes: 4 additions & 4 deletions bustubx/src/planner/logical_planner/plan_insert.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use crate::BustubxResult;
use std::sync::Arc;

use crate::planner::logical_plan_v2::{Insert, LogicalPlanV2};
use crate::planner::logical_plan::{Insert, LogicalPlan};

use super::LogicalPlanner;

impl<'a> LogicalPlanner<'a> {
pub fn plan_insert_v2(
pub fn plan_insert(
&self,
table_name: &sqlparser::ast::ObjectName,
columns_ident: &Vec<sqlparser::ast::Ident>,
source: &sqlparser::ast::Query,
) -> BustubxResult<LogicalPlanV2> {
) -> BustubxResult<LogicalPlan> {
let values = self.plan_set_expr(source.body.as_ref())?;
let table = self.plan_table_name(table_name)?;
let columns = columns_ident
.iter()
.map(|ident| ident.value.clone())
.collect();
Ok(LogicalPlanV2::Insert(Insert {
Ok(LogicalPlan::Insert(Insert {
table,
columns,
input: Arc::new(values),
Expand Down
Loading

0 comments on commit e44cd5f

Please sign in to comment.