diff --git a/arrow-array/src/record_batch.rs b/arrow-array/src/record_batch.rs index cf20f9a059cb..ba0a3fbdcf72 100644 --- a/arrow-array/src/record_batch.rs +++ b/arrow-array/src/record_batch.rs @@ -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 { @@ -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)), ) } @@ -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 @@ -750,6 +749,7 @@ pub struct RecordBatchOptions { impl RecordBatchOptions { /// Creates a new `RecordBatchOptions` + #[allow(deprecated)] pub fn new() -> Self { Self { match_field_names: true, @@ -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 @@ -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), @@ -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"); @@ -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) diff --git a/arrow-csv/src/reader/mod.rs b/arrow-csv/src/reader/mod.rs index 5440c7a86b24..c159d54f060e 100644 --- a/arrow-csv/src/reader/mod.rs +++ b/arrow-csv/src/reader/mod.rs @@ -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())), ) }) } diff --git a/arrow-ipc/src/reader.rs b/arrow-ipc/src/reader.rs index 83dc5702dc94..314fbf1a130a 100644 --- a/arrow-ipc/src/reader.rs +++ b/arrow-ipc/src/reader.rs @@ -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); diff --git a/arrow/src/util/data_gen.rs b/arrow/src/util/data_gen.rs index 42a0798f5540..8131549ceefb 100644 --- a/arrow/src/util/data_gen.rs +++ b/arrow/src/util/data_gen.rs @@ -46,11 +46,7 @@ pub fn create_random_batch( .map(|field| create_random_array(field, size, null_density, true_density)) .collect::>>()?; - RecordBatch::try_new_with_options( - schema, - columns, - &RecordBatchOptions::new().with_match_field_names(false), - ) + RecordBatch::try_new(schema, columns) } /// Create a random [ArrayRef] from a [DataType] with a length, diff --git a/parquet/benches/arrow_writer.rs b/parquet/benches/arrow_writer.rs index 4166d962b550..8bbe99865d0f 100644 --- a/parquet/benches/arrow_writer.rs +++ b/parquet/benches/arrow_writer.rs @@ -198,7 +198,7 @@ fn create_float_bench_batch_with_nans(size: usize, nan_density: f32) -> Result