Skip to content

Apache DataFusion SQL Query Engine

rm clone (#11532)

Jay Zhan4dd8532e6cd5
diff --git a/datafusion/optimizer/src/push_down_filter.rs b/datafusion/optimizer/src/push_down_filter.rs
index 33b2883d6e..a22f2e83e2 100644
--- a/datafusion/optimizer/src/push_down_filter.rs
+++ b/datafusion/optimizer/src/push_down_filter.rs
@@ -1020,7 +1020,7 @@ impl OptimizerRule for PushDownFilter {
/// ```
fn rewrite_projection(
predicates: Vec<Expr>,
- projection: Projection,
+ mut projection: Projection,
) -> Result<(Transformed<LogicalPlan>, Option<Expr>)> {
// A projection is filter-commutable if it do not contain volatile predicates or contain volatile
// predicates that are not used in the filter. However, we should re-writes all predicate expressions.
@@ -1053,11 +1053,13 @@ fn rewrite_projection(
// E.g. in `Filter: b\n Projection: a > 1 as b`, we can swap them, but the filter must be "a > 1"
let new_filter = LogicalPlan::Filter(Filter::try_new(
replace_cols_by_name(expr, &non_volatile_map)?,
- Arc::clone(&projection.input),
+ std::mem::take(&mut projection.input),
)?);
+ projection.input = Arc::new(new_filter);
+
Ok((
- insert_below(LogicalPlan::Projection(projection), new_filter)?,
+ Transformed::yes(LogicalPlan::Projection(projection)),
conjunction(keep_predicates),
))
}