MCPcopy Create free account
hub / github.com/apache/arrow-rs / read_record_batch

Method read_record_batch

arrow-ipc/src/reader.rs:548–621  ·  view source on GitHub ↗

Read the record batch, consuming the reader

(mut self)

Source from the content-addressed store, hash-verified

546
547 /// Read the record batch, consuming the reader
548 fn read_record_batch(mut self) -> Result<RecordBatch, ArrowError> {
549 let mut variadic_counts: VecDeque<i64> = self
550 .batch
551 .variadicBufferCounts()
552 .into_iter()
553 .flatten()
554 .collect();
555
556 let options = RecordBatchOptions::new().with_row_count(Some(self.batch.length() as usize));
557
558 let schema = Arc::clone(&self.schema);
559 if let Some(projection) = self.projection {
560 let mut arrays = vec![];
561 // project fields
562 for (idx, field) in schema.fields().iter().enumerate() {
563 // A projected field can appear more than once, so collect all matching positions.
564 let mut child = None;
565 for (proj_idx, projected_idx) in projection.iter().enumerate() {
566 if *projected_idx == idx {
567 if child.is_none() {
568 child = Some(self.create_array(field, &mut variadic_counts)?);
569 }
570
571 // Reuse the decoded array for duplicate projection entries.
572 arrays.push((proj_idx, child.as_ref().unwrap().clone()));
573 }
574 }
575
576 if child.is_none() {
577 self.skip_field(field, &mut variadic_counts)?;
578 }
579 }
580
581 arrays.sort_by_key(|t| t.0);
582
583 let schema = Arc::new(schema.project(projection)?);
584 let columns = arrays.into_iter().map(|t| t.1).collect::<Vec<_>>();
585
586 if self.skip_validation.get() {
587 // Safety: setting `skip_validation` requires `unsafe`, user assures data is valid
588 unsafe {
589 Ok(RecordBatch::new_unchecked(
590 schema,
591 columns,
592 self.batch.length() as usize,
593 ))
594 }
595 } else {
596 assert!(variadic_counts.is_empty());
597 RecordBatch::try_new_with_options(schema, columns, &options)
598 }
599 } else {
600 let mut children = vec![];
601 // keep track of index as lists require more than one node
602 for field in schema.fields() {
603 let child = self.create_array(field, &mut variadic_counts)?;
604 children.push(child);
605 }

Calls 15

try_newFunction · 0.85
collectMethod · 0.80
flattenMethod · 0.80
variadicBufferCountsMethod · 0.80
with_row_countMethod · 0.80
create_arrayMethod · 0.80
skip_fieldMethod · 0.80
read_messageMethod · 0.80
header_typeMethod · 0.80
metaDataLengthMethod · 0.80
into_iterMethod · 0.45