pub struct Writer { /* private fields */ }Expand description
A writer for the Lance v2.0 file grammar.
Implementations§
Source§impl Writer
impl Writer
Sourcepub fn try_new(
object_writer: Box<dyn ObjectWriter>,
schema: LanceSchema,
options: FileWriterOptions,
) -> Result<Self>
pub fn try_new( object_writer: Box<dyn ObjectWriter>, schema: LanceSchema, options: FileWriterOptions, ) -> Result<Self>
Create a new v2.0 writer with a desired output schema.
Sourcepub fn new_lazy(
object_writer: Box<dyn ObjectWriter>,
options: FileWriterOptions,
) -> Self
pub fn new_lazy( object_writer: Box<dyn ObjectWriter>, options: FileWriterOptions, ) -> Self
Create a new v2.0 writer without a desired output schema.
The output schema will be set based on the first batch of data to arrive. If no data arrives and the writer is finished then the write will fail.
Sourcepub fn with_page_metadata_spill(
self,
object_store: Arc<ObjectStore>,
path: Path,
) -> Self
pub fn with_page_metadata_spill( self, object_store: Arc<ObjectStore>, path: Path, ) -> Self
Spill page metadata to a sidecar file instead of accumulating in memory.
This can dramatically reduce memory usage when many writers are open
concurrently (e.g. IVF shuffle with thousands of partition writers).
The sidecar file is created lazily on the first page write. The caller
is responsible for cleaning up path (e.g. by placing it in a temp
directory that is removed via RAII).
Sourcepub async fn write_batches(
&mut self,
batches: impl Iterator<Item = &RecordBatch>,
) -> Result<()>
pub async fn write_batches( &mut self, batches: impl Iterator<Item = &RecordBatch>, ) -> Result<()>
Schedule batches of data to be written to the file
Sourcepub async fn write_batch(&mut self, batch: &RecordBatch) -> Result<()>
pub async fn write_batch(&mut self, batch: &RecordBatch) -> Result<()>
Schedule a batch of data to be written to the file
Note: the future returned by this method may complete before the data has been fully flushed to the file (some data may be in the data cache or the I/O cache)
Sourcepub async fn write_column(
&mut self,
column_index: usize,
array: ArrayRef,
) -> Result<()>
pub async fn write_column( &mut self, column_index: usize, array: ArrayRef, ) -> Result<()>
Write a single column, advancing only that column’s row counter.
Unlike write_batch, which advances every column
from a single shared row counter, this method advances one column
independently. Used across calls it produces a single file whose columns
may have different item counts.
column_index refers to a top-level field in the writer’s schema (the
same order as the schema’s fields); a nested child cannot be targeted on
its own. Because each call writes the whole field from a single array, the
children of a struct field always advance together and stay equal-length;
only different top-level fields can diverge in length. A column may be
written across multiple calls; its values are appended. A field that is
never written ends up as a zero-length column. The writer must have been
created with an explicit schema (via try_new); a lazy
schema cannot be inferred here because individual calls need not cover
every field.
// Field 0 gets three values, field 1 gets one — a non-rectangular file.
writer.write_column(0, Arc::new(Int32Array::from(vec![1, 2, 3]))).await?;
writer.write_column(1, Arc::new(Int32Array::from(vec![10]))).await?;Sourcepub fn add_schema_metadata(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
)
pub fn add_schema_metadata( &mut self, key: impl Into<String>, value: impl Into<String>, )
Add a metadata entry to the schema
This method is useful because sometimes the metadata is not known until after the
data has been written. This method allows you to alter the schema metadata. It
must be called before finish is called.
Sourcepub fn initialize_with_external_metadata(
&mut self,
schema: Schema,
column_metadata: Vec<ColumnMetadata>,
rows_written: u64,
)
pub fn initialize_with_external_metadata( &mut self, schema: Schema, column_metadata: Vec<ColumnMetadata>, rows_written: u64, )
Prepare the writer when column data and metadata were produced externally.
This is useful for flows that copy already-encoded pages (e.g., binary copy
during compaction) where the column buffers have been written directly and we
only need to write the footer and schema metadata. The provided
column_metadata must describe the buffers already persisted by the
underlying ObjectWriter, and rows_written should reflect the total number
of rows in those buffers.
Sourcepub async fn add_global_buffer(&mut self, buffer: Bytes) -> Result<u32>
pub async fn add_global_buffer(&mut self, buffer: Bytes) -> Result<u32>
Adds a global buffer to the file
The global buffer can contain any arbitrary bytes. It will be written to the disk immediately. This method returns the index of the global buffer (this will always start at 1 and increment by 1 each time this method is called)
Sourcepub async fn finish(&mut self) -> Result<FileWriteSummary>
pub async fn finish(&mut self) -> Result<FileWriteSummary>
Finishes writing the file
This method will wait until all data has been flushed to the file. Then it will write the file metadata and the footer. It will not return until all data has been flushed and the file has been closed.
Returns a summary of the completed file write.
pub async fn abort(&mut self)
pub async fn tell(&mut self) -> Result<u64>
Sourcepub async fn write_external_buffer(
&mut self,
bytes: &[u8],
) -> Result<(u64, u64)>
pub async fn write_external_buffer( &mut self, bytes: &[u8], ) -> Result<(u64, u64)>
Append a buffer whose metadata is supplied by the caller.
pub fn field_id_to_column_indices(&self) -> &[(u32, u32)]
Auto Trait Implementations§
impl !RefUnwindSafe for Writer
impl !Sync for Writer
impl !UnwindSafe for Writer
impl Freeze for Writer
impl Send for Writer
impl Unpin for Writer
impl UnsafeUnpin for Writer
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> 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