1- use std:: sync:: Arc ;
2-
31use anyhow:: Result ;
4- use arrow:: datatypes:: Schema ;
52use arrow:: error:: ArrowError ;
63use arrow:: record_batch:: RecordBatch ;
74use sqlparser:: parser:: ParserError ;
85
96use crate :: binder:: { BindError , Binder , BinderContext } ;
10- use crate :: catalog:: ColumnCatalog ;
117use crate :: execution_v1:: physical_plan:: physical_plan_builder:: PhysicalPlanBuilder ;
128use crate :: execution_v1:: volcano_executor:: VolcanoExecutor ;
139use crate :: parser:: parse_sql;
14- use crate :: planner:: LogicalPlan ;
1510use crate :: storage:: memory:: InMemoryStorage ;
1611use crate :: storage:: { Storage , StorageError , StorageImpl } ;
17- use crate :: types:: IdGenerator ;
1812
1913#[ derive( Debug ) ]
2014pub struct Database {
@@ -51,10 +45,11 @@ impl Database {
5145 /// Limit(1)
5246 /// Project(a,b)
5347 let logical_plan = binder. bind ( & stmts[ 0 ] ) ?;
54- println ! ( "logic plan {:#?}" , logical_plan) ;
48+ println ! ( "logic plan: {:#?}" , logical_plan) ;
5549
5650 let mut builder = PhysicalPlanBuilder :: new ( ) ;
5751 let operator = builder. build_plan ( & logical_plan) ?;
52+ println ! ( "operator: {:#?}" , logical_plan) ;
5853
5954 let storage = StorageImpl :: InMemoryStorage ( self . storage . clone ( ) ) ;
6055 let executor = VolcanoExecutor :: new ( storage) ;
@@ -127,7 +122,7 @@ pub enum DatabaseError {
127122#[ cfg( test) ]
128123mod test {
129124 use std:: sync:: Arc ;
130- use arrow:: array:: Int32Array ;
125+ use arrow:: array:: { BooleanArray , Int32Array } ;
131126 use arrow:: datatypes:: Schema ;
132127 use arrow:: record_batch:: RecordBatch ;
133128 use itertools:: Itertools ;
@@ -136,22 +131,32 @@ mod test {
136131 use crate :: execution_v1:: ExecutorError ;
137132 use crate :: storage:: { Storage , StorageError } ;
138133 use crate :: storage:: memory:: InMemoryStorage ;
139- use crate :: types:: { IdGenerator , LogicalType , TableId } ;
140-
141- fn build_table ( storage : & impl Storage ) -> Result < TableId , StorageError > {
142- let fields = vec ! [
143- ColumnCatalog :: new(
144- "c1" . to_string( ) ,
145- false ,
146- ColumnDesc :: new( LogicalType :: Integer , true )
147- ) . to_field( ) ,
148- ] ;
149- let batch = RecordBatch :: try_new (
150- Arc :: new ( Schema :: new ( fields) ) ,
151- vec ! [ Arc :: new( Int32Array :: from( vec![ 1 , 2 , 3 , 4 , 5 ] ) ) ]
134+ use crate :: types:: { IdGenerator , LogicalType , TableIdx } ;
135+
136+ fn build_table ( storage : & impl Storage ) -> Result < TableIdx , StorageError > {
137+ let schema = Arc :: new ( Schema :: new (
138+ vec ! [
139+ ColumnCatalog :: new(
140+ "c1" . to_string( ) ,
141+ false ,
142+ ColumnDesc :: new( LogicalType :: Integer , true )
143+ ) . to_field( ) ,
144+ ColumnCatalog :: new(
145+ "c2" . to_string( ) ,
146+ false ,
147+ ColumnDesc :: new( LogicalType :: Boolean , false )
148+ ) . to_field( ) ,
149+ ]
150+ ) ) ;
151+ let batch_1 = RecordBatch :: try_new (
152+ schema. clone ( ) ,
153+ vec ! [
154+ Arc :: new( Int32Array :: from( vec![ 1 , 2 , 3 , 4 , 5 ] ) ) ,
155+ Arc :: new( BooleanArray :: from( vec![ true , true , false , true , false ] ) )
156+ ]
152157 ) . unwrap ( ) ;
153158
154- Ok ( storage. create_table ( "t1" , vec ! [ batch ] ) ?)
159+ Ok ( storage. create_table ( "t1" , vec ! [ batch_1 ] ) ?)
155160 }
156161
157162 #[ test]
@@ -172,8 +177,8 @@ mod test {
172177 let database = Database :: new_on_mem ( ) ;
173178
174179 tokio_test:: block_on ( async move {
175- let _batch = database. run ( "create table t1 (a int)" ) . await ?;
176- let batch = database. run ( "select a from t1" ) . await ?;
180+ let _batch = database. run ( "create table t1 (a int, b int )" ) . await ?;
181+ let batch = database. run ( "select * from t1" ) . await ?;
177182 println ! ( "{:#?}" , batch) ;
178183
179184 Ok ( ( ) )
0 commit comments