ReaderBuilder

结构体 ReaderBuilder 

源代码
pub struct ReaderBuilder {
    batch_size: usize,
    strict_mode: bool,
    utf8_view: bool,
    reader_schema: Option<AvroSchema>,
    writer_schema_store: Option<SchemaStore>,
    active_fingerprint: Option<Fingerprint>,
}
展开描述

一个用于配置和构建 Avro 读取器和解码器的构建器。

ReaderBuilder 是此模块的主要入口点。它支持

  • 通过 Self::build 进行 OCF 读取,返回任何 BufRead 上的 Reader
  • 通过 Self::build_decoder 进行流式解码,返回一个 Decoder

§选项

  • batch_size: 每个 RecordBatch 的最大行数(默认值:1024)。请参见 Self::with_batch_size
  • utf8_view: 对字符串列使用 Arrow StringViewArray(默认值:false)。请参见 Self::with_utf8_view
  • strict_mode: 启用更严格的联合处理(默认值:false)。请参见 Self::with_strict_mode
  • reader_schema: 解码值时使用的可选读取器模式(投影/演进)(默认值:None)。请参见 Self::with_reader_schema
  • writer_schema_store: 构建用于单对象或 Confluent 帧的 Decoder 所必需。将指纹映射到 Avro 模式。请参见 Self::with_writer_schema_store
  • active_fingerprint: 当第一个帧省略指纹时(罕见),用于流式解码的可选起始指纹。请参见 Self::with_active_fingerprint

§示例

以 4096 行的批次读取 OCF 文件

use std::fs::File;
use std::io::BufReader;
use arrow_avro::reader::ReaderBuilder;

let file = File::open("data.avro")?;
let mut reader = ReaderBuilder::new()
    .with_batch_size(4096)
    .build(BufReader::new(file))?;

为 Confluent 消息构建一个 Decoder

use arrow_avro::schema::{AvroSchema, SchemaStore, Fingerprint, FingerprintAlgorithm};
use arrow_avro::reader::ReaderBuilder;

let mut store = SchemaStore::new_with_type(FingerprintAlgorithm::Id);
store.set(Fingerprint::Id(1234), AvroSchema::new(r#"{"type":"record","name":"E","fields":[]}"#.to_string()))?;

let decoder = ReaderBuilder::new()
    .with_writer_schema_store(store)
    .build_decoder()?;

字段§

§batch_size: usize§strict_mode: bool§utf8_view: bool§reader_schema: Option<AvroSchema>§writer_schema_store: Option<SchemaStore>§active_fingerprint: Option<Fingerprint>

实现§

§

impl ReaderBuilder

源代码

pub fn new() -> Self

使用默认值创建一个新的 ReaderBuilder

  • batch_size = 1024
  • strict_mode = false
  • utf8_view = false
  • reader_schema = None
  • writer_schema_store = None
  • active_fingerprint = None
源代码

fn make_record_decoder( &self, writer_schema: &Schema<'_>, reader_schema: Option<&Schema<'_>>, ) -> Result<RecordDecoder, ArrowError>

源代码

fn make_record_decoder_from_schemas( &self, writer_schema: &Schema<'_>, reader_schema: Option<&AvroSchema>, ) -> Result<RecordDecoder, ArrowError>

源代码

fn make_decoder_with_parts( &self, active_decoder: RecordDecoder, active_fingerprint: Option<Fingerprint>, cache: IndexMap<Fingerprint, RecordDecoder>, fingerprint_algorithm: FingerprintAlgorithm, ) -> Decoder

源代码

fn make_decoder( &self, header: Option<&Header>, reader_schema: Option<&AvroSchema>, ) -> Result<Decoder, ArrowError>

源代码

pub fn with_batch_size(self, batch_size: usize) -> Self

设置基于行的批处理大小

每次调用 Decoder::flush 或每次 Reader 迭代都会生成一个包含最多此行数的批次。较大的批次可以减少开销;较小的批次可以减少峰值内存使用和延迟。

源代码

pub fn with_utf8_view(self, utf8_view: bool) -> Self

为 UTF‑8 字符串数据选择 Arrow 的 StringViewArray

启用后,文本 Avro 字段将加载到 Arrow 的 StringViewArray 中,而不是标准的 StringArray。这可以通过减少分配来提高处理许多短字符串的工作负载的性能。

源代码

pub fn use_utf8view(&self) -> bool

返回是否为字符串数据启用了 StringViewArray

源代码

pub fn with_strict_mode(self, strict_mode: bool) -> Self

对某些 Avro 联合(例如 [T, "null"])启用更严格的行为。

true 时,原本会被强制转换的模糊或有损联合可能会改为产生描述性错误。使用此选项可在摄取早期捕获模式问题。

源代码

pub fn with_reader_schema(self, schema: AvroSchema) -> Self

设置解码期间使用的读取器模式

如果未提供,则直接使用 OCF 头部中的写入器模式(对于 Reader)或从指纹查找的模式(对于 Decoder)。

读取器模式可用于模式演进投影

源代码

pub fn with_writer_schema_store(self, store: SchemaStore) -> Self

设置用于通过指纹解析写入器模式的 SchemaStore

在构建用于单对象编码Confluent 线格式的 Decoder 时,这是必需的。该存储将指纹(Rabin / MD5 / SHA‑256 / ID)映射到完整的 Avro 模式。

默认为 None

源代码

pub fn with_active_fingerprint(self, fp: Fingerprint) -> Self

设置流式解码的初始模式指纹。

这对于在第一个记录主体之前不包含指纹的流(不常见)很有用。如果未设置,则使用第一个观察到的指纹。

源代码

pub fn build<R: BufRead>(self, reader: R) -> Result<Reader<R>, ArrowError>

从此构建器和 BufRead 构建一个 Reader (OCF)。

这将读取并验证 OCF 头部,使用发现的写入器(和可选的读取器)模式初始化内部行解码器,并准备迭代块,如有必要进行解压缩。

源代码

pub fn build_decoder(self) -> Result<Decoder, ArrowError>

从此构建器构建一个流式 Decoder

§要求
  • 必须通过 Self::with_writer_schema_store 提供 SchemaStore
  • 存储应包含流中可能出现的所有指纹。
§错误
  • 如果缺少模式存储,则返回 [ArrowError::InvalidArgumentError]

Trait 实现§

§

impl Debug for ReaderBuilder

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

使用给定的格式化程序格式化值。 阅读更多
§

impl Default for ReaderBuilder

§

fn default() -> Self

返回某个类型的“默认值”。阅读更多

自动 Trait 实现§

通用实现§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

获取 selfTypeId阅读更多
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

从拥有的值进行不可变借用。 阅读更多
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

从拥有的值进行可变借用。 阅读更多
§

impl<T> From<T> for T

§

fn from(t: T) -> T

返回未更改的参数。

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

调用 U::from(self)

也就是说,此转换是 From<T> for U 的实现选择执行的任何操作。

§

impl<T> Same for T

§

type Output = T

应该总是 Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

转换错误时返回的类型。
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

执行转换。
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

转换错误时返回的类型。
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

执行转换。
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,