Copilot commented on code in PR #24205: URL: https://github.com/apache/datafusion/pull/24205#discussion_r3744700599
########## datafusion/proto/tests/cases/public_conversions.rs: ########## @@ -0,0 +1,123 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Compile-time guard for the `From` / `TryFrom` conversions between DataFusion +//! types and `datafusion_proto::protobuf` messages that downstream crates call. +//! +//! These impls were silently dropped once (see +//! <https://github.com/apache/datafusion/issues/24019>): they were replaced by +//! crate-local `FromProto` / `TryFromProto` traits, which `cargo-semver-checks` +//! has no lint for, so nothing caught the break. Coercing each conversion to a +//! `fn` pointer here does — moving an impl between crates is fine, removing one +//! stops compiling. +//! +//! Only the spelling is asserted. Behaviour is covered by the round-trip tests +//! next to each impl. + +use datafusion_common::config::{ + CsvOptions, JsonOptions, ParquetColumnOptions, ParquetOptions, TableParquetOptions, +}; +use datafusion_common::display::StringifiedPlan; +use datafusion_common::{ + JoinConstraint, JoinType, NullEquality, TableReference, UnnestOptions, +}; +use datafusion_datasource::file_groups::FileGroup; +use datafusion_datasource::file_sink_config::FileSinkConfig; +use datafusion_datasource::{FileRange, PartitionedFile}; +use datafusion_datasource_csv::file_format::CsvSink; +use datafusion_datasource_json::file_format::JsonSink; +use datafusion_datasource_parquet::file_format::ParquetSink; +use datafusion_expr::expr::NullTreatment; +use datafusion_expr::{WindowFrame, WindowFrameBound, WindowFrameUnits}; +use datafusion_physical_expr::expressions::Column; +use datafusion_proto::physical_plan::to_proto::partitioned_files_to_proto; +use datafusion_proto::protobuf; + +/// Asserts `T: From<F>` by naming the conversion. +fn assert_from<F, T: From<F>>() { + let _: fn(F) -> T = From::from; +} + +/// Asserts `T: TryFrom<F>` by naming the conversion. +fn assert_try_from<F, T: TryFrom<F>>() { + let _: fn(F) -> Result<T, T::Error> = TryFrom::try_from; +} + +#[test] +fn file_scan_conversions_are_std_traits() { + assert_try_from::<&protobuf::PartitionedFile, PartitionedFile>(); + assert_try_from::<&PartitionedFile, protobuf::PartitionedFile>(); + assert_try_from::<&protobuf::FileRange, FileRange>(); + assert_try_from::<&FileRange, protobuf::FileRange>(); + assert_try_from::<&protobuf::FileGroup, FileGroup>(); + assert_try_from::<&FileGroup, protobuf::FileGroup>(); + assert_from::<&protobuf::PhysicalColumn, Column>(); + assert_from::<&Column, protobuf::PhysicalColumn>(); + + // The slice form has no local type to hang an impl on, so it is a function. + let _: fn(&[PartitionedFile]) -> datafusion_common::Result<protobuf::FileGroup> = + partitioned_files_to_proto; +} + +#[test] +fn file_sink_conversions_are_std_traits() { + assert_try_from::<&protobuf::FileSinkConfig, FileSinkConfig>(); + assert_try_from::<&FileSinkConfig, protobuf::FileSinkConfig>(); + assert_try_from::<&protobuf::JsonSink, JsonSink>(); + assert_try_from::<&JsonSink, protobuf::JsonSink>(); + assert_try_from::<&protobuf::CsvSink, CsvSink>(); + assert_try_from::<&CsvSink, protobuf::CsvSink>(); + assert_try_from::<&protobuf::ParquetSink, ParquetSink>(); + assert_try_from::<&ParquetSink, protobuf::ParquetSink>(); +} + +#[test] +fn window_frame_conversions_are_std_traits() { + assert_try_from::<protobuf::WindowFrame, WindowFrame>(); + assert_try_from::<&WindowFrame, protobuf::WindowFrame>(); + assert_try_from::<protobuf::WindowFrameBound, WindowFrameBound>(); + assert_try_from::<&WindowFrameBound, protobuf::WindowFrameBound>(); + assert_from::<protobuf::WindowFrameUnits, WindowFrameUnits>(); + assert_from::<WindowFrameUnits, protobuf::WindowFrameUnits>(); + assert_from::<protobuf::NullTreatment, NullTreatment>(); + assert_from::<NullTreatment, protobuf::NullTreatment>(); Review Comment: This compile-time API guard omits both restored `MergeIntoClauseKind` conversions. If those impls are later removed together with their current call sites, this regression test would still pass—the failure mode this file is intended to prevent. Please assert both `From` directions here. This issue also appears on line 117 of the same file. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
