findepi commented on code in PR #17675:
URL: https://github.com/apache/datafusion/pull/17675#discussion_r2382983761
##########
datafusion/expr/src/expr_rewriter/mod.rs:
##########
@@ -214,26 +214,29 @@ pub fn strip_outer_reference(expr: Expr) -> Expr {
/// Returns plan with expressions coerced to types compatible with
/// schema types
pub fn coerce_plan_expr_for_schema(
- plan: LogicalPlan,
+ plan: Arc<LogicalPlan>,
schema: &DFSchema,
-) -> Result<LogicalPlan> {
- match plan {
+) -> Result<Arc<LogicalPlan>> {
+ if matches!(plan.as_ref(), LogicalPlan::Projection(_)) {
// special case Projection to avoid adding multiple projections
- LogicalPlan::Projection(Projection { expr, input, .. }) => {
- let new_exprs = coerce_exprs_for_schema(expr, input.schema(),
schema)?;
- let projection = Projection::try_new(new_exprs, input)?;
- Ok(LogicalPlan::Projection(projection))
- }
- _ => {
- let exprs: Vec<Expr> =
plan.schema().iter().map(Expr::from).collect();
- let new_exprs = coerce_exprs_for_schema(exprs, plan.schema(),
schema)?;
- let add_project = new_exprs.iter().any(|expr|
expr.try_as_col().is_none());
- if add_project {
- let projection = Projection::try_new(new_exprs,
Arc::new(plan))?;
- Ok(LogicalPlan::Projection(projection))
- } else {
- Ok(plan)
- }
+ let LogicalPlan::Projection(Projection { expr, input, .. }) =
+ Arc::unwrap_or_clone(plan)
+ else {
+ unreachable!()
+ };
Review Comment:
The matching here became more complicated. Is this worth it?
##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -412,14 +416,14 @@ impl LogicalPlanBuilder {
/// Create a [CopyTo] for copying the contents of this builder to the
specified file(s)
pub fn copy_to(
- input: LogicalPlan,
+ input: impl Into<Arc<LogicalPlan>>,
Review Comment:
can it be just `Arc<LogicalPlan>`?
##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -175,7 +177,7 @@ impl LogicalPlanBuilder {
pub fn to_recursive_query(
self,
name: String,
- recursive_term: LogicalPlan,
+ recursive_term: impl Into<Arc<LogicalPlan>>,
Review Comment:
would just `Arc<LogicalPlan>` work?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]