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

Method project

arrow-array/src/record_batch.rs:455–480  ·  view source on GitHub ↗

Projects the schema onto the specified columns

(&self, indices: &[usize])

Source from the content-addressed store, hash-verified

453
454 /// Projects the schema onto the specified columns
455 pub fn project(&self, indices: &[usize]) -> Result<RecordBatch, ArrowError> {
456 let projected_schema = self.schema.project(indices)?;
457 let batch_fields = indices
458 .iter()
459 .map(|f| {
460 self.columns.get(*f).cloned().ok_or_else(|| {
461 ArrowError::SchemaError(format!(
462 "project index {} out of bounds, max field {}",
463 f,
464 self.columns.len()
465 ))
466 })
467 })
468 .collect::<Result<Vec<_>, _>>()?;
469
470 unsafe {
471 // Since we're starting from a valid RecordBatch and project
472 // creates a strict subset of the original, there's no need to
473 // redo the validation checks in `try_new_with_options`.
474 Ok(RecordBatch::new_unchecked(
475 SchemaRef::new(projected_schema),
476 batch_fields,
477 self.row_count,
478 ))
479 }
480 }
481
482 /// Normalize a semi-structured [`RecordBatch`] into a flat table.
483 ///

Callers 1

project_benchmarkFunction · 0.45

Calls 2

iterMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected