Skip to content

Fix Result name collision in parquet_derive #7548

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

Merged
merged 3 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions parquet_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn parquet_record_writer(input: proc_macro::TokenStream) -> proc_macro::Toke
fn write_to_row_group<W: ::std::io::Write + Send>(
&self,
row_group_writer: &mut ::parquet::file::writer::SerializedRowGroupWriter<'_, W>
) -> Result<(), ::parquet::errors::ParquetError> {
) -> ::std::result::Result<(), ::parquet::errors::ParquetError> {
use ::parquet::column::writer::ColumnWriter;

let mut row_group_writer = row_group_writer;
Expand All @@ -135,7 +135,7 @@ pub fn parquet_record_writer(input: proc_macro::TokenStream) -> proc_macro::Toke
Ok(())
}

fn schema(&self) -> Result<::parquet::schema::types::TypePtr, ::parquet::errors::ParquetError> {
fn schema(&self) -> ::std::result::Result<::parquet::schema::types::TypePtr, ::parquet::errors::ParquetError> {
use ::parquet::schema::types::Type as ParquetType;
use ::parquet::schema::types::TypePtr;
use ::parquet::basic::LogicalType;
Expand Down Expand Up @@ -211,7 +211,7 @@ pub fn parquet_record_reader(input: proc_macro::TokenStream) -> proc_macro::Toke
&mut self,
row_group_reader: &mut dyn ::parquet::file::reader::RowGroupReader,
num_records: usize,
) -> Result<(), ::parquet::errors::ParquetError> {
) -> ::std::result::Result<(), ::parquet::errors::ParquetError> {
use ::parquet::column::reader::ColumnReader;

let mut row_group_reader = row_group_reader;
Expand Down
30 changes: 30 additions & 0 deletions parquet_derive_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,36 @@ mod tests {
assert_eq!(drs[0].isize, out[0].isize);
}

#[test]
fn test_aliased_result() {
// Issue 7547, Where aliasing the `Result` led to
// a collision with the macro internals of derive ParquetRecordReader

mod aliased_result {
use parquet_derive::{ParquetRecordReader, ParquetRecordWriter};
pub type Result = std::result::Result<(), Box<dyn std::error::Error>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub type Result = std::result::Result<(), Box<dyn std::error::Error>>;
// not an actual result type
pub type Result = ();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did the modification but left the other one commented out so there is a bit more historical context (hope thats ok)


#[derive(ParquetRecordReader, ParquetRecordWriter, Debug)]
pub struct ARecord {
pub bool: bool,
pub string: String,
}

impl ARecord {
pub fn validate(&self) -> Result {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn validate(&self) -> Result {
pub fn validate(&self) -> std::result::Result<(), Box<dyn std::error::Error>> {

(so it doesn't use our Result shadow)

Ok(())
}
}
}

use aliased_result::ARecord;
let foo = ARecord {
bool: true,
string: "test".to_string(),
};
assert!(foo.validate().is_ok());
}

/// Returns file handle for a temp file in 'target' directory with a provided content
pub fn get_temp_file(file_name: &str, content: &[u8]) -> fs::File {
// build tmp path to a file in "target/debug/testdata"
Expand Down