Module schema

Module schema 

Source
Expand description

Core schema traits for compile-time Arrow typing.

This module provides the foundational traits generated by #[derive(Record)]:

§Schema Definition

TraitDescription
RecordMarker trait with const LEN: usize for column count
ColAt<I>Per-column metadata: type, name, nullability, builder, array
ForEachColCompile-time iteration via ColumnVisitor
SchemaMetaRuntime schema: fields(), schema(), metadata()
StructMetaNested struct support: child_fields(), new_struct_builder()

§Row Building

TraitDescription
BuildRowsEntry point: new_builders(capacity)
RowBuilderAppend methods: append_row(), append_rows(), finish()
IntoRecordBatchConvert arrays to RecordBatch
AppendStructAppend struct fields into a StructBuilder

§Zero-Copy Views (requires views feature)

Read RecordBatch data without allocation using generated view types.

§Generated Types

For each #[derive(Record)] struct Foo, the macro generates:

  • FooView<'a> — Borrowed row view with fields as references
  • FooViews<'a> — Iterator yielding Result<FooView<'a>, ViewAccessError>
  • impl TryFrom<FooView<'_>> for Foo — Convert view to owned record

§Reading Views

use typed_arrow::prelude::*;

#[derive(Record)]
struct Row {
    id: i32,
    name: String,
}

// Get iterator of views
for view in batch.iter_views::<Row>()?.try_flatten()? {
    // view.id is i32 (copied), view.name is &str (zero-copy)
    println!("{}: {}", view.id, view.name);
}

§Converting Views to Owned

Use .try_into() when data must outlive the batch:

use typed_arrow::prelude::*;

#[derive(Record)]
struct Row {
    id: i32,
    name: String,
}

let mut owned_rows = Vec::new();
for view in batch.iter_views::<Row>()?.try_flatten()? {
    let owned: Row = view.try_into()?; // Clone strings, copy primitives
    owned_rows.push(owned);
}
// owned_rows can now outlive the batch

The conversion uses TryFrom with ViewAccessError to handle nested structures that may fail during conversion.

§Key Traits

TraitDescription
FromRecordBatchCreate views from a batch via from_record_batch()
ViewResultIteratorExtHelper .try_flatten() for view iterators
StructViewInternal: extract views from nested StructArray

Re-exports§

pub use crate::error::SchemaError;
pub use crate::error::ViewAccessError;

Structs§

FieldMeta
Simple compile-time column metadata passed to visitors.

Traits§

AppendStruct
Trait implemented by #[derive(Record)] structs to append their fields into a StructBuilder. Used by row-based APIs to handle nested struct fields.
AppendStructRef
Trait implemented by #[derive(Record)] structs to append their fields into a StructBuilder from a borrowed reference. This enables container builders (e.g., lists of structs) to append child values without taking ownership of the struct.
BuildRows
Row-based building interface: construct typed column builders, append owned rows, and finish into typed arrays.
ColAt
Per-column metadata for a record at index I.
ColumnVisitor
A visitor invoked at compile time for each column of a Record.
ForEachCol
Trait emitted by derive/macro to enable for_each_col expansion.
FromRecordBatch
Trait for creating zero-copy views over a RecordBatch.
IntoRecordBatch
Trait implemented by derive-generated arrays to assemble a RecordBatch.
Record
A record (row) with a fixed, compile-time number of columns.
RowBuilder
Trait implemented by derive-generated builders to append rows of Row and finish into a typed arrays struct.
SchemaMeta
Arrow runtime schema metadata for a top-level Record.
StructMeta
Metadata and builder utilities for nested Struct fields.
StructView
Trait for creating a view from a StructArray at a specific index.
ViewResultIteratorExt
Extension trait providing convenience methods for iterators over Result<T, ViewAccessError>.