Skip to main content

FeatherWriter

Struct FeatherWriter 

Source
pub struct FeatherWriter { /* private fields */ }
Expand description

Streams encoded data into one local Feather file per data or record type, and per class for instruments.

Rows of every identifier share their type’s file. Each row carries its catalog identifier and the Arrow metadata it was encoded with, such as its instrument’s precision, so readers restore per-row metadata the file schema cannot hold.

The Self::write method accepts a data value of generic type T, encodes it using T’s metadata via EncodeToRecordBatch, routes it by CatalogFamily, and appends it to that key’s open file.

§File Lifecycle

Open files are tracked by their final .feather paths, while writes go to .feather.partial files. Sealing completes the stream and renames the partial file to its final path. A file is sealed and replaced only on rotation, Self::seal, or Self::close.

§Flushing

Self::flush pushes buffered bytes to disk without starting a new file. flush_interval_ms controls automatic flushing in milliseconds; 0 disables automatic flushing.

Implementations§

Source§

impl FeatherWriter

Source

pub fn new( directory: PathBuf, clock: WriterClock, rotation_config: RotationConfig, included_types: Option<HashSet<CatalogDataType>>, flush_interval_ms: Option<u64>, ) -> Self

Creates a new FeatherWriter instance.

Source

pub fn with_record_filter( self, record_filter: Option<WriterRecordFilter>, ) -> Self

Sets typed record-family filter for subsequent writes.

Source

pub fn write<T>(&mut self, data: T) -> Result<(), Box<dyn Error>>
where T: EncodeToRecordBatch + CatalogFamily + 'static,

Writes a single data value.

This is the user entry point. The data is encoded into a RecordBatch and appended to the open file for its type, or for its class when the data is an instrument.

Source

pub fn write_batch<T>(&mut self, data: Vec<T>) -> Result<(), Box<dyn Error>>
where T: EncodeToRecordBatch + CatalogFamily + 'static,

Writes a batch of data values as one or more RecordBatches.

Uses T::chunk_metadata to derive the file schema metadata. This protects types like OrderBookDelta from having their file metadata poisoned by a leading sentinel row (e.g. BookAction::Clear, which carries price_precision=0, size_precision=0).

Rows are grouped by identifier so each group encodes with its own metadata before it is appended to the type’s file.

Source

pub fn flush(&mut self) -> Result<(), Box<dyn Error>>

Flushes buffered bytes of every open file to disk.

This is called automatically based on flush_interval_ms if configured, but can also be called manually by the client. Files stay open, so flushing never starts a new file.

Source

pub fn seal(&mut self) -> Result<(), Box<dyn Error>>

Seals every open file so its complete stream is visible as a .feather file.

Writes after sealing open new files, so this is the boundary promotion uses.

Source

pub fn close(&mut self) -> Result<(), Box<dyn Error>>

Seals all open files and reports any write error recorded since the last flush.

Writes after closing open new files.

Source

pub fn is_closed(&self) -> bool

Returns whether the writer has been closed (all writers cleared).

Source

pub fn get_current_file_info(&self) -> HashMap<CatalogDataType, (u64, String)>

Returns the current file size and path of each open file, keyed by the type it stages.

Source

pub fn get_next_rotation_time( &self, data_type: &CatalogDataType, ) -> Option<UnixNanos>

Returns the next rotation time of the file staging data_type, if set.

Each instrument class stages its own file, so pass CatalogDataType::Instrument.

Source

pub fn write_data(&mut self, data: Data) -> Result<(), Box<dyn Error>>

Writes a Data enum value to the appropriate writer.

This is a convenience method that routes the Data enum to the appropriate typed write method.

Source

pub fn write_data_batch( &mut self, data: Vec<Data>, ) -> Result<(), Box<dyn Error>>

Writes mixed data as typed Arrow batches.

§Panics

Panics if the built-in data batch dispatch becomes non-exhaustive.

Source

pub fn write_any_message( &mut self, message: &dyn Any, ) -> Result<bool, Box<dyn Error>>

Writes supported message bus value.

Source

pub fn write_instrument( &mut self, instrument: InstrumentAny, ) -> Result<(), Box<dyn Error>>

Writes an instrument to the appropriate writer.

Each instrument class stages its own file, and every row carries its instrument ID.

Source

pub fn subscribe_to_message_bus( writer: Rc<RefCell<Self>>, ) -> Result<StreamingSinkSubscription, Box<dyn Error>>

Subscribes to all messages on the message bus (pattern “*”).

This will automatically write all supported data types that are published on the message bus to the feather files.

The writer must be wrapped in Rc<RefCell<>> to be shareable with the message bus handler.

Note: Writes are synchronous local file appends.

Source

pub fn unsubscribe_from_message_bus(handler: &StreamingSinkSubscription)

Unsubscribes from message bus.

Trait Implementations§

Source§

impl Debug for FeatherWriter

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for FeatherWriter

Drop contract: seals open files so their streams stay readable and promotable.

Errors are logged, never raised. Call FeatherWriter::close for deterministic sealing.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl StreamingSink for FeatherWriter

Source§

fn write_data(&mut self, data: Data) -> Result<()>

Writes a single Data enum value. Read more
Source§

fn write_batch(&mut self, data: Vec<Data>) -> Result<()>

Writes a batch of Data values. Read more
Source§

fn write_any(&mut self, message: &dyn Any) -> Result<bool>

Writes any supported Nautilus message value. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes buffered data to durable storage. Read more
Source§

fn close(&mut self) -> Result<()>

Closes sink after flushing buffered data. Read more

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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<T> Ungil for T
where T: Send,

§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more