diff --git a/Cargo.lock b/Cargo.lock index 028d194..18c6913 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -206,7 +206,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -603,6 +603,19 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "errno" version = "0.2.8" @@ -650,8 +663,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e11dcc7e4d79a8c89b9ab4c6f5c30b1fc4a83c420792da3542fd31179ed5f517" dependencies = [ "cfg-if", - "rustix", - "windows-sys", + "rustix 0.35.7", + "windows-sys 0.36.1", ] [[package]] @@ -835,6 +848,15 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + [[package]] name = "humantime" version = "2.1.0" @@ -890,6 +912,28 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24c3f4eff5495aee4c0399d7b6a0dc2b6e81be84242ffbfcf253ebacccc1d0cb" +[[package]] +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys 0.42.0", +] + +[[package]] +name = "is-terminal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330" +dependencies = [ + "hermit-abi 0.2.6", + "io-lifetimes 1.0.3", + "rustix 0.36.5", + "windows-sys 0.42.0", +] + [[package]] name = "itertools" version = "0.10.3" @@ -992,9 +1036,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.126" +version = "0.2.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "libm" @@ -1045,6 +1089,12 @@ version = "0.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" +[[package]] +name = "linux-raw-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" + [[package]] name = "lock_api" version = "0.4.7" @@ -1079,7 +1129,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -1205,7 +1255,7 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", ] @@ -1269,7 +1319,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -1450,10 +1500,24 @@ checksum = "d51cc38aa10f6bbb377ed28197aa052aa4e2b762c22be9d3153d01822587e787" dependencies = [ "bitflags", "errno", - "io-lifetimes", + "io-lifetimes 0.7.2", + "libc", + "linux-raw-sys 0.0.46", + "windows-sys 0.36.1", +] + +[[package]] +name = "rustix" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes 1.0.3", "libc", - "linux-raw-sys", - "windows-sys", + "linux-raw-sys 0.1.3", + "windows-sys 0.42.0", ] [[package]] @@ -1663,10 +1727,12 @@ dependencies = [ "dirs", "downcast-rs", "enum_dispatch", + "env_logger", "futures", "futures-async-stream", "itertools", "lazy_static", + "log", "ordered-float", "paste", "petgraph", @@ -2023,43 +2089,100 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", +] + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "yansi" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 368d883..4c59cc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,8 @@ strum = "0.24" strum_macros = "0.24" ordered-float = "3.0" derive-new = "0.5.9" +log = "0.4" +env_logger = "0.10" [dev-dependencies] test-case = "2" diff --git a/Makefile b/Makefile index 2a1851e..5f48f1f 100644 --- a/Makefile +++ b/Makefile @@ -37,3 +37,6 @@ debug: debug_v2: ENABLE_V2=1 RUST_BACKTRACE=1 cargo run + +debug_v2_log: + RUST_LOG='sqlrs::planner=debug,sqlrs::execution=debug' ENABLE_V2=1 RUST_BACKTRACE=1 cargo run diff --git a/src/execution/mod.rs b/src/execution/mod.rs index f464967..5f61378 100644 --- a/src/execution/mod.rs +++ b/src/execution/mod.rs @@ -19,6 +19,8 @@ use crate::catalog_v2::CatalogError; use crate::main_entry::ClientContext; use crate::types_v2::TypeError; +static LOGGING_TARGET: &str = "sqlrs::execution"; + #[derive(new)] pub struct ExecutionContext { pub(crate) client_context: Arc, diff --git a/src/execution/physical_plan_generator.rs b/src/execution/physical_plan_generator.rs index b627e04..3d1e41c 100644 --- a/src/execution/physical_plan_generator.rs +++ b/src/execution/physical_plan_generator.rs @@ -1,10 +1,13 @@ use std::sync::Arc; use derive_new::new; +use log::debug; use super::{ColumnBindingResolver, PhysicalOperator}; +use crate::execution::LOGGING_TARGET; use crate::main_entry::ClientContext; use crate::planner_v2::{LogicalOperator, LogicalOperatorVisitor}; +use crate::util::tree_render::TreeRender; #[derive(new)] pub struct PhysicalPlanGenerator { @@ -21,7 +24,13 @@ impl PhysicalPlanGenerator { op.resolve_operator_types(); // then create the main physical plan - self.create_plan_internal(op) + let plan = self.create_plan_internal(op); + debug!( + target: LOGGING_TARGET, + "Physical Plan:\n{}", + TreeRender::physical_plan_tree(&plan), + ); + plan } pub(crate) fn create_plan_internal(&self, op: LogicalOperator) -> PhysicalOperator { diff --git a/src/main.rs b/src/main.rs index a347095..c1a6b7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,8 @@ use sqlrs::{cli, Database}; #[tokio::main] async fn main() -> Result<()> { + env_logger::init(); + let db = Database::new_on_csv(); create_csv_table(&db, "employee")?; create_csv_table(&db, "department")?; diff --git a/src/planner_v2/binder/statement/bind_insert.rs b/src/planner_v2/binder/statement/bind_insert.rs index adb2d09..466b58a 100644 --- a/src/planner_v2/binder/statement/bind_insert.rs +++ b/src/planner_v2/binder/statement/bind_insert.rs @@ -88,8 +88,6 @@ impl Binder { let mut plan = select_node.plan; // cast inserted types to expected types when necessary self.cast_logical_operator_to_types(&inserted_types, &expected_types, &mut plan)?; - // TODO: add debug level log for plan - // println!("plan: {:#?}", plan); let root = LogicalInsert::new( LogicalOperatorBase::new(vec![plan], vec![], vec![]), diff --git a/src/planner_v2/mod.rs b/src/planner_v2/mod.rs index c95cd55..0ebbdd5 100644 --- a/src/planner_v2/mod.rs +++ b/src/planner_v2/mod.rs @@ -13,12 +13,16 @@ pub use constants::*; pub use errors::*; pub use expression_binder::*; pub use expression_iterator::*; +use log::debug; pub use logical_operator_visitor::*; pub use operator::*; use sqlparser::ast::Statement; use crate::main_entry::ClientContext; use crate::types_v2::LogicalType; +use crate::util::tree_render::TreeRender; + +static LOGGING_TARGET: &str = "sqlrs::planner"; pub struct Planner { binder: Binder, @@ -41,14 +45,27 @@ impl Planner { } pub fn create_plan(&mut self, statement: &Statement) -> Result<(), PlannerError> { + debug!( + target: LOGGING_TARGET, + "Planner raw statement: {:?}", statement + ); + let bound_statement = self.binder.bind(statement)?; + + debug!( + target: LOGGING_TARGET, + r#"Planner bound_statement: +names: {:?} +types: {:?} +plan: +{}"#, + bound_statement.names, + bound_statement.types, + TreeRender::logical_plan_tree(&bound_statement.plan), + ); self.plan = Some(bound_statement.plan); self.names = Some(bound_statement.names); self.types = Some(bound_statement.types); - // println!( - // "created_plan: {:#?}\nnames: {:?}\ntypes: {:?}", - // self.plan, self.names, self.types - // ); Ok(()) } } diff --git a/src/util/tree_render.rs b/src/util/tree_render.rs index c765cad..2d1895a 100644 --- a/src/util/tree_render.rs +++ b/src/util/tree_render.rs @@ -30,9 +30,10 @@ impl TreeRender { } BoundExpression::BoundCastExpression(e) => { format!( - "Cast({}[{}])", + "Cast({}[{}],{:?})", e.base.alias, - Self::bound_expression_to_string(&e.child) + Self::bound_expression_to_string(&e.child), + e.base.return_type, ) } }