mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-21 12:41:39 +00:00
fix(plugin-plan): resolve Doris profiles to the Doris explain dialect
This commit is contained in:
@@ -74,12 +74,16 @@ pub async fn get_agent_explain_info_core(
|
||||
decode_agent_explain_result(result)
|
||||
}
|
||||
|
||||
/// Resolves the dialect an EXPLAIN must be generated for. A custom JDBC
|
||||
/// connection is only known to be Oracle when its configuration says so; every
|
||||
/// other custom JDBC connection stays `Jdbc` and therefore gets no plan
|
||||
/// acquisition. Shared with the plugin Host plan API so both paths agree on
|
||||
/// which dialects are treatable.
|
||||
/// Resolves the dialect an EXPLAIN must be generated for. Doris' MySQL-based
|
||||
/// connection profiles are Doris dialects, not MySQL. A custom JDBC connection
|
||||
/// is only known to be Oracle when its configuration says so; every other
|
||||
/// custom JDBC connection stays `Jdbc` and therefore gets no plan acquisition.
|
||||
/// Shared with the plugin Host plan API so both paths agree on which dialects
|
||||
/// are treatable.
|
||||
pub(crate) fn explain_database_type(config: &ConnectionConfig) -> DatabaseType {
|
||||
if crate::db::doris::is_config(config) {
|
||||
return DatabaseType::Doris;
|
||||
}
|
||||
if config.db_type != DatabaseType::Jdbc {
|
||||
return config.db_type;
|
||||
}
|
||||
@@ -129,6 +133,7 @@ mod tests {
|
||||
use crate::plugins::{
|
||||
InstalledPlugin, PluginDriverManifest, PluginDriverSession, PluginManifest, PluginRuntimeEnv,
|
||||
};
|
||||
use crate::query_execution_sql::{build_explain_sql, ExplainSqlOptions};
|
||||
#[cfg(unix)]
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -153,6 +158,41 @@ mod tests {
|
||||
assert!(decode_agent_explain_result(serde_json::json!(["unexpected"])).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolves_doris_profiles_to_doris_explain_sql_without_changing_mysql() {
|
||||
let cases = [
|
||||
(DatabaseType::Doris, None, DatabaseType::Doris, "EXPLAIN SELECT 1"),
|
||||
(DatabaseType::Mysql, Some("doris"), DatabaseType::Doris, "EXPLAIN SELECT 1"),
|
||||
(DatabaseType::Mysql, Some("selectdb"), DatabaseType::Doris, "EXPLAIN SELECT 1"),
|
||||
(DatabaseType::Mysql, None, DatabaseType::Mysql, "EXPLAIN FORMAT=JSON SELECT 1"),
|
||||
(DatabaseType::Mysql, Some("mysql"), DatabaseType::Mysql, "EXPLAIN FORMAT=JSON SELECT 1"),
|
||||
];
|
||||
|
||||
for (raw_type, driver_profile, expected_type, expected_sql) in cases {
|
||||
let config: ConnectionConfig = serde_json::from_value(serde_json::json!({
|
||||
"id": "dialect-test",
|
||||
"name": "Dialect test",
|
||||
"db_type": raw_type.as_str(),
|
||||
"driver_profile": driver_profile,
|
||||
"host": "127.0.0.1",
|
||||
"port": 9030,
|
||||
"username": "user",
|
||||
"password": "secret"
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
let resolved_type = explain_database_type(&config);
|
||||
assert_eq!(resolved_type, expected_type, "{raw_type:?} + {driver_profile:?}");
|
||||
let explain = build_explain_sql(ExplainSqlOptions {
|
||||
database_type: Some(resolved_type),
|
||||
format: None,
|
||||
analyze: None,
|
||||
sql: "SELECT 1".to_string(),
|
||||
});
|
||||
assert_eq!(explain.sql.as_deref(), Some(expected_sql), "{raw_type:?} + {driver_profile:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infers_only_oracle_custom_jdbc_for_oracle_explain_safety() {
|
||||
let oracle: ConnectionConfig = serde_json::from_value(serde_json::json!({
|
||||
|
||||
@@ -851,4 +851,17 @@ mod tests {
|
||||
unsupported_dialect_message(DatabaseType::Redis)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn capabilities_report_doris_for_the_mysql_doris_profile() {
|
||||
let mut doris = config(DatabaseType::Mysql, 30);
|
||||
doris.driver_profile = Some("doris".to_string());
|
||||
let (state, _dir) = saved_connection_state(std::slice::from_ref(&doris)).await;
|
||||
open_connection(&state, &doris.id).await;
|
||||
|
||||
let capabilities = plugin_plan_capabilities(&state, &doris.id).await.unwrap();
|
||||
let capabilities = serde_json::to_value(capabilities).unwrap();
|
||||
assert_eq!(capabilities["dbType"], "doris");
|
||||
assert!(capabilities["supports"]["estimatedPlan"].as_bool().unwrap_or_default());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user