-
Notifications
You must be signed in to change notification settings - Fork 984
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 is unsound")] | ||
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 is unsound")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be there any reason it is unsound so the user can accept exact risks when using it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tbh I've not sat down and worked out a precise exploit chain, if I had this would flagged as a security vulnerability. However, it is breaking a pretty fundamental invariant that is assumed in a number of places. The worst it is probably going to do is cause something to panic, or produce invalid output, but the potential is there and I'd sleep happier not having it being used 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had the same question above -- if we are going to claim something is unsound I think we should justify why and provide some hints for an alternative |
||
#[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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is marked non_exhaustive so the churn should be fairly minimal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we mark it unsound, I think it would help to provide a link / reference with an explanation about why it is unsound
For example, it is not clear to me why mismatched names is unsound 🤔