-
Notifications
You must be signed in to change notification settings - Fork 2.1k
proto: add proto converter reference to PhysicalExtensionCodec trait #21055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -275,6 +275,7 @@ impl PhysicalExtensionCodec for AdapterPreservingCodec { | |
| buf: &[u8], | ||
| inputs: &[Arc<dyn ExecutionPlan>], | ||
| _ctx: &TaskContext, | ||
| _proto_converter: &dyn PhysicalProtoConverterExtension, | ||
| ) -> Result<Arc<dyn ExecutionPlan>> { | ||
| // Try to parse as our extension payload | ||
| if let Ok(payload) = serde_json::from_slice::<ExtensionPayload>(buf) | ||
|
|
@@ -303,6 +304,7 @@ impl PhysicalExtensionCodec for AdapterPreservingCodec { | |
| &self, | ||
| _node: Arc<dyn ExecutionPlan>, | ||
| _buf: &mut Vec<u8>, | ||
| _proto_converter: &dyn PhysicalProtoConverterExtension, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming these |
||
| ) -> Result<()> { | ||
| // We don't need this for the example - adapter wrapping happens in | ||
| // `execution_plan_to_proto` instead. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,10 @@ use datafusion_expr::{ | |
| AggregateUDF, AggregateUDFImpl, ScalarUDF, ScalarUDFImpl, WindowUDF, WindowUDFImpl, | ||
| }; | ||
| use datafusion_physical_plan::ExecutionPlan; | ||
| use datafusion_proto::physical_plan::PhysicalExtensionCodec; | ||
| use datafusion_proto::physical_plan::{ | ||
| DefaultPhysicalProtoConverter, PhysicalExtensionCodec, | ||
| PhysicalProtoConverterExtension, | ||
| }; | ||
|
|
||
| use stabby::slice::Slice as SSlice; | ||
| use stabby::str::Str as SStr; | ||
|
|
@@ -145,8 +148,12 @@ unsafe extern "C" fn try_decode_fn_wrapper( | |
| .collect::<Result<Vec<_>>>(); | ||
| let inputs = sresult_return!(inputs); | ||
|
|
||
| let plan = | ||
| sresult_return!(codec.try_decode(buf.as_ref(), &inputs, task_ctx.as_ref())); | ||
| let plan = sresult_return!(codec.try_decode( | ||
| buf.as_ref(), | ||
| &inputs, | ||
| task_ctx.as_ref(), | ||
| &DefaultPhysicalProtoConverter {}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timsaucer not sure if you have any suggestions but I think this is fine. Generally we have not made any effort to make dynamic filters / expr deduplication work with plans that go through FFI. |
||
| )); | ||
|
|
||
| FFI_Result::Ok(FFI_ExecutionPlan::new(plan, runtime)) | ||
| } | ||
|
|
@@ -160,7 +167,11 @@ unsafe extern "C" fn try_encode_fn_wrapper( | |
| let plan: Arc<dyn ExecutionPlan> = sresult_return!((&node).try_into()); | ||
|
|
||
| let mut bytes = Vec::new(); | ||
| sresult_return!(codec.try_encode(plan, &mut bytes)); | ||
| sresult_return!(codec.try_encode( | ||
| plan, | ||
| &mut bytes, | ||
| &DefaultPhysicalProtoConverter {} | ||
| )); | ||
|
|
||
| FFI_Result::Ok(bytes.into_iter().collect()) | ||
| } | ||
|
|
@@ -335,6 +346,7 @@ impl PhysicalExtensionCodec for ForeignPhysicalExtensionCodec { | |
| buf: &[u8], | ||
| inputs: &[Arc<dyn ExecutionPlan>], | ||
| _ctx: &TaskContext, | ||
| _proto_converter: &dyn PhysicalProtoConverterExtension, | ||
| ) -> Result<Arc<dyn ExecutionPlan>> { | ||
| let inputs = inputs | ||
| .iter() | ||
|
|
@@ -348,7 +360,12 @@ impl PhysicalExtensionCodec for ForeignPhysicalExtensionCodec { | |
| Ok(plan) | ||
| } | ||
|
|
||
| fn try_encode(&self, node: Arc<dyn ExecutionPlan>, buf: &mut Vec<u8>) -> Result<()> { | ||
| fn try_encode( | ||
| &self, | ||
| node: Arc<dyn ExecutionPlan>, | ||
| buf: &mut Vec<u8>, | ||
| _proto_converter: &dyn PhysicalProtoConverterExtension, | ||
| ) -> Result<()> { | ||
| let plan = FFI_ExecutionPlan::new(node, None); | ||
| let bytes = df_result!(unsafe { (self.0.try_encode)(&self.0, plan) })?; | ||
|
|
||
|
|
@@ -426,7 +443,10 @@ pub(crate) mod tests { | |
| use datafusion_functions_aggregate::sum::Sum; | ||
| use datafusion_functions_window::rank::{Rank, RankType}; | ||
| use datafusion_physical_plan::ExecutionPlan; | ||
| use datafusion_proto::physical_plan::PhysicalExtensionCodec; | ||
| use datafusion_proto::physical_plan::{ | ||
| DefaultPhysicalProtoConverter, PhysicalExtensionCodec, | ||
| PhysicalProtoConverterExtension, | ||
| }; | ||
|
|
||
| use crate::execution_plan::tests::EmptyExec; | ||
| use crate::proto::physical_extension_codec::FFI_PhysicalExtensionCodec; | ||
|
|
@@ -449,6 +469,7 @@ pub(crate) mod tests { | |
| buf: &[u8], | ||
| _inputs: &[Arc<dyn ExecutionPlan>], | ||
| _ctx: &TaskContext, | ||
| _proto_converter: &dyn PhysicalProtoConverterExtension, | ||
| ) -> Result<Arc<dyn ExecutionPlan>> { | ||
| if buf[0] != Self::MAGIC_NUMBER { | ||
| return exec_err!( | ||
|
|
@@ -467,6 +488,7 @@ pub(crate) mod tests { | |
| &self, | ||
| node: Arc<dyn ExecutionPlan>, | ||
| buf: &mut Vec<u8>, | ||
| _proto_converter: &dyn PhysicalProtoConverterExtension, | ||
| ) -> Result<()> { | ||
| buf.push(Self::MAGIC_NUMBER); | ||
|
|
||
|
|
@@ -587,10 +609,18 @@ pub(crate) mod tests { | |
| let exec = create_test_exec(); | ||
| let input_execs = [create_test_exec()]; | ||
| let mut bytes = Vec::new(); | ||
| foreign_codec.try_encode(Arc::clone(&exec), &mut bytes)?; | ||
|
|
||
| let returned_exec = | ||
| foreign_codec.try_decode(&bytes, &input_execs, ctx.task_ctx().as_ref())?; | ||
| foreign_codec.try_encode( | ||
| Arc::clone(&exec), | ||
| &mut bytes, | ||
| &DefaultPhysicalProtoConverter {}, | ||
| )?; | ||
|
|
||
| let returned_exec = foreign_codec.try_decode( | ||
| &bytes, | ||
| &input_execs, | ||
| ctx.task_ctx().as_ref(), | ||
| &DefaultPhysicalProtoConverter {}, | ||
| )?; | ||
|
|
||
| assert!(returned_exec.is::<EmptyExec>()); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add new methods with the param that default to the old methods to avoid a breaking change. Did you consider that as an option?