|
17 | 17 |
|
18 | 18 | //! This module defines the interface for logical nodes |
19 | 19 | use crate::{Expr, LogicalPlan}; |
20 | | -use datafusion_common::{DFSchema, DFSchemaRef}; |
| 20 | +use datafusion_common::{DFSchema, DFSchemaRef, Result}; |
21 | 21 | use std::hash::{Hash, Hasher}; |
22 | 22 | use std::{any::Any, collections::HashSet, fmt, sync::Arc}; |
23 | 23 |
|
@@ -76,27 +76,31 @@ pub trait UserDefinedLogicalNode: fmt::Debug + Send + Sync { |
76 | 76 | /// For example: `TopK: k=10` |
77 | 77 | fn fmt_for_explain(&self, f: &mut fmt::Formatter) -> fmt::Result; |
78 | 78 |
|
79 | | - /// Create a new `ExtensionPlanNode` with the specified children |
| 79 | + #[deprecated(since = "39.0.0", note = "use with_exprs_and_inputs instead")] |
| 80 | + #[allow(clippy::wrong_self_convention)] |
| 81 | + fn from_template( |
| 82 | + &self, |
| 83 | + exprs: &[Expr], |
| 84 | + inputs: &[LogicalPlan], |
| 85 | + ) -> Arc<dyn UserDefinedLogicalNode> { |
| 86 | + self.with_exprs_and_inputs(exprs.to_vec(), inputs.to_vec()) |
| 87 | + .unwrap() |
| 88 | + } |
| 89 | + |
| 90 | + /// Create a new `UserDefinedLogicalNode` with the specified children |
80 | 91 | /// and expressions. This function is used during optimization |
81 | 92 | /// when the plan is being rewritten and a new instance of the |
82 | | - /// `ExtensionPlanNode` must be created. |
| 93 | + /// `UserDefinedLogicalNode` must be created. |
83 | 94 | /// |
84 | 95 | /// Note that exprs and inputs are in the same order as the result |
85 | 96 | /// of self.inputs and self.exprs. |
86 | 97 | /// |
87 | | - /// So, `self.from_template(exprs, ..).expressions() == exprs |
88 | | - // |
89 | | - // TODO(clippy): This should probably be renamed to use a `with_*` prefix. Something |
90 | | - // like `with_template`, or `with_exprs_and_inputs`. |
91 | | - // |
92 | | - // Also, I think `ExtensionPlanNode` has been renamed to `UserDefinedLogicalNode` |
93 | | - // but the doc comments have not been updated. |
94 | | - #[allow(clippy::wrong_self_convention)] |
95 | | - fn from_template( |
| 98 | + /// So, `self.with_exprs_and_inputs(exprs, ..).expressions() == exprs |
| 99 | + fn with_exprs_and_inputs( |
96 | 100 | &self, |
97 | | - exprs: &[Expr], |
98 | | - inputs: &[LogicalPlan], |
99 | | - ) -> Arc<dyn UserDefinedLogicalNode>; |
| 101 | + exprs: Vec<Expr>, |
| 102 | + inputs: Vec<LogicalPlan>, |
| 103 | + ) -> Result<Arc<dyn UserDefinedLogicalNode>>; |
100 | 104 |
|
101 | 105 | /// Returns the necessary input columns for this node required to compute |
102 | 106 | /// the columns in the output schema |
@@ -312,12 +316,12 @@ impl<T: UserDefinedLogicalNodeCore> UserDefinedLogicalNode for T { |
312 | 316 | self.fmt_for_explain(f) |
313 | 317 | } |
314 | 318 |
|
315 | | - fn from_template( |
| 319 | + fn with_exprs_and_inputs( |
316 | 320 | &self, |
317 | | - exprs: &[Expr], |
318 | | - inputs: &[LogicalPlan], |
319 | | - ) -> Arc<dyn UserDefinedLogicalNode> { |
320 | | - Arc::new(self.from_template(exprs, inputs)) |
| 321 | + exprs: Vec<Expr>, |
| 322 | + inputs: Vec<LogicalPlan>, |
| 323 | + ) -> Result<Arc<dyn UserDefinedLogicalNode>> { |
| 324 | + Ok(Arc::new(self.from_template(&exprs, &inputs))) |
321 | 325 | } |
322 | 326 |
|
323 | 327 | fn necessary_children_exprs( |
|
0 commit comments