Writer

Struct Writer 

Source
pub struct Writer<W: Write, F: AvroFormat> {
    writer: W,
    schema: Arc<Schema>,
    format: F,
    compression: Option<CompressionCodec>,
    capacity: usize,
    encoder: RecordEncoder,
}
Expand description

Generic Avro writer.

This type is generic over the output Write sink (W) and the Avro format (F). You’ll usually use the concrete aliases:

Fields§

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

Implementations§

Source§

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

Source

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

Convenience constructor – same as WriterBuilder::build with AvroOcfFormat.

§Example
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());
Source

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

Return a reference to the 16‑byte sync marker generated for this file.

Source§

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

Source

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

Convenience constructor to create a new AvroStreamWriter.

The resulting stream contains just Avro binary bodies (no OCF header/sync and no single‑object or Confluent framing). If you need those frames, add them externally.

§Example
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());
Source§

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

Source

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

Serialize one [RecordBatch] to the output.

Source

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

A convenience method to write a slice of [RecordBatch].

This is equivalent to calling write for each batch in the slice.

Source

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

Flush remaining buffered data and (for OCF) ensure the header is present.

Source

pub fn into_inner(self) -> W

Consume the writer, returning the underlying output object.

Source

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

Source

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

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W, F> Freeze for Writer<W, F>
where W: Freeze, F: Freeze,

§

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

§

impl<W, F> Send for Writer<W, F>
where W: Send, F: Send,

§

impl<W, F> Sync for Writer<W, F>
where W: Sync, F: Sync,

§

impl<W, F> Unpin for Writer<W, F>
where W: Unpin, F: Unpin,

§

impl<W, F> UnwindSafe for Writer<W, F>
where W: UnwindSafe, F: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

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,