@@ -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