Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pretty print backtrace #15913

Merged
merged 5 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,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.17"
Expand Down
2 changes: 1 addition & 1 deletion src/bendpy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 4 additions & 2 deletions src/common/exception/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 5 additions & 0 deletions src/common/exception/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion src/common/io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/query/ee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jsonb = { workspace = true }
tantivy = { workspace = true }

[build-dependencies]
databend-common-building = { path = "../../common/building" }
databend-common-building = { workspace = true }

[lints]
workspace = true
2 changes: 1 addition & 1 deletion src/query/functions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/query/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
85 changes: 47 additions & 38 deletions src/query/service/src/servers/mysql/mysql_federated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Vec<(Regex, LazyBlockFunc)>> =
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<Vec<(Regex, Option<(TableSchemaRef, DataBlock)>)>> =
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<Vec<(Regex, Option<(TableSchemaRef, DataBlock)>)>> =
LazyLock::new(|| {
vec![
// Txn.
(Regex::new("(?i)^(START(.*))").unwrap(), None),
(Regex::new("(?i)^(SET NAMES(.*))").unwrap(), None),
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/query/sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Loading