From 4d3bc093b7e1f1703b45e284dbe58ce64ad1c7a3 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 17:23:15 +0800 Subject: [PATCH] Implement schema for create index/table --- bustubx/src/expression/mod.rs | 2 +- bustubx/src/planner/logical_plan_v2/mod.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bustubx/src/expression/mod.rs b/bustubx/src/expression/mod.rs index ed119ee..5a2dc41 100644 --- a/bustubx/src/expression/mod.rs +++ b/bustubx/src/expression/mod.rs @@ -14,7 +14,7 @@ use crate::catalog::Schema; use crate::catalog::{Column, DataType}; use crate::common::ScalarValue; use crate::storage::Tuple; -use crate::{BustubxError, BustubxResult}; +use crate::{BustubxResult}; pub trait ExprTrait { /// Get the data type of this expression, given the schema of the input diff --git a/bustubx/src/planner/logical_plan_v2/mod.rs b/bustubx/src/planner/logical_plan_v2/mod.rs index cb30c88..88e87ea 100644 --- a/bustubx/src/planner/logical_plan_v2/mod.rs +++ b/bustubx/src/planner/logical_plan_v2/mod.rs @@ -11,7 +11,7 @@ mod table_scan; mod util; mod values; -use crate::catalog::SchemaRef; +use crate::catalog::{Column, DataType, Schema, SchemaRef}; pub use create_index::CreateIndex; pub use create_table::CreateTable; pub use empty_relation::EmptyRelation; @@ -21,6 +21,7 @@ pub use join::Join; pub use limit::Limit; pub use project::Project; pub use sort::{OrderByExpr, Sort}; +use std::sync::Arc; pub use table_scan::TableScan; pub use util::*; pub use values::Values; @@ -43,10 +44,13 @@ pub enum LogicalPlanV2 { impl LogicalPlanV2 { pub fn schema(&self) -> &SchemaRef { match self { - LogicalPlanV2::CreateTable(_) => todo!(), - LogicalPlanV2::CreateIndex(_) => todo!(), + LogicalPlanV2::CreateTable(_) => &Arc::new(Schema::empty()), + LogicalPlanV2::CreateIndex(_) => &Arc::new(Schema::empty()), LogicalPlanV2::Filter(Filter { input, .. }) => input.schema(), - LogicalPlanV2::Insert(_) => todo!(), + LogicalPlanV2::Insert(_) => &Arc::new(Schema::new(vec![Column::new( + "insert_rows".to_string(), + DataType::Int32, + )])), LogicalPlanV2::Join(Join { schema, .. }) => schema, LogicalPlanV2::Limit(Limit { input, .. }) => input.schema(), LogicalPlanV2::Project(Project { schema, .. }) => schema,