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
38 changes: 0 additions & 38 deletions datafusion/src/execution/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
60 changes: 60 additions & 0 deletions datafusion/tests/sql/explain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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, Field, Schema};
use datafusion::{
logical_plan::{LogicalPlan, LogicalPlanBuilder, 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);
}
}
1 change: 1 addition & 0 deletions datafusion/tests/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ 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;
Expand Down