From d8fbeb3d4108bdd4beb1af8624a9d559df6fa732 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Thu, 3 Feb 2022 16:46:23 -0500 Subject: [PATCH 1/2] Move optimize test out of context.rs --- datafusion/src/execution/context.rs | 38 ------------------- datafusion/tests/sql/explain.rs | 58 +++++++++++++++++++++++++++++ datafusion/tests/sql/mod.rs | 1 + 3 files changed, 59 insertions(+), 38 deletions(-) create mode 100644 datafusion/tests/sql/explain.rs diff --git a/datafusion/src/execution/context.rs b/datafusion/src/execution/context.rs index deec84d5a0ff8..fb271a1a7e568 100644 --- a/datafusion/src/execution/context.rs +++ b/datafusion/src/execution/context.rs @@ -1347,44 +1347,6 @@ mod tests { )); } - #[test] - fn optimize_explain() { - let schema = Schema::new(vec![Field::new("id", DataType::Int32, false)]); - - let plan = LogicalPlanBuilder::scan_empty(Some("employee"), &schema, None) - .unwrap() - .explain(true, false) - .unwrap() - .build() - .unwrap(); - - if let LogicalPlan::Explain(e) = &plan { - assert_eq!(e.stringified_plans.len(), 1); - } else { - panic!("plan was not an explain: {:?}", plan); - } - - // now optimize the plan and expect to see more plans - let optimized_plan = ExecutionContext::new().optimize(&plan).unwrap(); - if let LogicalPlan::Explain(e) = &optimized_plan { - // should have more than one plan - assert!( - e.stringified_plans.len() > 1, - "plans: {:#?}", - e.stringified_plans - ); - // should have at least one optimized plan - let opt = e - .stringified_plans - .iter() - .any(|p| matches!(p.plan_type, PlanType::OptimizedLogicalPlan { .. })); - - assert!(opt, "plans: {:#?}", e.stringified_plans); - } else { - panic!("plan was not an explain: {:?}", plan); - } - } - #[tokio::test] async fn parallel_projection() -> Result<()> { let partition_count = 4; diff --git a/datafusion/tests/sql/explain.rs b/datafusion/tests/sql/explain.rs new file mode 100644 index 0000000000000..b3fa75e77efb0 --- /dev/null +++ b/datafusion/tests/sql/explain.rs @@ -0,0 +1,58 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use arrow::datatypes::{DataType, Schema, Field}; +use datafusion::{logical_plan::{LogicalPlanBuilder, LogicalPlan, PlanType}, prelude::ExecutionContext}; + + +#[test] +fn optimize_explain() { + let schema = Schema::new(vec![Field::new("id", DataType::Int32, false)]); + + let plan = LogicalPlanBuilder::scan_empty(Some("employee"), &schema, None) + .unwrap() + .explain(true, false) + .unwrap() + .build() + .unwrap(); + + if let LogicalPlan::Explain(e) = &plan { + assert_eq!(e.stringified_plans.len(), 1); + } else { + panic!("plan was not an explain: {:?}", plan); + } + + // now optimize the plan and expect to see more plans + let optimized_plan = ExecutionContext::new().optimize(&plan).unwrap(); + if let LogicalPlan::Explain(e) = &optimized_plan { + // should have more than one plan + assert!( + e.stringified_plans.len() > 1, + "plans: {:#?}", + e.stringified_plans + ); + // should have at least one optimized plan + let opt = e + .stringified_plans + .iter() + .any(|p| matches!(p.plan_type, PlanType::OptimizedLogicalPlan { .. })); + + assert!(opt, "plans: {:#?}", e.stringified_plans); + } else { + panic!("plan was not an explain: {:?}", plan); + } +} diff --git a/datafusion/tests/sql/mod.rs b/datafusion/tests/sql/mod.rs index ea6829969462c..1e3f910309f13 100644 --- a/datafusion/tests/sql/mod.rs +++ b/datafusion/tests/sql/mod.rs @@ -99,6 +99,7 @@ pub mod window; pub mod information_schema; #[cfg_attr(not(feature = "unicode_expressions"), ignore)] pub mod unicode; +mod explain; fn assert_float_eq(expected: &[Vec], received: &[Vec]) where From 24d998a65c3a0ac11add309a66e707591de738c9 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Thu, 3 Feb 2022 16:46:34 -0500 Subject: [PATCH 2/2] Update --- datafusion/tests/sql/explain.rs | 8 +++++--- datafusion/tests/sql/mod.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/datafusion/tests/sql/explain.rs b/datafusion/tests/sql/explain.rs index b3fa75e77efb0..00842b5eb8abf 100644 --- a/datafusion/tests/sql/explain.rs +++ b/datafusion/tests/sql/explain.rs @@ -15,9 +15,11 @@ // specific language governing permissions and limitations // under the License. -use arrow::datatypes::{DataType, Schema, Field}; -use datafusion::{logical_plan::{LogicalPlanBuilder, LogicalPlan, PlanType}, prelude::ExecutionContext}; - +use arrow::datatypes::{DataType, Field, Schema}; +use datafusion::{ + logical_plan::{LogicalPlan, LogicalPlanBuilder, PlanType}, + prelude::ExecutionContext, +}; #[test] fn optimize_explain() { diff --git a/datafusion/tests/sql/mod.rs b/datafusion/tests/sql/mod.rs index 1e3f910309f13..95623d45e467d 100644 --- a/datafusion/tests/sql/mod.rs +++ b/datafusion/tests/sql/mod.rs @@ -96,10 +96,10 @@ pub mod udf; pub mod union; pub mod window; +mod explain; pub mod information_schema; #[cfg_attr(not(feature = "unicode_expressions"), ignore)] pub mod unicode; -mod explain; fn assert_float_eq(expected: &[Vec], received: &[Vec]) where