use std::{
any::Any,
fmt::{self, Debug},
sync::Arc,
};
use crate::logical_plan::plan::Extension;
use crate::logical_plan::{DFSchemaRef, Expr, LogicalPlan, UserDefinedLogicalNode};
pub fn new(input: LogicalPlan) -> LogicalPlan {
let node = Arc::new(TestUserDefinedPlanNode { input });
LogicalPlan::Extension(Extension { node })
}
struct TestUserDefinedPlanNode {
input: LogicalPlan,
}
impl Debug for TestUserDefinedPlanNode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.fmt_for_explain(f)
}
}
impl UserDefinedLogicalNode for TestUserDefinedPlanNode {
fn as_any(&self) -> &dyn Any {
self
}
fn inputs(&self) -> Vec<&LogicalPlan> {
vec![&self.input]
}
fn schema(&self) -> &DFSchemaRef {
self.input.schema()
}
fn expressions(&self) -> Vec<Expr> {
vec![]
}
fn fmt_for_explain(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "TestUserDefined")
}
fn from_template(
&self,
exprs: &[Expr],
inputs: &[LogicalPlan],
) -> Arc<dyn UserDefinedLogicalNode + Send + Sync> {
assert_eq!(inputs.len(), 1, "input size inconsistent");
assert_eq!(exprs.len(), 0, "expression size inconsistent");
Arc::new(TestUserDefinedPlanNode {
input: inputs[0].clone(),
})
}
}