Writer

结构体 Writer 

源代码
pub struct Writer<W: Write, F: AvroFormat> {
    writer: W,
    schema: Arc<Schema>,
    format: F,
    compression: Option<CompressionCodec>,
    capacity: usize,
    encoder: RecordEncoder,
}
展开描述

通用 Avro 写入器。

此类型是关于输出写入器 (W) 和 Avro 格式 (F) 的泛型。你通常会使用具体的别名:

字段§

§writer: W§schema: Arc<Schema>§format: F§compression: Option<CompressionCodec>§capacity: usize§encoder: RecordEncoder

实现§

§

impl<W: Write> Writer<W, AvroOcfFormat>

源代码

pub fn new(writer: W, schema: Schema) -> Result<Self, ArrowError>

便捷构造函数 – 与使用 AvroOcfFormatWriterBuilder::build 相同。

§示例
use std::sync::Arc;
use arrow_array::{ArrayRef, Int32Array, RecordBatch};
use arrow_schema::{DataType, Field, Schema};
use arrow_avro::writer::AvroWriter;

let schema = Schema::new(vec![Field::new("id", DataType::Int32, false)]);
let batch = RecordBatch::try_new(
    Arc::new(schema.clone()),
    vec![Arc::new(Int32Array::from(vec![1, 2, 3])) as ArrayRef],
)?;

let buf: Vec<u8> = Vec::new();
let mut w = AvroWriter::new(buf, schema)?;
w.write(&batch)?;
w.finish()?;
let bytes = w.into_inner();
assert!(!bytes.is_empty());
源代码

pub fn sync_marker(&self) -> Option<&[u8; 16]>

返回为此文件生成的 16 字节同步标记的引用。

§

impl<W: Write> Writer<W, AvroSoeFormat>

源代码

pub fn new(writer: W, schema: Schema) -> Result<Self, ArrowError>

创建新的 AvroStreamWriter 的便捷构造函数。

生成的流包含 单一对象编码(无 OCF 头部/同步)。

§示例
use std::sync::Arc;
use arrow_array::{ArrayRef, Int64Array, RecordBatch};
use arrow_schema::{DataType, Field, Schema};
use arrow_avro::writer::AvroStreamWriter;

let schema = Schema::new(vec![Field::new("x", DataType::Int64, false)]);
let batch = RecordBatch::try_new(
    Arc::new(schema.clone()),
    vec![Arc::new(Int64Array::from(vec![10, 20])) as ArrayRef],
)?;

let sink: Vec<u8> = Vec::new();
let mut w = AvroStreamWriter::new(sink, schema)?;
w.write(&batch)?;
w.finish()?;
let bytes = w.into_inner();
assert!(!bytes.is_empty());
§

impl<W: Write, F: AvroFormat> Writer<W, F>

源代码

pub fn write(&mut self, batch: &RecordBatch) -> Result<(), ArrowError>

将一个 [RecordBatch] 序列化到输出。

源代码

pub fn write_batches( &mut self, batches: &[&RecordBatch], ) -> Result<(), ArrowError>

一个方便的方法,用于写入 [RecordBatch] 的切片。

这等同于对切片中的每个批次调用 write

源代码

pub fn finish(&mut self) -> Result<(), ArrowError>

刷新剩余的缓冲数据,并(对于 OCF)确保存在头部。

源代码

pub fn into_inner(self) -> W

消耗写入器,返回底层输出对象。

源代码

fn write_ocf_block( &mut self, batch: &RecordBatch, sync: &[u8; 16], ) -> Result<(), ArrowError>

源代码

fn write_stream(&mut self, batch: &RecordBatch) -> Result<(), ArrowError>

Trait 实现§

§

impl<W: Debug + Write, F: Debug + AvroFormat> Debug for Writer<W, F>

§

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

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

自动 Trait 实现§

§

impl<W, F> Freeze for Writer<W, F>
其中 W: Freeze, F: Freeze,

§

impl<W, F> RefUnwindSafe for Writer<W, F>

§

impl<W, F> Send for Writer<W, F>
其中 W: Send, F: Send,

§

impl<W, F> Sync for Writer<W, F>
其中 W: Sync, F: Sync,

§

impl<W, F> Unpin for Writer<W, F>
其中 W: Unpin, F: Unpin,

§

impl<W, F> UnwindSafe for Writer<W, F>
其中 W: UnwindSafe, F: UnwindSafe,

通用实现§

§

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,