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
12 changes: 12 additions & 0 deletions datafusion/expr/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@ impl LogicalPlanBuilder {
Ok(Self::from(union_with_alias(self.plan.clone(), plan, None)?))
}

pub fn union_with_alias(
&self,
plan: LogicalPlan,
alias: Option<String>,
) -> Result<Self> {
Ok(Self::from(union_with_alias(
self.plan.clone(),
plan,
alias,
)?))
}

/// Apply a union, removing duplicate rows
pub fn union_distinct(&self, plan: LogicalPlan) -> Result<Self> {
// unwrap top-level Distincts, to avoid duplication
Expand Down
20 changes: 20 additions & 0 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,26 @@ impl Projection {
})
}

/// Create a new Projection using the specified output schema
pub fn new_from_schema(
input: Arc<LogicalPlan>,
schema: DFSchemaRef,
alias: Option<String>,
) -> Self {
let expr: Vec<Expr> = schema
.fields()
.iter()
.map(|field| field.qualified_column())
.map(Expr::Column)
.collect();
Self {
expr,
input,
schema,
alias,
}
}

pub fn try_from_plan(plan: &LogicalPlan) -> datafusion_common::Result<&Projection> {
match plan {
LogicalPlan::Projection(it) => Ok(it),
Expand Down
1 change: 1 addition & 0 deletions datafusion/optimizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod inline_table_scan;
pub mod limit_push_down;
pub mod optimizer;
pub mod projection_push_down;
pub mod propagate_empty_relation;
pub mod reduce_cross_join;
pub mod reduce_outer_join;
pub mod scalar_subquery_to_join;
Expand Down
2 changes: 2 additions & 0 deletions datafusion/optimizer/src/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::filter_push_down::FilterPushDown;
use crate::inline_table_scan::InlineTableScan;
use crate::limit_push_down::LimitPushDown;
use crate::projection_push_down::ProjectionPushDown;
use crate::propagate_empty_relation::PropagateEmptyRelation;
use crate::reduce_cross_join::ReduceCrossJoin;
use crate::reduce_outer_join::ReduceOuterJoin;
use crate::rewrite_disjunctive_predicate::RewriteDisjunctivePredicate;
Expand Down Expand Up @@ -165,6 +166,7 @@ impl Optimizer {
Arc::new(ReduceCrossJoin::new()),
Arc::new(CommonSubexprEliminate::new()),
Arc::new(EliminateLimit::new()),
Arc::new(PropagateEmptyRelation::new()),
Arc::new(RewriteDisjunctivePredicate::new()),
];
if config.filter_null_keys {
Expand Down
Loading