Skip to content

Commit 5a278c6

Browse files
nilskchalamb
andauthored
RecordBatchDecoder: skip RecordBatch validation when skip_validation property is enabled (#7509)
* RecordBatchDecoder: respect skip_validation property * Update arrow-ipc/src/reader.rs Co-authored-by: Andrew Lamb <[email protected]> * Update arrow-ipc/src/reader.rs Co-authored-by: Andrew Lamb <[email protected]> --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent ce18e5b commit 5a278c6

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

arrow-ipc/src/reader.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,46 @@ impl<'a> RecordBatchDecoder<'a> {
490490
self.skip_field(field, &mut variadic_counts)?;
491491
}
492492
}
493-
assert!(variadic_counts.is_empty());
493+
494494
arrays.sort_by_key(|t| t.0);
495-
RecordBatch::try_new_with_options(
496-
Arc::new(schema.project(projection)?),
497-
arrays.into_iter().map(|t| t.1).collect(),
498-
&options,
499-
)
495+
496+
let schema = Arc::new(schema.project(projection)?);
497+
let columns = arrays.into_iter().map(|t| t.1).collect::<Vec<_>>();
498+
499+
if self.skip_validation.get() {
500+
// Safety: setting `skip_validation` requires `unsafe`, user assures data is valid
501+
unsafe {
502+
Ok(RecordBatch::new_unchecked(
503+
schema,
504+
columns,
505+
self.batch.length() as usize,
506+
))
507+
}
508+
} else {
509+
assert!(variadic_counts.is_empty());
510+
RecordBatch::try_new_with_options(schema, columns, &options)
511+
}
500512
} else {
501513
let mut children = vec![];
502514
// keep track of index as lists require more than one node
503515
for field in schema.fields() {
504516
let child = self.create_array(field, &mut variadic_counts)?;
505517
children.push(child);
506518
}
507-
assert!(variadic_counts.is_empty());
508-
RecordBatch::try_new_with_options(schema, children, &options)
519+
520+
if self.skip_validation.get() {
521+
// Safety: setting `skip_validation` requires `unsafe`, user assures data is valid
522+
unsafe {
523+
Ok(RecordBatch::new_unchecked(
524+
schema,
525+
children,
526+
self.batch.length() as usize,
527+
))
528+
}
529+
} else {
530+
assert!(variadic_counts.is_empty());
531+
RecordBatch::try_new_with_options(schema, children, &options)
532+
}
509533
}
510534
}
511535

0 commit comments

Comments
 (0)