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
2 changes: 1 addition & 1 deletion datafusion/proto/src/physical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub trait PhysicalPlanNodeExt: Sized {
proto_converter: &dyn PhysicalProtoConverterExtension,
) -> Result<protobuf::PhysicalPlanNode> {
let plan_clone = Arc::clone(&plan);
let plan = plan.as_ref() as &dyn Any;
let plan = plan.as_ref();

if let Some(exec) = plan.downcast_ref::<ExplainExec>() {
return protobuf::PhysicalPlanNode::try_from_explain_exec(exec, codec);
Expand Down
72 changes: 70 additions & 2 deletions datafusion/proto/tests/cases/roundtrip_physical_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ use datafusion::physical_plan::windows::{
};
use datafusion::physical_plan::{
DisplayAs, DisplayFormatType, ExecutionPlan, InputOrderMode, Partitioning,
PhysicalExpr, RangePartitioning, SendableRecordBatchStream, SplitPoint, Statistics,
displayable,
PhysicalExpr, PlanProperties, RangePartitioning, SendableRecordBatchStream,
SplitPoint, Statistics, displayable,
};
use datafusion::prelude::{ParquetReadOptions, SessionContext};
use datafusion::scalar::ScalarValue;
Expand Down Expand Up @@ -229,6 +229,74 @@ fn roundtrip_empty() -> Result<()> {
roundtrip_test(Arc::new(EmptyExec::new(Arc::new(Schema::empty()))))
}

#[derive(Debug)]
struct DowncastDelegatingExec {
inner: Arc<dyn ExecutionPlan>,
}

impl DowncastDelegatingExec {
fn new(inner: Arc<dyn ExecutionPlan>) -> Self {
Self { inner }
}
}

impl DisplayAs for DowncastDelegatingExec {
fn fmt_as(&self, t: DisplayFormatType, f: &mut Formatter) -> std::fmt::Result {
self.inner.fmt_as(t, f)
}
}

impl ExecutionPlan for DowncastDelegatingExec {
fn name(&self) -> &str {
self.inner.name()
}

fn properties(&self) -> &Arc<PlanProperties> {
self.inner.properties()
}

fn children(&self) -> Vec<&Arc<dyn ExecutionPlan>> {
self.inner.children()
}

fn with_new_children(
self: Arc<Self>,
children: Vec<Arc<dyn ExecutionPlan>>,
) -> Result<Arc<dyn ExecutionPlan>> {
let inner = Arc::clone(&self.inner).with_new_children(children)?;
Ok(Arc::new(Self::new(inner)))
}

fn downcast_delegate(&self) -> Option<&dyn ExecutionPlan> {
Some(self.inner.as_ref())
}

fn execute(
&self,
partition: usize,
context: Arc<TaskContext>,
) -> Result<SendableRecordBatchStream> {
self.inner.execute(partition, context)
}
}

#[test]
fn serialize_uses_downcast_delegate() -> Result<()> {
let inner: Arc<dyn ExecutionPlan> =
Arc::new(EmptyExec::new(Arc::new(Schema::empty())));
let plan: Arc<dyn ExecutionPlan> = Arc::new(DowncastDelegatingExec::new(inner));
let codec = DefaultPhysicalExtensionCodec {};

let proto = PhysicalPlanNode::try_from_physical_plan(plan, &codec)?;

assert!(matches!(
proto.physical_plan_type,
Some(protobuf::physical_plan_node::PhysicalPlanType::Empty(_))
));

Ok(())
}

#[test]
fn roundtrip_date_time_interval() -> Result<()> {
let schema = Schema::new(vec![
Expand Down
Loading