@@ -5,14 +5,14 @@ use std::sync::Arc;
55use crate :: array:: DataChunk ;
66use crate :: binder:: { BindError , Binder } ;
77use crate :: catalog:: { CatalogRef , DatabaseCatalog } ;
8- use crate :: executor:: { ExecuteError , ExecutorBuilder } ;
8+ use crate :: executor:: { ExecuteError , Executor } ;
99use crate :: parser:: { parse, ParserError } ;
10- use crate :: storage:: InMemoryStorage ;
10+ use crate :: storage:: { InMemoryStorage , StorageRef } ;
1111
1212/// The database instance.
1313pub struct Database {
1414 catalog : CatalogRef ,
15- executor_builder : ExecutorBuilder ,
15+ storage : StorageRef ,
1616}
1717
1818impl Default for Database {
@@ -26,24 +26,21 @@ impl Database {
2626 pub fn new ( ) -> Self {
2727 let catalog = Arc :: new ( DatabaseCatalog :: new ( ) ) ;
2828 let storage = Arc :: new ( InMemoryStorage :: new ( ) ) ;
29- Database {
30- catalog : catalog. clone ( ) ,
31- executor_builder : ExecutorBuilder :: new ( catalog, storage) ,
32- }
29+ Database { catalog, storage }
3330 }
3431
3532 /// Run SQL queries and return the outputs.
3633 pub fn run ( & self , sql : & str ) -> Result < Vec < DataChunk > , Error > {
3734 // parse
3835 let stmts = parse ( sql) ?;
3936 let mut binder = Binder :: new ( self . catalog . clone ( ) ) ;
37+ let executor = Executor :: new ( self . catalog . clone ( ) , self . storage . clone ( ) ) ;
4038
4139 let mut outputs = vec ! [ ] ;
4240 for stmt in stmts {
4341 let bound_stmt = binder. bind ( & stmt) ?;
4442 debug ! ( "{:#?}" , bound_stmt) ;
45- let mut executor = self . executor_builder . build ( bound_stmt) ;
46- let output = executor. execute ( ) ?;
43+ let output = executor. execute ( bound_stmt) ?;
4744 outputs. push ( output) ;
4845 }
4946 Ok ( outputs)
0 commit comments