Skip to content

Commit b21cae9

Browse files
adriangbclaude
andcommitted
refactor: rename proto trait register to register_proto
Makes call sites like `config.update_extension(MyExec::register_proto)` say what is being registered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0c16f8a commit b21cae9

8 files changed

Lines changed: 76 additions & 69 deletions

File tree

‎datafusion-examples/examples/proto/extension_plan_registry.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ mod crate_a {
9595
use super::*;
9696

9797
pub fn register(config: &mut SessionConfig) -> Result<()> {
98-
config.update_extension(ParentExec::register)
98+
config.update_extension(ParentExec::register_proto)
9999
}
100100
}
101101

@@ -104,7 +104,7 @@ mod crate_b {
104104
use super::*;
105105

106106
pub fn register(config: &mut SessionConfig) -> Result<()> {
107-
config.update_extension(ChildExec::register)
107+
config.update_extension(ChildExec::register_proto)
108108
}
109109
}
110110

‎datafusion/physical-expr/src/proto.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
//! The `PhysicalExpr` face of the session-scoped [`ProtoDecoderRegistry`],
1919
//! which routes extension expressions to their decoders by name:
20-
//! [`ExtensionExprFromProto::register`] and [`physical_expr_names`], all keyed on `dyn PhysicalExpr`. The store itself
20+
//! [`ExtensionExprFromProto::register_proto`] and [`physical_expr_names`], all keyed on `dyn PhysicalExpr`. The store itself
2121
//! is shared with every other extension kind, so a session carries one
2222
//! registry.
2323
@@ -37,7 +37,7 @@ use datafusion_proto_models::protobuf::physical_expr_node::ExprType;
3737
/// Only extension expressions implement this. A built-in expression has an
3838
/// `ExprType` variant of its own, keeps the inherent `try_from_proto`
3939
/// dispatched from that variant, and has no wire name to be registered under —
40-
/// so it has no [`register`](Self::register) method.
40+
/// so it has no [`register`](Self::register_proto) method.
4141
///
4242
/// One impl block says what the expression is called and how it decodes; its
4343
/// `try_to_proto` on [`PhysicalExpr`] writes the matching node with
@@ -81,7 +81,7 @@ use datafusion_proto_models::protobuf::physical_expr_node::ExprType;
8181
/// }
8282
///
8383
/// let mut config = SessionConfig::new();
84-
/// config.update_extension(MyExpr::register)?;
84+
/// config.update_extension(MyExpr::register_proto)?;
8585
/// ```
8686
pub trait ExtensionExprFromProto: PhysicalExpr + Sized {
8787
/// The name this expression type is written and registered under.
@@ -113,7 +113,7 @@ pub trait ExtensionExprFromProto: PhysicalExpr + Sized {
113113
/// plan or a data source can use the same name in the same registry.
114114
///
115115
/// Add it to the session's registry with
116-
/// `config.update_extension(MyExpr::register)?`, which keeps the decoders
116+
/// `config.update_extension(MyExpr::register_proto)?`, which keeps the decoders
117117
/// that other libraries added. One registry holds every kind, so a library
118118
/// registers its plans and its expressions into the same registry.
119119
///
@@ -136,9 +136,9 @@ pub trait ExtensionExprFromProto: PhysicalExpr + Sized {
136136
/// use datafusion_proto_models::ProtoDecoderRegistry;
137137
///
138138
/// let mut registry = ProtoDecoderRegistry::new();
139-
/// Column::register(&mut registry).unwrap();
139+
/// Column::register_proto(&mut registry).unwrap();
140140
/// ```
141-
fn register(registry: &mut ProtoDecoderRegistry) -> Result<()> {
141+
fn register_proto(registry: &mut ProtoDecoderRegistry) -> Result<()> {
142142
registry.register_decoder::<dyn PhysicalExpr, Self, PhysicalExprDecoder>(
143143
Self::NAME,
144144
Self::try_from_proto,
@@ -175,7 +175,7 @@ pub fn extension_expr_node<T: ExtensionExprFromProto>(
175175
/// to the monomorphized [`ExtensionExprFromProto::try_from_proto`].
176176
///
177177
/// Deliberately private, and the same type on both the
178-
/// [`ExtensionExprFromProto::register`] and the [`decode_physical_expr`] side.
178+
/// [`ExtensionExprFromProto::register_proto`] and the [`decode_physical_expr`] side.
179179
/// [`ExtensionExprFromProto`] is the public contract and
180180
/// [`decode_physical_expr`] (hidden, internal to DataFusion) is the only way
181181
/// to invoke one, so the storage

‎datafusion/physical-plan/src/proto/registry.rs‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//! registration order, which two independent crates cannot agree on.
2525
//!
2626
//! An extension plan implements [`ExtensionPlanFromProto`] instead, and
27-
//! [`ExtensionPlanFromProto::register`] puts its decoder in the
27+
//! [`ExtensionPlanFromProto::register_proto`] puts its decoder in the
2828
//! [`ProtoDecoderRegistry`] the decoding session carries. Lookup is by name,
2929
//! so registration order does not matter. Built-ins cannot be registered;
3030
//! anything unnamed or unregistered still takes the codec chain, unchanged.
@@ -108,7 +108,7 @@ pub trait ExtensionPlanFromProto: ExecutionPlan + Sized {
108108
/// expression or a data source can use the same name in the same registry.
109109
///
110110
/// Add it to the session's registry with
111-
/// `config.update_extension(MyExec::register)?`, which keeps the decoders
111+
/// `config.update_extension(MyExec::register_proto)?`, which keeps the decoders
112112
/// that other libraries added. See [`ProtoDecoderRegistry`].
113113
///
114114
/// A built-in plan does not implement this trait, so it cannot be
@@ -119,7 +119,7 @@ pub trait ExtensionPlanFromProto: ExecutionPlan + Sized {
119119
/// use datafusion_physical_plan::proto::{ExtensionPlanFromProto, ProtoDecoderRegistry};
120120
///
121121
/// let mut registry = ProtoDecoderRegistry::new();
122-
/// FilterExec::register(&mut registry).unwrap();
122+
/// FilterExec::register_proto(&mut registry).unwrap();
123123
/// ```
124124
///
125125
/// The same imports without that call compile, so the failure above is
@@ -133,7 +133,7 @@ pub trait ExtensionPlanFromProto: ExecutionPlan + Sized {
133133
/// let mut registry = ProtoDecoderRegistry::new();
134134
/// let _ = (FilterExec::try_from_proto, &mut registry);
135135
/// ```
136-
fn register(registry: &mut ProtoDecoderRegistry) -> Result<()> {
136+
fn register_proto(registry: &mut ProtoDecoderRegistry) -> Result<()> {
137137
registry.register_decoder::<dyn ExecutionPlan, Self, ExecutionPlanDecoder>(
138138
Self::NAME,
139139
Self::try_from_proto,
@@ -145,7 +145,7 @@ pub trait ExtensionPlanFromProto: ExecutionPlan + Sized {
145145
/// to the monomorphized [`ExtensionPlanFromProto::try_from_proto`].
146146
///
147147
/// Deliberately private, and the same type on both the
148-
/// [`ExtensionPlanFromProto::register`] and the [`decode_execution_plan`] side.
148+
/// [`ExtensionPlanFromProto::register_proto`] and the [`decode_execution_plan`] side.
149149
/// [`ExtensionPlanFromProto`] is the public contract and
150150
/// [`decode_execution_plan`] (hidden, internal to DataFusion) is the only way
151151
/// to invoke one, so this can
@@ -215,9 +215,9 @@ mod tests {
215215
use datafusion_execution::config::SessionConfig;
216216

217217
let mut config = SessionConfig::new();
218-
config.update_extension(RegisteredExec::register)?;
218+
config.update_extension(RegisteredExec::register_proto)?;
219219
let before = config.clone();
220-
config.update_extension(OtherRegisteredExec::register)?;
220+
config.update_extension(OtherRegisteredExec::register_proto)?;
221221

222222
let names = |config: &SessionConfig| {
223223
let registry = config.get_extension::<ProtoDecoderRegistry>().unwrap();
@@ -240,8 +240,8 @@ mod tests {
240240
#[test]
241241
fn register_is_idempotent_for_the_same_type() -> Result<()> {
242242
let mut registry = ProtoDecoderRegistry::new();
243-
RegisteredExec::register(&mut registry)?;
244-
RegisteredExec::register(&mut registry)?;
243+
RegisteredExec::register_proto(&mut registry)?;
244+
RegisteredExec::register_proto(&mut registry)?;
245245

246246
assert_eq!(execution_plan_names(&registry).count(), 1);
247247
assert!(execution_plan_names(&registry).any(|name| name == RegisteredExec::NAME));
@@ -251,11 +251,11 @@ mod tests {
251251
#[test]
252252
fn register_rejects_a_name_collision_between_types() -> Result<()> {
253253
let mut registry = ProtoDecoderRegistry::new();
254-
RegisteredExec::register(&mut registry)?;
254+
RegisteredExec::register_proto(&mut registry)?;
255255

256256
// A distinct type declaring the same `NAME`: the collision two
257257
// independent crates could hit, caught at registration.
258-
let err = RegisteredExecClone::register(&mut registry)
258+
let err = RegisteredExecClone::register_proto(&mut registry)
259259
.expect_err("colliding registration must fail");
260260
assert!(
261261
err.to_string().contains(RegisteredExec::NAME)
@@ -268,8 +268,8 @@ mod tests {
268268
#[test]
269269
fn register_keeps_distinct_names_apart() -> Result<()> {
270270
let mut registry = ProtoDecoderRegistry::new();
271-
RegisteredExec::register(&mut registry)?;
272-
OtherRegisteredExec::register(&mut registry)?;
271+
RegisteredExec::register_proto(&mut registry)?;
272+
OtherRegisteredExec::register_proto(&mut registry)?;
273273

274274
assert_eq!(execution_plan_names(&registry).count(), 2);
275275
let mut names: Vec<&str> = execution_plan_names(&registry).collect();
@@ -282,8 +282,8 @@ mod tests {
282282
#[test]
283283
fn register_rejects_an_empty_plan_name() {
284284
let mut registry = ProtoDecoderRegistry::new();
285-
let err =
286-
UnnamedExec::register(&mut registry).expect_err("an empty NAME must fail");
285+
let err = UnnamedExec::register_proto(&mut registry)
286+
.expect_err("an empty NAME must fail");
287287
assert!(
288288
err.to_string().contains("empty name"),
289289
"unexpected error: {err}"
@@ -300,7 +300,7 @@ mod tests {
300300
registry.register_decoder::<dyn OtherKind, u8, u32>(RegisteredExec::NAME, 7)?;
301301

302302
assert!(execution_plan_names(&registry).next().is_none());
303-
RegisteredExec::register(&mut registry)?;
303+
RegisteredExec::register_proto(&mut registry)?;
304304
assert_eq!(
305305
execution_plan_names(&registry).collect::<Vec<_>>(),
306306
vec![RegisteredExec::NAME]

‎datafusion/proto-models/src/registry.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ struct Registered {
6464
/// ```rust,ignore
6565
/// // in each library
6666
/// pub fn register(config: &mut SessionConfig) -> Result<()> {
67-
/// config.update_extension(MyExec::register)?;
68-
/// config.update_extension(MyExpr::register)
67+
/// config.update_extension(MyExec::register_proto)?;
68+
/// config.update_extension(MyExpr::register_proto)
6969
/// }
7070
///
7171
/// // in the application that owns the session

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ pub trait PhysicalExtensionCodec: Debug + Send + Sync + Any {
15631563
///
15641564
/// Expressions can instead name themselves on the wire and be decoded by a
15651565
/// per-type decoder registered on the session — see
1566-
/// [`ExtensionExprFromProto`] and [`ExtensionExprFromProto::register`]. That path
1566+
/// [`ExtensionExprFromProto`] and [`ExtensionExprFromProto::register_proto`]. That path
15671567
/// resolves by name rather than by codec registration order, so two crates
15681568
/// claiming the same name collide at registration. This method stays the
15691569
/// fallback for everything unnamed or unregistered.
@@ -1581,7 +1581,7 @@ pub trait PhysicalExtensionCodec: Debug + Send + Sync + Any {
15811581
///
15821582
/// [`parse_physical_expr`]: crate::physical_plan::from_proto::parse_physical_expr
15831583
/// [`ExtensionExprFromProto`]: datafusion_physical_plan::proto::ExtensionExprFromProto
1584-
/// [`ExtensionExprFromProto::register`]: datafusion_physical_plan::proto::ExtensionExprFromProto::register
1584+
/// [`ExtensionExprFromProto::register_proto`]: datafusion_physical_plan::proto::ExtensionExprFromProto::register_proto
15851585
fn try_decode_expr(
15861586
&self,
15871587
_buf: &[u8],

‎datafusion/proto/tests/cases/plans/expr_registry.rs‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ fn registry_decodes_named_extension_expr() -> Result<()> {
504504

505505
let session = session_with(
506506
SessionConfig::new().with_batch_size(1234),
507-
TagExpr::register,
507+
TagExpr::register_proto,
508508
)?;
509509
let decoded = from_wire(&node, &session, &TestCodec::Refusing)?;
510510
let decoded = decoded.downcast_ref::<TagExpr>().unwrap();
@@ -523,7 +523,7 @@ fn unnamed_or_unregistered_falls_back_to_codec() -> Result<()> {
523523
set_expr_name(&mut unnamed, None);
524524

525525
let empty = SessionContext::new();
526-
let registered = session_with(SessionConfig::new(), TagExpr::register)?;
526+
let registered = session_with(SessionConfig::new(), TagExpr::register_proto)?;
527527
for (node, session) in [(&named, &empty), (&unnamed, &registered)] {
528528
let decoded = from_wire(node, session, &TestCodec::Tag)?;
529529
let decoded = decoded.downcast_ref::<TagExpr>().unwrap();
@@ -539,7 +539,8 @@ fn unnamed_or_unregistered_falls_back_to_codec() -> Result<()> {
539539
#[test]
540540
fn codec_failure_keeps_its_error_and_names_the_missing_registration() -> Result<()> {
541541
let named = to_wire(&tag_expr()?, &TestCodec::Refusing)?;
542-
let session = session_with(SessionConfig::new(), <TaggedExpr<Other>>::register)?;
542+
let session =
543+
session_with(SessionConfig::new(), <TaggedExpr<Other>>::register_proto)?;
543544

544545
let err = from_wire(&named, &session, &TestCodec::Exhausted).unwrap_err();
545546
assert!(
@@ -572,17 +573,19 @@ fn codec_failure_keeps_its_error_and_names_the_missing_registration() -> Result<
572573
#[test]
573574
fn registration_rejects_collisions_and_empty_names() -> Result<()> {
574575
let mut registry = ProtoDecoderRegistry::new();
575-
TagExpr::register(&mut registry)?;
576-
TagExpr::register(&mut registry)?;
576+
TagExpr::register_proto(&mut registry)?;
577+
TagExpr::register_proto(&mut registry)?;
577578

578-
let err = <TaggedExpr<TagClone> as ExtensionExprFromProto>::register(&mut registry)
579-
.unwrap_err()
580-
.to_string();
579+
let err =
580+
<TaggedExpr<TagClone> as ExtensionExprFromProto>::register_proto(&mut registry)
581+
.unwrap_err()
582+
.to_string();
581583
assert!(err.contains("already registered"), "{err}");
582584

583-
let err = <TaggedExpr<Unnamed> as ExtensionExprFromProto>::register(&mut registry)
584-
.unwrap_err()
585-
.to_string();
585+
let err =
586+
<TaggedExpr<Unnamed> as ExtensionExprFromProto>::register_proto(&mut registry)
587+
.unwrap_err()
588+
.to_string();
586589
assert!(err.contains("empty name"), "{err}");
587590

588591
assert_eq!(
@@ -600,7 +603,7 @@ fn nested_extension_exprs_both_decode_through_the_registry() -> Result<()> {
600603
Arc::new(TagExpr::new("inner", col("a", &test_schema())?));
601604
let outer: Arc<dyn PhysicalExpr> = Arc::new(TagExpr::new("outer", inner));
602605
let node = to_wire(&outer, &TestCodec::Refusing)?;
603-
let session = session_with(SessionConfig::new(), TagExpr::register)?;
606+
let session = session_with(SessionConfig::new(), TagExpr::register_proto)?;
604607

605608
let decoded = from_wire(&node, &session, &TestCodec::Refusing)?;
606609
let outer = decoded.downcast_ref::<TagExpr>().unwrap();
@@ -615,7 +618,8 @@ fn nested_extension_exprs_both_decode_through_the_registry() -> Result<()> {
615618
#[test]
616619
fn a_failing_registry_decoder_does_not_fall_through_to_the_codec() -> Result<()> {
617620
let node = to_wire(&tag_expr()?, &TestCodec::Tag)?;
618-
let session = session_with(SessionConfig::new(), <TaggedExpr<Failing>>::register)?;
621+
let session =
622+
session_with(SessionConfig::new(), <TaggedExpr<Failing>>::register_proto)?;
619623
let err = from_wire(&node, &session, &TestCodec::Tag).unwrap_err();
620624
assert!(
621625
err.to_string()
@@ -630,7 +634,7 @@ fn a_failing_registry_decoder_does_not_fall_through_to_the_codec() -> Result<()>
630634
/// session.
631635
#[test]
632636
fn extension_expr_resolves_scalar_and_aggregate_udfs_from_the_session() -> Result<()> {
633-
let session = session_with(SessionConfig::new(), FunctionRefExpr::register)?;
637+
let session = session_with(SessionConfig::new(), FunctionRefExpr::register_proto)?;
634638
session.register_udf(create_udf(
635639
"my_add_one",
636640
vec![DataType::Int64],
@@ -664,7 +668,7 @@ fn extension_expr_resolves_scalar_and_aggregate_udfs_from_the_session() -> Resul
664668
child: col("a", &test_schema())?,
665669
});
666670
let node = to_wire(&expr, &TestCodec::Refusing)?;
667-
let reader = session_with(SessionConfig::new(), FunctionRefExpr::register)?;
671+
let reader = session_with(SessionConfig::new(), FunctionRefExpr::register_proto)?;
668672
let err = from_wire(&node, &reader, &TestCodec::Refusing).unwrap_err();
669673
assert!(err.to_string().contains("my_add_one"), "{err}");
670674
Ok(())
@@ -686,7 +690,7 @@ fn registry_expr_survives_a_whole_plan_roundtrip() -> Result<()> {
686690

687691
let session = session_with(
688692
SessionConfig::new().with_batch_size(4096),
689-
TagExpr::register,
693+
TagExpr::register_proto,
690694
)?;
691695
let decoded = physical_plan_from_bytes_with_extension_codec(
692696
&bytes,
@@ -838,7 +842,7 @@ fn registry_expr_keeps_its_expression_id_for_deduplication() -> Result<()> {
838842
"the serializer must stamp the expression id"
839843
);
840844

841-
let session = session_with(SessionConfig::new(), IdentityExpr::register)?;
845+
let session = session_with(SessionConfig::new(), IdentityExpr::register_proto)?;
842846
let task_ctx = session.task_ctx();
843847
let decode_ctx = PhysicalPlanDecodeContext::new(task_ctx.as_ref(), &codec);
844848
let decoded = converter.proto_to_physical_expr(&node, &schema, &decode_ctx)?;
@@ -949,8 +953,8 @@ fn registry_plan_and_expr_with_the_same_name_roundtrip_together() -> Result<()>
949953
let bytes = physical_plan_to_bytes_with_extension_codec(plan, &TestCodec::Refusing)?;
950954

951955
let session = session_with(SessionConfig::new().with_batch_size(2048), |registry| {
952-
SameNameExec::register(registry)?;
953-
TagExpr::register(registry)
956+
SameNameExec::register_proto(registry)?;
957+
TagExpr::register_proto(registry)
954958
})?;
955959
let decoded = physical_plan_from_bytes_with_extension_codec(
956960
&bytes,

0 commit comments

Comments
 (0)