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
impl FeatherWriter
Sourcepub fn new(
directory: PathBuf,
clock: WriterClock,
rotation_config: RotationConfig,
included_types: Option<HashSet<CatalogDataType>>,
flush_interval_ms: Option<u64>,
) -> Self
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.
Sourcepub fn with_record_filter(
self,
record_filter: Option<WriterRecordFilter>,
) -> Self
pub fn with_record_filter( self, record_filter: Option<WriterRecordFilter>, ) -> Self
Sets typed record-family filter for subsequent writes.
Sourcepub fn write<T>(&mut self, data: T) -> Result<(), Box<dyn Error>>where
T: EncodeToRecordBatch + CatalogFamily + 'static,
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.
Sourcepub fn write_batch<T>(&mut self, data: Vec<T>) -> Result<(), Box<dyn Error>>where
T: EncodeToRecordBatch + CatalogFamily + 'static,
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.
Sourcepub fn flush(&mut self) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn seal(&mut self) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn close(&mut self) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns whether the writer has been closed (all writers cleared).
Sourcepub fn get_current_file_info(&self) -> HashMap<CatalogDataType, (u64, String)>
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.
Sourcepub fn get_next_rotation_time(
&self,
data_type: &CatalogDataType,
) -> Option<UnixNanos>
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.
Sourcepub fn write_data(&mut self, data: Data) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn write_data_batch(
&mut self,
data: Vec<Data>,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn write_any_message(
&mut self,
message: &dyn Any,
) -> Result<bool, Box<dyn Error>>
pub fn write_any_message( &mut self, message: &dyn Any, ) -> Result<bool, Box<dyn Error>>
Writes supported message bus value.
Sourcepub fn write_instrument(
&mut self,
instrument: InstrumentAny,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn subscribe_to_message_bus(
writer: Rc<RefCell<Self>>,
) -> Result<StreamingSinkSubscription, Box<dyn Error>>
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.
Sourcepub fn unsubscribe_from_message_bus(handler: &StreamingSinkSubscription)
pub fn unsubscribe_from_message_bus(handler: &StreamingSinkSubscription)
Unsubscribes from message bus.
Trait Implementations§
Source§impl Debug for FeatherWriter
impl Debug for FeatherWriter
Source§impl Drop for FeatherWriter
Drop contract: seals open files so their streams stay readable and promotable.
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.
Auto Trait Implementations§
impl !RefUnwindSafe for FeatherWriter
impl !UnwindSafe for FeatherWriter
impl Freeze for FeatherWriter
impl Send for FeatherWriter
impl Sync for FeatherWriter
impl Unpin for FeatherWriter
impl UnsafeUnpin for FeatherWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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