-
Notifications
You must be signed in to change notification settings - Fork 14
Support user provided codecs #81
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ use datafusion_proto::{ | |
| protobuf::PhysicalPlanNode, | ||
| }; | ||
|
|
||
| use crate::{plan::DistributedCodec, task::ExecutionTask}; | ||
| use crate::task::ExecutionTask; | ||
|
|
||
| use super::ExecutionStage; | ||
|
|
||
|
|
@@ -35,54 +35,42 @@ pub struct ExecutionStageProto { | |
| pub tasks: Vec<ExecutionTask>, | ||
| } | ||
|
|
||
| impl TryFrom<&ExecutionStage> for ExecutionStageProto { | ||
| type Error = DataFusionError; | ||
|
|
||
| fn try_from(stage: &ExecutionStage) -> Result<Self, Self::Error> { | ||
| let codec = stage.codec.clone().unwrap_or(Arc::new(DistributedCodec {})); | ||
|
|
||
| let proto_plan = | ||
| PhysicalPlanNode::try_from_physical_plan(stage.plan.clone(), codec.as_ref())?; | ||
| let inputs = stage | ||
| .child_stages_iter() | ||
| .map(|s| Box::new(ExecutionStageProto::try_from(s).unwrap())) | ||
| .collect(); | ||
|
|
||
| Ok(ExecutionStageProto { | ||
| num: stage.num as u64, | ||
| name: stage.name(), | ||
| plan: Some(Box::new(proto_plan)), | ||
| inputs, | ||
| tasks: stage.tasks.clone(), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<ExecutionStage> for ExecutionStageProto { | ||
| type Error = DataFusionError; | ||
| pub fn proto_from_stage( | ||
| stage: &ExecutionStage, | ||
| codec: &dyn PhysicalExtensionCodec, | ||
|
Collaborator
Author
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. As now a codec is needed here, we cannot just implement this in terms of a simple |
||
| ) -> Result<ExecutionStageProto, DataFusionError> { | ||
| let proto_plan = PhysicalPlanNode::try_from_physical_plan(stage.plan.clone(), codec)?; | ||
| let inputs = stage | ||
| .child_stages_iter() | ||
| .map(|s| Ok(Box::new(proto_from_stage(s, codec)?))) | ||
| .collect::<Result<Vec<_>>>()?; | ||
|
|
||
| fn try_from(stage: ExecutionStage) -> Result<Self, Self::Error> { | ||
| ExecutionStageProto::try_from(&stage) | ||
| } | ||
| Ok(ExecutionStageProto { | ||
| num: stage.num as u64, | ||
| name: stage.name(), | ||
| plan: Some(Box::new(proto_plan)), | ||
| inputs, | ||
| tasks: stage.tasks.clone(), | ||
| }) | ||
| } | ||
|
|
||
| pub fn stage_from_proto( | ||
| msg: ExecutionStageProto, | ||
| registry: &dyn FunctionRegistry, | ||
| runtime: &RuntimeEnv, | ||
| codec: Arc<dyn PhysicalExtensionCodec>, | ||
| codec: &dyn PhysicalExtensionCodec, | ||
| ) -> Result<ExecutionStage> { | ||
| let plan_node = msg.plan.ok_or(internal_datafusion_err!( | ||
| "ExecutionStageMsg is missing the plan" | ||
| ))?; | ||
|
|
||
| let plan = plan_node.try_into_physical_plan(registry, runtime, codec.as_ref())?; | ||
| let plan = plan_node.try_into_physical_plan(registry, runtime, codec)?; | ||
|
|
||
| let inputs = msg | ||
| .inputs | ||
| .into_iter() | ||
| .map(|s| { | ||
| stage_from_proto(*s, registry, runtime, codec.clone()) | ||
| stage_from_proto(*s, registry, runtime, codec) | ||
| .map(|s| Arc::new(s) as Arc<dyn ExecutionPlan>) | ||
| }) | ||
| .collect::<Result<Vec<_>>>()?; | ||
|
|
@@ -93,7 +81,6 @@ pub fn stage_from_proto( | |
| plan, | ||
| inputs, | ||
| tasks: msg.tasks, | ||
| codec: Some(codec), | ||
| depth: 0, | ||
| }) | ||
| } | ||
|
|
@@ -116,6 +103,7 @@ mod tests { | |
| use datafusion_proto::physical_plan::DefaultPhysicalExtensionCodec; | ||
| use prost::Message; | ||
|
|
||
| use crate::stage::proto::proto_from_stage; | ||
| use crate::stage::{proto::stage_from_proto, ExecutionStage, ExecutionStageProto}; | ||
|
|
||
| // create a simple mem table | ||
|
|
@@ -158,12 +146,11 @@ mod tests { | |
| plan: physical_plan, | ||
| inputs: vec![], | ||
| tasks: vec![], | ||
| codec: Some(Arc::new(DefaultPhysicalExtensionCodec {})), | ||
| depth: 0, | ||
| }; | ||
|
|
||
| // Convert to proto message | ||
| let stage_msg = ExecutionStageProto::try_from(&stage)?; | ||
| let stage_msg = proto_from_stage(&stage, &DefaultPhysicalExtensionCodec {})?; | ||
|
|
||
| // Serialize to bytes | ||
| let mut buf = Vec::new(); | ||
|
|
@@ -180,7 +167,7 @@ mod tests { | |
| decoded_msg, | ||
| &ctx, | ||
| ctx.runtime_env().as_ref(), | ||
| Arc::new(DefaultPhysicalExtensionCodec {}), | ||
| &DefaultPhysicalExtensionCodec {}, | ||
| )?; | ||
|
|
||
| // Compare original and round-tripped stages | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Intuively this makes sense but I think I can only fully get the role of
combined_codecwhen I start using it