Skip to content

Commit 619eb90

Browse files
authored
feat(cubestore): Support EXPLAIN for meta queries (#9876)
1 parent b238a29 commit 619eb90

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::queryplanner::serialized_plan::{IndexSnapshot, RowRange};
3030
use crate::queryplanner::tail_limit::TailLimitExec;
3131
use crate::queryplanner::topk::ClusterAggregateTopK;
3232
use crate::queryplanner::topk::{AggregateTopKExec, SortColumn};
33-
use crate::queryplanner::CubeTableLogical;
33+
use crate::queryplanner::{CubeTableLogical, InfoSchemaTableProvider};
3434
use datafusion::cube_ext::join::CrossJoinExec;
3535
use datafusion::cube_ext::joinagg::CrossJoinAggExec;
3636
use datafusion::cube_ext::rolling::RollingWindowAggExec;
@@ -257,6 +257,12 @@ 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
261+
.as_any()
262+
.downcast_ref::<InfoSchemaTableProvider>()
263+
.is_some()
264+
{
265+
"InfoSchemaTableProvider".to_string()
260266
} else {
261267
panic!("unknown table provider");
262268
}

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

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,23 @@ impl SqlServiceImpl {
461461
};
462462
Ok(res)
463463
}
464-
_ => Err(CubeError::user(
465-
"Explain not supported for selects from system tables".to_string(),
466-
)),
464+
QueryPlan::Meta(logical_plan) => {
465+
if !analyze {
466+
Ok(DataFrame::new(
467+
vec![Column::new(
468+
"logical plan".to_string(),
469+
ColumnType::String,
470+
0,
471+
)],
472+
vec![Row::new(vec![TableValue::String(pp_plan(&logical_plan))])],
473+
))
474+
} else {
475+
Err(CubeError::user(
476+
"EXPLAIN ANALYZE is not supported for selects from system tables"
477+
.to_string(),
478+
))
479+
}
480+
}
467481
}?;
468482
Ok(Arc::new(res))
469483
}
@@ -3834,6 +3848,33 @@ mod tests {
38343848
)
38353849
}
38363850

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+
38373878
#[tokio::test]
38383879
async fn explain_logical_plan() {
38393880
Config::run_test("explain_logical_plan", async move |services| {
@@ -3868,6 +3909,7 @@ mod tests {
38683909
);
38693910
}).await;
38703911
}
3912+
38713913
#[tokio::test]
38723914
async fn explain_physical_plan() {
38733915
Config::test("explain_analyze_router").update_config(|mut config| {
@@ -3878,7 +3920,7 @@ mod tests {
38783920
}).start_test(async move |services| {
38793921
let service = services.sql_service;
38803922

3881-
Config::test("expalain_analyze_worker_1").update_config(|mut config| {
3923+
Config::test("explain_analyze_worker_1").update_config(|mut config| {
38823924
config.worker_bind_address = Some("127.0.0.1:14006".to_string());
38833925
config.server_name = "127.0.0.1:14006".to_string();
38843926
config.metastore_remote_address = Some("127.0.0.1:15006".to_string());

0 commit comments

Comments
 (0)