Skip to content

Commit

Permalink
union adding arc (#2868)
Browse files Browse the repository at this point in the history
  • Loading branch information
comphead authored Jul 11, 2022
1 parent f769c33 commit a1a6976
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
20 changes: 13 additions & 7 deletions datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ pub fn union_with_alias(
.into_iter()
.flat_map(|p| match p {
LogicalPlan::Union(Union { inputs, .. }) => inputs,
x => vec![x],
x => vec![Arc::new(x)],
});

inputs_iter
Expand All @@ -916,16 +916,22 @@ pub fn union_with_alias(
})?;

let inputs = inputs_iter
.map(|p| match p {
.map(|p| match p.as_ref() {
LogicalPlan::Projection(Projection {
expr, input, alias, ..
}) => {
project_with_column_index_alias(expr, input, union_schema.clone(), alias)
.unwrap()
}
x => x,
}) => Arc::new(
project_with_column_index_alias(
expr.to_vec(),
input.clone(),
union_schema.clone(),
alias.clone(),
)
.unwrap(),
),
x => Arc::new(x.clone()),
})
.collect::<Vec<_>>();

if inputs.is_empty() {
return Err(DataFusionError::Plan("Empty UNION".to_string()));
}
Expand Down
6 changes: 4 additions & 2 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ impl LogicalPlan {
LogicalPlan::Subquery(Subquery { subquery, .. }) => vec![subquery],
LogicalPlan::SubqueryAlias(SubqueryAlias { input, .. }) => vec![input],
LogicalPlan::Extension(extension) => extension.node.inputs(),
LogicalPlan::Union(Union { inputs, .. }) => inputs.iter().collect(),
LogicalPlan::Union(Union { inputs, .. }) => {
inputs.iter().map(|arc| arc.as_ref()).collect()
}
LogicalPlan::Distinct(Distinct { input }) => vec![input],
LogicalPlan::Explain(explain) => vec![&explain.plan],
LogicalPlan::Analyze(analyze) => vec![&analyze.input],
Expand Down Expand Up @@ -1072,7 +1074,7 @@ pub struct Repartition {
#[derive(Clone)]
pub struct Union {
/// Inputs to merge
pub inputs: Vec<LogicalPlan>,
pub inputs: Vec<Arc<LogicalPlan>>,
/// Union schema. Should be the same for all inputs.
pub schema: DFSchemaRef,
/// Union output relation alias
Expand Down
2 changes: 1 addition & 1 deletion datafusion/expr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ pub fn from_plan(
})),
LogicalPlan::Union(Union { schema, alias, .. }) => {
Ok(LogicalPlan::Union(Union {
inputs: inputs.to_vec(),
inputs: inputs.iter().cloned().map(Arc::new).collect(),
schema: schema.clone(),
alias: alias.clone(),
}))
Expand Down
4 changes: 2 additions & 2 deletions datafusion/optimizer/src/limit_push_down.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn limit_push_down(
let new_inputs = inputs
.iter()
.map(|x| {
Ok(LogicalPlan::Limit(Limit {
Ok(Arc::new(LogicalPlan::Limit(Limit {
skip: None,
fetch: Some(ancestor_fetch),
input: Arc::new(limit_push_down(
Expand All @@ -204,7 +204,7 @@ fn limit_push_down(
x,
_optimizer_config,
)?),
}))
})))
})
.collect::<Result<_>>()?;
Ok(LogicalPlan::Union(Union {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/optimizer/src/projection_push_down.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ fn optimize_plan(
schema.metadata().clone(),
)?;
Ok(LogicalPlan::Union(Union {
inputs: new_inputs,
inputs: new_inputs.iter().cloned().map(Arc::new).collect(),
schema: Arc::new(new_schema),
alias: alias.clone(),
}))
Expand Down

0 comments on commit a1a6976

Please sign in to comment.