Skip to content
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

Minor: Error handling and minor fixes for ShuffleCodec #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 15 additions & 13 deletions src/shuffle/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ use crate::protobuf::{RaySqlExecNode, ShuffleReaderExecNode, ShuffleWriterExecNo
use crate::shuffle::{ShuffleReaderExec, ShuffleWriterExec};
use datafusion::arrow::datatypes::SchemaRef;
use datafusion::common::{DataFusionError, Result};
use datafusion::execution::runtime_env::RuntimeEnv;
use datafusion::execution::FunctionRegistry;
use datafusion::physical_plan::{ExecutionPlan, Partitioning};
use datafusion_proto::physical_plan::from_proto::parse_protobuf_hash_partitioning;
use datafusion_proto::physical_plan::to_proto::serialize_physical_expr;
use datafusion_proto::physical_plan::DefaultPhysicalExtensionCodec;
use datafusion_proto::physical_plan::PhysicalExtensionCodec;
use datafusion_proto::physical_plan::{AsExecutionPlan, DefaultPhysicalExtensionCodec};
use datafusion_proto::protobuf::{self, PhysicalHashRepartition, PhysicalPlanNode};
use datafusion_proto::protobuf::{self, PhysicalHashRepartition};
use prost::Message;
use std::sync::Arc;

Expand All @@ -38,7 +37,7 @@ impl PhysicalExtensionCodec for ShuffleCodec {
fn try_decode(
&self,
buf: &[u8],
_inputs: &[Arc<dyn ExecutionPlan>],
inputs: &[Arc<dyn ExecutionPlan>],
registry: &dyn FunctionRegistry,
) -> Result<Arc<dyn ExecutionPlan>, DataFusionError> {
// decode bytes to protobuf struct
Expand All @@ -63,11 +62,7 @@ impl PhysicalExtensionCodec for ShuffleCodec {
)))
}
Some(PlanType::ShuffleWriter(writer)) => {
let plan = writer.plan.unwrap().try_into_physical_plan(
registry,
&RuntimeEnv::default(),
self,
)?;
let plan = inputs[0].clone();
let hash_part = parse_protobuf_hash_partitioning(
writer.partitioning.as_ref(),
registry,
Expand All @@ -81,7 +76,9 @@ impl PhysicalExtensionCodec for ShuffleCodec {
&writer.shuffle_dir,
)))
}
_ => unreachable!(),
_ => Err(DataFusionError::Execution(
"Missing or unexpected plan_type".into(),
)),
}
}

Expand All @@ -102,18 +99,23 @@ impl PhysicalExtensionCodec for ShuffleCodec {
};
PlanType::ShuffleReader(reader)
} else if let Some(writer) = node.as_any().downcast_ref::<ShuffleWriterExec>() {
let plan = PhysicalPlanNode::try_from_physical_plan(writer.plan.clone(), self)?;
let partitioning =
encode_partitioning_scheme(writer.properties().output_partitioning())?;
let writer = ShuffleWriterExecNode {
stage_id: writer.stage_id as u32,
plan: Some(plan),
// No need to redundantly serialize the child plan, as input plan(s) are recursively
// serialized by PhysicalPlanNode and will be available as `inputs` in `try_decode`.
// TODO: remove this field from the proto definition?
plan: None,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@austin362667 is this assessment legit or is there a reason that I missed for serialising the child plan as part of the ShuffleWriterExecNode proto instead of relying on the built-in recursive input plan serialisation?

As a side note, this change is needed so that we don't assume that the ShuffleCodec (i.e. self in the try_from_physical_plan(writer.plan.clone(), self) call) is the only extension codec needed for serialising the whole plan, but allow for additional extensions be registered without requiring this particular codec to be aware of them.

partitioning: Some(partitioning),
shuffle_dir: writer.shuffle_dir.clone(),
};
PlanType::ShuffleWriter(writer)
} else {
unreachable!()
return Err(DataFusionError::Execution(format!(
"Unsupported plan node: {}",
node.name()
)));
};
plan.encode(buf);
Ok(())
Expand Down