Skip to content

Commit 8d4ecbf

Browse files
adriangbclaude
andcommitted
chore(proto): remove transient FromProto/TryFromProto traits
After C3-C7 relocated all of the orphan-rule-violating conversion impls into the crates that own their target types, the `FromProto` / `TryFromProto` traits in `datafusion-proto::convert` and the `convert_required_proto!` macro have no remaining external uses. Delete them. Two cleanups remain in datafusion-proto's source tree, neither of which warrant a public trait: - `physical_plan/from_proto.rs` had one use of `Column::from_proto` for the physical-expr `Column`; inlined to `Column::new(...)` at the single callsite (Phase-2 work will migrate this to the `to_proto` hook). - `logical_plan/file_formats.rs` has 8 conversion impls between `*FormatFactory` (foreign in datasource-* crates) and `*OptionsProto` (foreign in proto-common). A private file-local `FromProto<T>` trait keeps these organized; it is not exported and has no relationship to the deleted public traits. End-state callers see plain `(&p).try_into()?` everywhere, matching the target architecture in apache#21835's follow-up doc. Wire format unchanged. 161 proto tests pass (6 pre-existing parquet-testing submodule failures unrelated). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent e5adb90 commit 8d4ecbf

5 files changed

Lines changed: 11 additions & 77 deletions

File tree

‎datafusion/proto/src/common.rs‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,6 @@ macro_rules! convert_required {
4747
}};
4848
}
4949

50-
/// Like [`convert_required`] but for types whose proto conversion goes through
51-
/// the [`TryFromProto`](crate::convert::TryFromProto) trait instead of
52-
/// [`TryFrom`]. Required because some prost-generated types now live in a
53-
/// separate crate, so `TryFrom`/`From` cannot be implemented on foreign-foreign
54-
/// pairs from `datafusion-proto` directly.
55-
#[macro_export]
56-
macro_rules! convert_required_proto {
57-
($T:ty, $PB:expr) => {{
58-
if let Some(field) = $PB.as_ref() {
59-
Ok::<$T, _>(<$T as $crate::convert::TryFromProto<_>>::try_from_proto(
60-
field,
61-
)?)
62-
} else {
63-
Err(proto_error("Missing required field in protobuf"))
64-
}
65-
}};
66-
}
67-
6850
#[macro_export]
6951
macro_rules! into_required {
7052
($PB:expr) => {{

‎datafusion/proto/src/convert.rs‎

Lines changed: 0 additions & 44 deletions
This file was deleted.

‎datafusion/proto/src/lib.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,10 @@
123123
//! ```
124124
pub mod bytes;
125125
pub mod common;
126-
pub mod convert;
127126
pub mod generated;
128127
pub mod logical_plan;
129128
pub mod physical_plan;
130129

131-
pub use convert::{FromProto, TryFromProto};
132-
133130
pub mod protobuf {
134131
pub use datafusion_proto_common::common::proto_error;
135132
pub use datafusion_proto_common::protobuf::*;

‎datafusion/proto/src/logical_plan/file_formats.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use std::sync::Arc;
1919

2020
use super::LogicalExtensionCodec;
21-
use crate::convert::FromProto;
2221
use crate::protobuf::{
2322
CsvOptions as CsvOptionsProto, CsvQuoteStyle as CsvQuoteStyleProto,
2423
JsonOptions as JsonOptionsProto,
@@ -35,6 +34,16 @@ use datafusion_datasource_json::file_format::JsonFormatFactory;
3534
use datafusion_execution::TaskContext;
3635
use prost::Message;
3736

37+
/// File-local helper trait used to organize the FormatFactory <-> Options
38+
/// conversions below. Both source and target types are foreign to this crate
39+
/// for the file-format pairs (e.g. `CsvFormatFactory` is in
40+
/// `datafusion-datasource-csv` and `CsvOptionsProto` is in
41+
/// `datafusion-proto-common`), so the orphan rule forbids a standard `From`
42+
/// impl here. Kept private — public callers should not depend on it.
43+
trait FromProto<T>: Sized {
44+
fn from_proto(value: T) -> Self;
45+
}
46+
3847
#[derive(Debug)]
3948
pub struct CsvLogicalExtensionCodec;
4049

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,10 @@ use super::{
4848
DefaultPhysicalProtoConverter, PhysicalExtensionCodec, PhysicalPlanDecodeContext,
4949
PhysicalProtoConverterExtension,
5050
};
51-
use crate::convert::FromProto;
5251
use crate::logical_plan::{self};
5352
use crate::protobuf::physical_expr_node::ExprType;
5453
use crate::{convert_required, protobuf};
5554

56-
impl FromProto<&protobuf::PhysicalColumn> for Column {
57-
fn from_proto(c: &protobuf::PhysicalColumn) -> Column {
58-
Column::new(&c.name, c.index as usize)
59-
}
60-
}
61-
6255
/// Parses a physical sort expression from a protobuf.
6356
///
6457
/// # Arguments
@@ -256,10 +249,7 @@ pub fn parse_physical_expr_with_converter(
256249
.ok_or_else(|| proto_error("Unexpected empty physical expression"))?;
257250

258251
let pexpr: Arc<dyn PhysicalExpr> = match expr_type {
259-
ExprType::Column(c) => {
260-
let pcol = Column::from_proto(c);
261-
Arc::new(pcol)
262-
}
252+
ExprType::Column(c) => Arc::new(Column::new(&c.name, c.index as usize)),
263253
ExprType::UnknownColumn(c) => Arc::new(UnKnownColumn::new(&c.name)),
264254
ExprType::Literal(scalar) => Arc::new(Literal::new(scalar.try_into()?)),
265255
ExprType::BinaryExpr(binary_expr) => {

0 commit comments

Comments
 (0)