Skip to content

Deprecate RecordBatchOptions::with_match_field_names #7406

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 9 additions & 8 deletions arrow-array/src/record_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ impl RecordBatch {

// function for comparing column type and field type
// return true if 2 types are not matched
#[allow(deprecated)]
let type_not_match = if options.match_field_names {
|(_, (col_type, field_type)): &(usize, (&DataType, &DataType))| col_type != field_type
} else {
Expand Down Expand Up @@ -400,10 +401,7 @@ impl RecordBatch {
RecordBatch::try_new_with_options(
SchemaRef::new(projected_schema),
batch_fields,
&RecordBatchOptions {
match_field_names: true,
row_count: Some(self.row_count),
},
&RecordBatchOptions::new().with_row_count(Some(self.row_count)),
)
}

Expand Down Expand Up @@ -742,6 +740,7 @@ impl RecordBatch {
#[non_exhaustive]
pub struct RecordBatchOptions {
/// Match field names of structs and lists. If set to `true`, the names must match.
#[deprecated(note = "match_field_names can lead to unpredictable behaviour")]
pub match_field_names: bool,

/// Optional row count, useful for specifying a row count for a RecordBatch with no columns
Expand All @@ -750,6 +749,7 @@ pub struct RecordBatchOptions {

impl RecordBatchOptions {
/// Creates a new `RecordBatchOptions`
#[allow(deprecated)]
pub fn new() -> Self {
Self {
match_field_names: true,
Expand All @@ -764,6 +764,8 @@ impl RecordBatchOptions {
}

/// Sets the `match_field_names` of `RecordBatchOptions` and returns this [`RecordBatch`]
#[deprecated(note = "match_field_names can lead to unpredictable behaviour")]
#[allow(deprecated)]
pub fn with_match_field_names(mut self, match_field_names: bool) -> Self {
self.match_field_names = match_field_names;
self
Expand Down Expand Up @@ -1059,6 +1061,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn create_record_batch_field_name_mismatch() {
let fields = vec![
Field::new("a1", DataType::Int32, false),
Expand Down Expand Up @@ -1514,10 +1517,7 @@ mod tests {
let expected = RecordBatch::try_new_with_options(
Arc::new(Schema::empty()),
vec![],
&RecordBatchOptions {
match_field_names: true,
row_count: Some(3),
},
&RecordBatchOptions::new().with_row_count(Some(3)),
)
.expect("valid conversion");

Expand Down Expand Up @@ -1558,6 +1558,7 @@ mod tests {
assert_eq!("Invalid argument error: Column 'a' is declared as non-nullable but contains null values", format!("{}", maybe_batch.err().unwrap()));
}
#[test]
#[allow(deprecated)]
fn test_record_batch_options() {
let options = RecordBatchOptions::new()
.with_match_field_names(false)
Expand Down
4 changes: 1 addition & 3 deletions arrow-csv/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,7 @@ fn parse(
RecordBatch::try_new_with_options(
projected_schema,
arr,
&RecordBatchOptions::new()
.with_match_field_names(true)
.with_row_count(Some(rows.len())),
&RecordBatchOptions::new().with_row_count(Some(rows.len())),
)
})
}
Expand Down
4 changes: 1 addition & 3 deletions arrow-ipc/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2400,9 +2400,7 @@ mod tests {
#[test]
fn test_no_columns_batch() {
let schema = Arc::new(Schema::empty());
let options = RecordBatchOptions::new()
.with_match_field_names(true)
.with_row_count(Some(10));
let options = RecordBatchOptions::new().with_row_count(Some(10));
let input_batch = RecordBatch::try_new_with_options(schema, vec![], &options).unwrap();
let output_batch = roundtrip_ipc_stream(&input_batch);
assert_eq!(input_batch, output_batch);
Expand Down
6 changes: 1 addition & 5 deletions arrow/src/util/data_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ pub fn create_random_batch(
.map(|field| create_random_array(field, size, null_density, true_density))
.collect::<Result<Vec<ArrayRef>>>()?;

RecordBatch::try_new_with_options(
schema,
columns,
&RecordBatchOptions::new().with_match_field_names(false),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why this was here, as the below code will always create the correct types AFAICT - perhaps a workaround for a since fixed bug?

)
RecordBatch::try_new(schema, columns)
}

/// Create a random [ArrayRef] from a [DataType] with a length,
Expand Down
2 changes: 1 addition & 1 deletion parquet/benches/arrow_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn create_float_bench_batch_with_nans(size: usize, nan_density: f32) -> Result<R
Ok(RecordBatch::try_new_with_options(
Arc::new(schema),
columns,
&RecordBatchOptions::new().with_match_field_names(false),
&RecordBatchOptions::new(),
)?)
}

Expand Down
Loading