Skip to content

Commit 585e597

Browse files
adriangbclaude
andcommitted
feat: decode extension ExecutionPlans through the session registry
Wires the name-keyed registry into the central decode dispatch. The rule is the one function decode already uses a layer down (payload -> codec; else registry -> codec fallback): * `plan_name` present *and* registered on the decoding session -> the plan's own `try_from_proto`, no codec involved. * anything else -> the `PhysicalExtensionCodec` chain, unchanged. Existing behavior is untouched: codec-encoded plans stay anonymous on the wire (`plan_name: None`) and take the same path they always have. When a name is present but unregistered and the codec also fails, the error now points at the missing registration and lists what the session does know, instead of leaving only the codec's generic "unsupported plan". Tests cover a session-dependent extension plan (its worker pool is rebuilt from the decoding session, never serialized), two independent extension plans coexisting with no `ComposedPhysicalExtensionCodec`, the registry winning over a codec that claims every payload, and codec-encoded plans decoding as before. Closes apache#24625. Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 8444d7f commit 585e597

3 files changed

Lines changed: 788 additions & 11 deletions

File tree

‎datafusion/proto/src/physical_plan/mod.rs‎

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use arrow::datatypes::{IntervalMonthDayNanoType, Schema, SchemaRef};
2525
use datafusion_catalog::memory::MemorySourceConfig;
2626
use datafusion_common::utils::{usize_from_wire, usize_to_wire};
2727
use datafusion_common::{
28-
DataFusionError, Result, internal_datafusion_err, internal_err, not_impl_err,
29-
plan_err,
28+
DataFusionError, Result, config_datafusion_err, internal_datafusion_err,
29+
internal_err, not_impl_err, plan_err,
3030
};
3131
use datafusion_datasource_arrow::source::ArrowSource;
3232
#[cfg(feature = "avro")]
@@ -71,7 +71,7 @@ use datafusion_physical_plan::placeholder_row::PlaceholderRowExec;
7171
use datafusion_physical_plan::projection::ProjectionExec;
7272
use datafusion_physical_plan::proto::{
7373
ExecutionPlanDecode, ExecutionPlanDecodeCtx, ExecutionPlanEncode,
74-
ExecutionPlanEncodeCtx,
74+
ExecutionPlanEncodeCtx, ExecutionPlanRegistry, ExecutionPlanRegistryExt,
7575
};
7676
use datafusion_physical_plan::repartition::RepartitionExec;
7777
use datafusion_physical_plan::scalar_subquery::ScalarSubqueryExec;
@@ -1399,20 +1399,49 @@ pub trait PhysicalPlanNodeExt: Sized {
13991399
ctx: &PhysicalPlanDecodeContext<'_>,
14001400
proto_converter: &dyn PhysicalProtoConverterExtension,
14011401
) -> Result<Arc<dyn ExecutionPlan>> {
1402+
// Lookup-order policy, mirroring the one function decode already uses a
1403+
// layer down (payload -> codec; else registry -> codec fallback): a
1404+
// plan that named itself on the wire and is registered on this session
1405+
// decodes itself, no codec involved. Anything else — an unnamed node
1406+
// from a codec-encoded writer, or a name this session does not know —
1407+
// takes the codec chain exactly as before.
1408+
let registry = ctx.task_ctx().session_config().execution_plan_registry();
1409+
if let Some(plan_name) = extension.plan_name.as_deref()
1410+
&& let Some(decoder) = registry
1411+
.as_ref()
1412+
.and_then(|registry| registry.decoder(plan_name))
1413+
{
1414+
let plan_decoder = ConverterPlanDecoder {
1415+
ctx,
1416+
proto_converter,
1417+
};
1418+
// The decoder receives the whole node, like every built-in
1419+
// `try_from_proto`, and decodes its own children through the ctx.
1420+
return decoder(self.node(), &ExecutionPlanDecodeCtx::new(&plan_decoder));
1421+
}
1422+
14021423
let inputs: Vec<Arc<dyn ExecutionPlan>> = extension
14031424
.inputs
14041425
.iter()
14051426
.map(|i| proto_converter.proto_to_execution_plan(i, ctx))
14061427
.collect::<Result<_>>()?;
14071428

1408-
let extension_node = ctx.codec().try_decode(
1409-
extension.node.as_slice(),
1410-
&inputs,
1411-
ctx.task_ctx(),
1412-
proto_converter,
1413-
)?;
1414-
1415-
Ok(extension_node)
1429+
ctx.codec()
1430+
.try_decode(
1431+
extension.node.as_slice(),
1432+
&inputs,
1433+
ctx.task_ctx(),
1434+
proto_converter,
1435+
)
1436+
.map_err(|e| match extension.plan_name.as_deref() {
1437+
// The writer named the plan but this session has no decoder for
1438+
// it: say so, rather than leaving only the codec's "unsupported
1439+
// plan" error to explain a missing registration.
1440+
Some(plan_name) => {
1441+
unregistered_extension_plan_err(plan_name, registry.as_deref(), &e)
1442+
}
1443+
None => e,
1444+
})
14161445
}
14171446

14181447
fn generate_series_name_to_str(name: protobuf::GenerateSeriesName) -> &'static str {
@@ -2142,6 +2171,36 @@ impl PhysicalExtensionCodec for ComposedPhysicalExtensionCodec {
21422171
}
21432172
}
21442173

2174+
/// Error for a `PhysicalExtensionNode` that names its plan type but finds no
2175+
/// decoder registered for that name and no codec able to decode it either.
2176+
///
2177+
/// Lists what *is* registered, because the usual cause is a session configured
2178+
/// on the writing side but not on the reading one.
2179+
fn unregistered_extension_plan_err(
2180+
plan_name: &str,
2181+
registry: Option<&ExecutionPlanRegistry>,
2182+
codec_error: &DataFusionError,
2183+
) -> DataFusionError {
2184+
let mut registered: Vec<&str> = registry
2185+
.map(|registry| registry.names().collect())
2186+
.unwrap_or_default();
2187+
registered.sort_unstable();
2188+
let registered = if registered.is_empty() {
2189+
"none".to_string()
2190+
} else {
2191+
registered.join(", ")
2192+
};
2193+
// Not an `Internal` error: the cause is a session that was not configured,
2194+
// not a bug in DataFusion, and `Internal` would tell the user to file one.
2195+
config_datafusion_err!(
2196+
"No decoder is registered for the extension ExecutionPlan '{plan_name}', and the \
2197+
PhysicalExtensionCodec failed with [{codec_error}]. Register the plan on the \
2198+
decoding session's SessionConfig with \
2199+
`ExecutionPlanRegistryExt::register_execution_plan`, or supply a \
2200+
PhysicalExtensionCodec that handles it. Registered extension plans: {registered}"
2201+
)
2202+
}
2203+
21452204
/// Adapter backing [`ExecutionPlanEncodeCtx`] for plans migrated to the
21462205
/// `try_to_proto` hook (#22419). Routes child-plan and child-expr encoding back
21472206
/// through the central converter so nested plans honor their own hooks.

0 commit comments

Comments
 (0)