Skip to content

Commit 4e9e392

Browse files
committed
feat(cubestore): Support EXPLAIN for meta queries
1 parent 3968a07 commit 4e9e392

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

rust/cubestore/cubestore/src/queryplanner/pretty_printers.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ fn pp_source(t: &dyn TableProvider) -> String {
257257
format!("CubeTable(index: {})", pp_index(t.index_snapshot()))
258258
} else if let Some(t) = t.as_any().downcast_ref::<InlineTableProvider>() {
259259
format!("InlineTableProvider(data: {} rows)", t.get_data().len())
260-
} else if t.as_any().downcast_ref::<InfoSchemaTableProvider>().is_some() {
260+
} else if t
261+
.as_any()
262+
.downcast_ref::<InfoSchemaTableProvider>()
263+
.is_some()
264+
{
261265
"InfoSchemaTableProvider".to_string()
262266
} else {
263267
panic!("unknown table provider");

rust/cubestore/cubestore/src/sql/mod.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ impl SqlServiceImpl {
473473
))
474474
} else {
475475
Err(CubeError::user(
476-
"EXPLAIN ANALYZE is not supported for selects from system tables".to_string(),
476+
"EXPLAIN ANALYZE is not supported for selects from system tables"
477+
.to_string(),
477478
))
478479
}
479480
}
@@ -3847,6 +3848,33 @@ mod tests {
38473848
)
38483849
}
38493850

3851+
#[tokio::test]
3852+
async fn explain_meta_logical_plan() {
3853+
Config::run_test("explain_meta_logical_plan", async move |services| {
3854+
let service = services.sql_service;
3855+
service.exec_query("CREATE SCHEMA foo").await.unwrap();
3856+
3857+
let result = service.exec_query(
3858+
"EXPLAIN SELECT table_name FROM information_schema.tables WHERE table_schema = 'foo'"
3859+
).await.unwrap();
3860+
assert_eq!(result.len(), 1);
3861+
assert_eq!(result.get_columns().len(), 1);
3862+
3863+
let pp_plan = match &result
3864+
.get_rows()[0]
3865+
.values()[0] {
3866+
TableValue::String(pp_plan) => pp_plan,
3867+
_ => {assert!(false); ""}
3868+
};
3869+
assert_eq!(
3870+
pp_plan,
3871+
"Projection, [information_schema.tables.table_name]\
3872+
\n Filter\
3873+
\n Scan information_schema.tables, source: InfoSchemaTableProvider, fields: [table_schema, table_name]"
3874+
);
3875+
}).await;
3876+
}
3877+
38503878
#[tokio::test]
38513879
async fn explain_logical_plan() {
38523880
Config::run_test("explain_logical_plan", async move |services| {
@@ -3881,6 +3909,7 @@ mod tests {
38813909
);
38823910
}).await;
38833911
}
3912+
38843913
#[tokio::test]
38853914
async fn explain_physical_plan() {
38863915
Config::test("explain_analyze_router").update_config(|mut config| {
@@ -3891,7 +3920,7 @@ mod tests {
38913920
}).start_test(async move |services| {
38923921
let service = services.sql_service;
38933922

3894-
Config::test("expalain_analyze_worker_1").update_config(|mut config| {
3923+
Config::test("explain_analyze_worker_1").update_config(|mut config| {
38953924
config.worker_bind_address = Some("127.0.0.1:14006".to_string());
38963925
config.server_name = "127.0.0.1:14006".to_string();
38973926
config.metastore_remote_address = Some("127.0.0.1:15006".to_string());

0 commit comments

Comments
 (0)