Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::queryplanner::serialized_plan::{IndexSnapshot, RowRange};
use crate::queryplanner::tail_limit::TailLimitExec;
use crate::queryplanner::topk::ClusterAggregateTopK;
use crate::queryplanner::topk::{AggregateTopKExec, SortColumn};
use crate::queryplanner::CubeTableLogical;
use crate::queryplanner::{CubeTableLogical, InfoSchemaTableProvider};
use datafusion::cube_ext::join::CrossJoinExec;
use datafusion::cube_ext::joinagg::CrossJoinAggExec;
use datafusion::cube_ext::rolling::RollingWindowAggExec;
Expand Down Expand Up @@ -257,6 +257,12 @@ fn pp_source(t: &dyn TableProvider) -> String {
format!("CubeTable(index: {})", pp_index(t.index_snapshot()))
} else if let Some(t) = t.as_any().downcast_ref::<InlineTableProvider>() {
format!("InlineTableProvider(data: {} rows)", t.get_data().len())
} else if t
.as_any()
.downcast_ref::<InfoSchemaTableProvider>()
.is_some()
{
"InfoSchemaTableProvider".to_string()
} else {
panic!("unknown table provider");
}
Expand Down
50 changes: 46 additions & 4 deletions rust/cubestore/cubestore/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,23 @@ impl SqlServiceImpl {
};
Ok(res)
}
_ => Err(CubeError::user(
"Explain not supported for selects from system tables".to_string(),
)),
QueryPlan::Meta(logical_plan) => {
if !analyze {
Ok(DataFrame::new(
vec![Column::new(
"logical plan".to_string(),
ColumnType::String,
0,
)],
vec![Row::new(vec![TableValue::String(pp_plan(&logical_plan))])],
))
} else {
Err(CubeError::user(
"EXPLAIN ANALYZE is not supported for selects from system tables"
.to_string(),
))
}
}
}?;
Ok(Arc::new(res))
}
Expand Down Expand Up @@ -3834,6 +3848,33 @@ mod tests {
)
}

#[tokio::test]
async fn explain_meta_logical_plan() {
Config::run_test("explain_meta_logical_plan", async move |services| {
let service = services.sql_service;
service.exec_query("CREATE SCHEMA foo").await.unwrap();

let result = service.exec_query(
"EXPLAIN SELECT table_name FROM information_schema.tables WHERE table_schema = 'foo'"
).await.unwrap();
assert_eq!(result.len(), 1);
assert_eq!(result.get_columns().len(), 1);

let pp_plan = match &result
.get_rows()[0]
.values()[0] {
TableValue::String(pp_plan) => pp_plan,
_ => {assert!(false); ""}
};
assert_eq!(
pp_plan,
"Projection, [information_schema.tables.table_name]\
\n Filter\
\n Scan information_schema.tables, source: InfoSchemaTableProvider, fields: [table_schema, table_name]"
);
}).await;
}

#[tokio::test]
async fn explain_logical_plan() {
Config::run_test("explain_logical_plan", async move |services| {
Expand Down Expand Up @@ -3868,6 +3909,7 @@ mod tests {
);
}).await;
}

#[tokio::test]
async fn explain_physical_plan() {
Config::test("explain_analyze_router").update_config(|mut config| {
Expand All @@ -3878,7 +3920,7 @@ mod tests {
}).start_test(async move |services| {
let service = services.sql_service;

Config::test("expalain_analyze_worker_1").update_config(|mut config| {
Config::test("explain_analyze_worker_1").update_config(|mut config| {
config.worker_bind_address = Some("127.0.0.1:14006".to_string());
config.server_name = "127.0.0.1:14006".to_string();
config.metastore_remote_address = Some("127.0.0.1:15006".to_string());
Expand Down
Loading