DataFileReader
struct DataFileReader[C: CodecSet = DefaultCodecs]Reads an Avro Object Container File held in memory.
Implements Copyable, Movable
- Fields
data: List[UInt8]schema: Schema: The parsedavro.schema. Empty untilensure_schema()when the reader was opened withdefer_schema=True.schema_ready: Bool: False only between adefer_schema=Trueopen andensure_schema().metadata_keys: List[String]: Metadata keys in the order the file wrote them.metadata_vals: List[List[UInt8]]: Metadata values, parallel tometadata_keys.codec: Stringsync_marker: List[UInt8]pos: Int: Offset of the next block header indata.block: List[UInt8]block_pos: Intblock_left: Intblock_index: Int
__init__
def __init__(out self, var data: List[UInt8], *, defer_schema: Bool = False) Read the header. defer_schema skips parsing the avro.schema JSON, which is the expensive half of opening a small file.
It is for a caller that already holds a compiled DecodePlan for
this exact schema — see avro.cursor.PlanCache. Nothing else changes:
the schema is parsed on demand the moment anything needs it, so
next() and read_all() behave the same either way.
open
def open(path: StringSpan) -> Self Read the whole file, then parse its header.
from_bytes
def from_bytes(data: Span[UInt8]) -> Self ensure_schema
def ensure_schema(mut self) Parse avro.schema if a defer_schema=True open left it unparsed.
metadata_index
def metadata_index(self, key: StringSpan) -> Int Where key sits in metadata_keys/metadata_vals, or -1.
Span(reader.metadata_vals[i]) then reads the entry's raw bytes
without copying them.
A linear scan, and deliberately so: a file has a handful of metadata
entries, and this compares StringSlices rather than allocating a
String to hash the way a Dict lookup would.
metadata_string
def metadata_string(self, key: StringSpan) -> String A metadata entry decoded as UTF-8; "" when the key is absent.
has_metadata
def has_metadata(self, key: StringSpan) -> Bool metadata_map
def metadata_map(self) -> Dict[String, List[UInt8]] The metadata as a Dict, for callers that want that shape.
schema_json
def schema_json(self) -> String The schema exactly as the file spelled it.
has_next
def has_next(mut self) -> Bool next
def next(mut self) -> Value Decode the next record; raises when the file is exhausted.
read_all
def read_all(mut self) -> List[Value] count_blocks
def count_blocks(self) -> Int Walk every block header, without decompressing anything.
Independent of how far iteration has got: it re-reads the header and then strides over the blocks.