diff --git a/Cargo.lock b/Cargo.lock index 2ab34fa2618c..918a227a0c42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2368,6 +2368,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "color-backtrace" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "150fd80a270c0671379f388c8204deb6a746bb4eac8a6c03fe2460b2c0127ea0" +dependencies = [ + "backtrace", + "termcolor", +] + [[package]] name = "color-eyre" version = "0.6.3" @@ -2915,6 +2925,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ctor" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" +dependencies = [ + "quote", + "syn 2.0.52", +] + [[package]] name = "ctrlc" version = "3.4.2" @@ -3358,6 +3378,8 @@ dependencies = [ "arrow-schema", "backtrace", "bincode 2.0.0-rc.3", + "color-backtrace", + "ctor 0.2.8", "databend-common-arrow", "databend-common-ast", "geos", @@ -3480,7 +3502,7 @@ dependencies = [ "comfy-table 6.2.0", "crc32fast", "criterion", - "ctor", + "ctor 0.2.8", "databend-common-arrow", "databend-common-ast", "databend-common-base", @@ -4133,7 +4155,7 @@ dependencies = [ "chrono-tz 0.8.6", "cidr", "cron", - "ctor", + "ctor 0.2.8", "dashmap", "databend-common-ast", "databend-common-async-functions", @@ -5092,7 +5114,7 @@ dependencies = [ "chrono-tz 0.8.6", "config", "criterion", - "ctor", + "ctor 0.2.8", "dashmap", "databend-common-arrow", "databend-common-ast", @@ -10416,7 +10438,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fb9b5c752f145ac5046bccc3c4f62892e3c950c1d1eab80c5949cd68a2078db" dependencies = [ - "ctor", + "ctor 0.1.26", "web-time", ] diff --git a/Cargo.toml b/Cargo.toml index a15957997323..25c481642180 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -231,6 +231,7 @@ chrono = { version = "0.4.31", features = ["serde"] } chrono-tz = { version = "0.8", features = ["serde"] } clap = { version = "4.4.2", features = ["derive"] } criterion = "0.5" +ctor = "0.2" dashmap = "5.4.0" deepsize = { version = "0.2.0" } deltalake = "0.18" diff --git a/src/bendpy/Cargo.toml b/src/bendpy/Cargo.toml index e9f6030b4cb1..f156bbba6145 100644 --- a/src/bendpy/Cargo.toml +++ b/src/bendpy/Cargo.toml @@ -17,7 +17,7 @@ crate-type = ["cdylib"] [dependencies] arrow = { workspace = true, features = ["pyarrow"] } arrow-schema = { workspace = true } -ctor = "0.2.5" +ctor = { workspace = true } databend-common-config = { workspace = true } databend-common-exception = { workspace = true } databend-common-expression = { workspace = true } diff --git a/src/common/exception/Cargo.toml b/src/common/exception/Cargo.toml index 0858f1afa9d6..c8406acc4a11 100644 --- a/src/common/exception/Cargo.toml +++ b/src/common/exception/Cargo.toml @@ -11,13 +11,15 @@ doctest = false test = true [dependencies] -databend-common-arrow = { path = "../arrow" } -databend-common-ast = { path = "../../query/ast" } +databend-common-arrow = { workspace = true } +databend-common-ast = { workspace = true } anyhow = { workspace = true } arrow-schema = { workspace = true } backtrace = { workspace = true } bincode = { workspace = true } +color-backtrace = { version = "0.6" } +ctor = { workspace = true } geos = { workspace = true } geozero = { workspace = true } http = { workspace = true } diff --git a/src/common/exception/src/lib.rs b/src/common/exception/src/lib.rs index 3e9be10a2415..170e24188dde 100644 --- a/src/common/exception/src/lib.rs +++ b/src/common/exception/src/lib.rs @@ -28,3 +28,8 @@ pub use exception_backtrace::USER_SET_ENABLE_BACKTRACE; pub use exception_into::SerializedError; pub use with_context::ErrorWithContext; pub use with_context::WithContext; + +#[ctor::ctor] +fn init_color_backtrace() { + color_backtrace::install(); +} diff --git a/src/common/io/Cargo.toml b/src/common/io/Cargo.toml index 93ccb7a30d2f..0a7711f92a6f 100644 --- a/src/common/io/Cargo.toml +++ b/src/common/io/Cargo.toml @@ -16,7 +16,7 @@ borsh = { workspace = true } bytes = { workspace = true } chrono = { workspace = true } chrono-tz = { workspace = true } -databend-common-exception = { path = "../exception" } +databend-common-exception = { workspace = true } ethnum = { workspace = true } geo = { workspace = true } geos = { workspace = true } diff --git a/src/query/ee/Cargo.toml b/src/query/ee/Cargo.toml index f4554779939f..503dd52d2db5 100644 --- a/src/query/ee/Cargo.toml +++ b/src/query/ee/Cargo.toml @@ -69,7 +69,7 @@ jsonb = { workspace = true } tantivy = { workspace = true } [build-dependencies] -databend-common-building = { path = "../../common/building" } +databend-common-building = { workspace = true } [lints] workspace = true diff --git a/src/query/functions/Cargo.toml b/src/query/functions/Cargo.toml index 49eecbcd2621..879bb8f67a15 100644 --- a/src/query/functions/Cargo.toml +++ b/src/query/functions/Cargo.toml @@ -19,7 +19,7 @@ chrono = { workspace = true } chrono-tz = { workspace = true } crc32fast = "1.3.2" criterion = { workspace = true } -ctor = "0.1.26" +ctor = { workspace = true } databend-common-arrow = { workspace = true } databend-common-base = { workspace = true } databend-common-exception = { workspace = true } diff --git a/src/query/service/Cargo.toml b/src/query/service/Cargo.toml index 6c701bc0f01b..a0be07c5b838 100644 --- a/src/query/service/Cargo.toml +++ b/src/query/service/Cargo.toml @@ -49,7 +49,7 @@ byteorder = { workspace = true } chrono = { workspace = true } chrono-tz = { workspace = true } config = { version = "0.13.4", features = [] } -ctor = "0.1.26" +ctor = { workspace = true } dashmap = { workspace = true } databend-common-arrow = { workspace = true } databend-common-ast = { workspace = true } diff --git a/src/query/service/src/servers/mysql/mysql_federated.rs b/src/query/service/src/servers/mysql/mysql_federated.rs index 968280541379..41fa600c146b 100644 --- a/src/query/service/src/servers/mysql/mysql_federated.rs +++ b/src/query/service/src/servers/mysql/mysql_federated.rs @@ -14,8 +14,8 @@ use std::collections::HashMap; use std::sync::Arc; +use std::sync::LazyLock; -use ctor::ctor; use databend_common_expression::types::StringType; use databend_common_expression::utils::FromData; use databend_common_expression::DataBlock; @@ -124,54 +124,62 @@ impl MySQLFederated { // Check SELECT @@variable, @@variable fn federated_select_variable_check(&self, query: &str) -> Option<(TableSchemaRef, DataBlock)> { - #[ctor] - static SELECT_VARIABLES_LAZY_RULES: Vec<(Regex, LazyBlockFunc)> = vec![ - ( - Regex::new("(?i)^(SELECT @@(.*))").unwrap(), - MySQLFederated::select_variable_data_block, - ), - ( - Regex::new("(?i)^(/\\* mysql-connector-java(.*))").unwrap(), - MySQLFederated::select_variable_data_block, - ), - ]; + static SELECT_VARIABLES_LAZY_RULES: LazyLock> = + LazyLock::new(|| { + vec![ + ( + Regex::new("(?i)^(SELECT @@(.*))").unwrap(), + MySQLFederated::select_variable_data_block, + ), + ( + Regex::new("(?i)^(/\\* mysql-connector-java(.*))").unwrap(), + MySQLFederated::select_variable_data_block, + ), + ] + }); FederatedHelper::lazy_block_match_rule(query, &SELECT_VARIABLES_LAZY_RULES) } // Check SHOW VARIABLES LIKE. fn federated_show_variables_check(&self, query: &str) -> Option<(TableSchemaRef, DataBlock)> { - #[ctor] - static SHOW_VARIABLES_RULES: Vec<(Regex, Option<(TableSchemaRef, DataBlock)>)> = vec![ - ( - // sqlalchemy < 1.4.30 - Regex::new("(?i)^(SHOW VARIABLES LIKE 'sql_mode'(.*))").unwrap(), - MySQLFederated::show_variables_block( - "sql_mode", - "ONLY_FULL_GROUP_BY STRICT_TRANS_TABLES NO_ZERO_IN_DATE NO_ZERO_DATE ERROR_FOR_DIVISION_BY_ZERO NO_ENGINE_SUBSTITUTION", - ), - ), - ( - Regex::new("(?i)^(SHOW VARIABLES LIKE 'lower_case_table_names'(.*))").unwrap(), - MySQLFederated::show_variables_block("lower_case_table_names", "0"), - ), - ( - Regex::new("(?i)^(show collation where(.*))").unwrap(), - MySQLFederated::show_variables_block("", ""), - ), - ( - Regex::new("(?i)^(SHOW VARIABLES(.*))").unwrap(), - MySQLFederated::show_variables_block("", ""), - ), - ]; + #![allow(clippy::type_complexity)] + static SHOW_VARIABLES_RULES: LazyLock)>> = + LazyLock::new(|| { + vec![ + ( + // sqlalchemy < 1.4.30 + Regex::new("(?i)^(SHOW VARIABLES LIKE 'sql_mode'(.*))").unwrap(), + MySQLFederated::show_variables_block( + "sql_mode", + "ONLY_FULL_GROUP_BY STRICT_TRANS_TABLES NO_ZERO_IN_DATE NO_ZERO_DATE ERROR_FOR_DIVISION_BY_ZERO NO_ENGINE_SUBSTITUTION", + ), + ), + ( + Regex::new("(?i)^(SHOW VARIABLES LIKE 'lower_case_table_names'(.*))") + .unwrap(), + MySQLFederated::show_variables_block("lower_case_table_names", "0"), + ), + ( + Regex::new("(?i)^(show collation where(.*))").unwrap(), + MySQLFederated::show_variables_block("", ""), + ), + ( + Regex::new("(?i)^(SHOW VARIABLES(.*))").unwrap(), + MySQLFederated::show_variables_block("", ""), + ), + ] + }); FederatedHelper::block_match_rule(query, &SHOW_VARIABLES_RULES) } // Check for SET or others query, this is the final check of the federated query. fn federated_mixed_check(&self, query: &str) -> Option<(TableSchemaRef, DataBlock)> { - #[ctor] - static MIXED_RULES: Vec<(Regex, Option<(TableSchemaRef, DataBlock)>)> = vec![ + #![allow(clippy::type_complexity)] + static MIXED_RULES: LazyLock)>> = + LazyLock::new(|| { + vec![ // Txn. (Regex::new("(?i)^(START(.*))").unwrap(), None), (Regex::new("(?i)^(SET NAMES(.*))").unwrap(), None), @@ -235,7 +243,8 @@ impl MySQLFederated { (Regex::new("(?i)^(/\\*!40014 SET(.*) \\*/)$").unwrap(), None), (Regex::new("(?i)^(/\\*!40000 SET(.*) \\*/)$").unwrap(), None), (Regex::new("(?i)^(/\\*!40000 ALTER(.*) \\*/)$").unwrap(), None), - ]; + ] + }); FederatedHelper::block_match_rule(query, &MIXED_RULES) } diff --git a/src/query/sql/Cargo.toml b/src/query/sql/Cargo.toml index 0edbc8e3a2b1..f7f586d3daae 100644 --- a/src/query/sql/Cargo.toml +++ b/src/query/sql/Cargo.toml @@ -24,7 +24,7 @@ chrono = { workspace = true } chrono-tz = { workspace = true } cidr = { version = "0.2.2" } cron = "0.12.0" -ctor = "0.1.26" +ctor = { workspace = true } dashmap = { workspace = true } databend-common-ast = { workspace = true } databend-common-async-functions = { workspace = true }