Skip to content
Merged
Changes from 4 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
29 changes: 27 additions & 2 deletions datafusion/optimizer/src/eliminate_nested_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{OptimizerConfig, OptimizerRule};
use datafusion_common::tree_node::Transformed;
use datafusion_common::Result;
use datafusion_expr::expr_rewriter::coerce_plan_expr_for_schema;
use datafusion_expr::{Distinct, LogicalPlan, Union};
use datafusion_expr::{Distinct, LogicalPlan, Projection, Union};
use itertools::Itertools;
use std::sync::Arc;

Expand Down Expand Up @@ -54,7 +54,7 @@ impl OptimizerRule for EliminateNestedUnion {
plan: LogicalPlan,
_config: &dyn OptimizerConfig,
) -> Result<Transformed<LogicalPlan>> {
match plan {
match plan.clone() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you add this clone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover from something I was trying earlier, I thought clippy catches this stuff ...

LogicalPlan::Union(Union { inputs, schema }) => {
let inputs = inputs
.into_iter()
Expand Down Expand Up @@ -100,6 +100,31 @@ fn extract_plans_from_union(plan: Arc<LogicalPlan>) -> Vec<LogicalPlan> {
.into_iter()
.map(Arc::unwrap_or_clone)
.collect::<Vec<_>>(),
LogicalPlan::Projection(Projection {
expr,
input,
schema,
..
}) => match Arc::unwrap_or_clone(input) {
LogicalPlan::Union(Union { inputs, .. }) => inputs
.into_iter()
.map(Arc::unwrap_or_clone)
.map(|plan| {
LogicalPlan::Projection(
Projection::try_new_with_schema(
expr.clone(),
Arc::new(plan.clone()),
Arc::clone(&schema),
)
.unwrap(),
)
})
.collect::<Vec<_>>(),

plan => vec![LogicalPlan::Projection(
Projection::try_new_with_schema(expr, Arc::new(plan), schema).unwrap(),
)],
},
plan => vec![plan],
}
}
Expand Down
Loading