-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Adding with_schema_unchecked method for RecordBatch
#7402
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
Conversation
etseidl
left a comment
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.
Seems reasonable to me. Just left a few minor suggestions.
arrow-array/src/record_batch.rs
Outdated
| /// | ||
| /// If provided schema is not compatible with this [`RecordBatch`] columns the runtime behavior | ||
| /// is undefined | ||
| pub fn with_schema_force(self, schema: SchemaRef) -> Result<Self, ArrowError> { |
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.
Maybe with_schema_unchecked would be better?
arrow-array/src/record_batch.rs
Outdated
| /// Forcibly overrides the schema of this [`RecordBatch`] | ||
| /// without additional schema checks however bringing all the schema compatibility responsibilities | ||
| /// to the caller site. |
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.
| /// Forcibly overrides the schema of this [`RecordBatch`] | |
| /// without additional schema checks however bringing all the schema compatibility responsibilities | |
| /// to the caller site. | |
| /// Overrides the schema of this [`RecordBatch`] | |
| /// without additional schema checks. Note, however, that this pushes all the schema compatibility responsibilities | |
| /// to the caller site. In particular, the caller guarantees that `schema` is a superset | |
| /// of the current schema as determined by [`Schema::contains`]. |
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.
Nice said!
arrow-array/src/record_batch.rs
Outdated
| } | ||
|
|
||
| #[test] | ||
| fn test_batch_with_force_schema() { |
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.
Could you please also add a check where the forced schema succeeds?
arrow-array/src/record_batch.rs
Outdated
| // Wrong number of columns | ||
| let invalid_schema_more_cols = Schema::new(vec![ | ||
| Field::new("a", DataType::Utf8, false), | ||
| Field::new("a", DataType::Int32, false), |
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.
| Field::new("a", DataType::Int32, false), | |
| Field::new("b", DataType::Int32, false), |
?. This triggers my OCD 😅
|
Thanks @etseidl for the feedback. Addressed all the comments |
with_schema_force method for RecordBatchwith_schema_unchecked method for RecordBatch
etseidl
left a comment
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.
Thanks @comphead!
|
I think this needs to either be reverted or made unsafe, it allows constructing invalid ArrayData with safe code... Edit: PR to make this unsafe - #7405 |
Which issue does this PR close?
Closes #.
Rationale for this change
Sometimes Arrow-rs users don't require schema checks on
RecordBatchrelying on their schema checks and schema validity rules. However now it is not possible to override the schema without performance impact.Examples: apache/datafusion#15162
apache/datafusion#15603
Proposed
with_schema_uncheckedmethod forRecordBatchoverrides the schema without additional schema checks however bringing all the schema compatibility responsibilities to the caller site.What changes are included in this PR?
Are there any user-facing changes?