Class VortexWriter
- All Implemented Interfaces:
AutoCloseable
Open one with builder(Session, String, Schema, BufferAllocator) to write to a URI, or
builder(Session, NativeWritable, Schema, BufferAllocator) to write into a caller-provided byte sink.
Use writeBatch(VectorSchemaRoot, BufferAllocator) for zero-copy Java batches with independent buffer
lifetimes. Batches are also accepted via the Arrow C Data Interface: callers export an Arrow record batch to an
ArrowArray / ArrowSchema pair and pass the addresses to writeBatch(long, long), or export
only the ArrowArray and pass its address to writeBatch(long). The writer accepts up to four
in-flight batches on the session's runtime thread before back-pressuring the caller.
Call close() to flush remaining batches and finalize the file. Call finish(Map) instead to add
metadata segments that are known only after the last batch, for example a bloom filter of the written keys.
If the writer becomes unreachable without an explicit close(), VortexCleaner will flush and
release native resources as a backstop — but callers should always finalize explicitly so that I/O errors surface
through the normal call path.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionlongReturn the number of compressed bytes that the writer holds and did not write to the sink yet.static VortexWriter.Builderbuilder(Session session, NativeWritable writable, org.apache.arrow.vector.types.pojo.Schema arrowSchema, org.apache.arrow.memory.BufferAllocator allocator) Start configuring a writer that streams the file into a caller-provided byte sink instead of a native storage client.static VortexWriter.Builderbuilder(Session session, String uri, org.apache.arrow.vector.types.pojo.Schema arrowSchema, org.apache.arrow.memory.BufferAllocator allocator) Start configuring a writer that streams records into the file aturithrough a native storage client.longReturn the number of bytes successfully written to the underlying sink so far.voidclose()Flush any pending batches and finalize the file.doubleReturn the compressed bytes divided by the uncompressed bytes over the data that the writer compressed so far.longReturn an estimate of the size of the file if the writer finished now.finish()Flush pending batches, finalize the file, and return its statistics and physical sizes.Flush pending batches, addmetadatato the file footer, finalize the file, and return its statistics and physical sizes.voidwriteBatch(long arrowArrayAddr) Write a batch from an Arrow C Data Interface array.voidwriteBatch(long arrowArrayAddr, long arrowSchemaAddr) Write a batch directly from Arrow C Data Interface addresses.voidwriteBatch(org.apache.arrow.vector.VectorSchemaRoot root, org.apache.arrow.memory.BufferAllocator allocator) Write a Java Arrow batch without copying its data.
-
Method Details
-
builder
public static VortexWriter.Builder builder(Session session, String uri, org.apache.arrow.vector.types.pojo.Schema arrowSchema, org.apache.arrow.memory.BufferAllocator allocator) Start configuring a writer that streams records into the file aturithrough a native storage client. The path may be a full URI or a plain local filesystem path.- Parameters:
arrowSchema- describes the exact layout of every batch written
-
builder
public static VortexWriter.Builder builder(Session session, NativeWritable writable, org.apache.arrow.vector.types.pojo.Schema arrowSchema, org.apache.arrow.memory.BufferAllocator allocator) Start configuring a writer that streams the file into a caller-provided byte sink instead of a native storage client. This is the integration point for external I/O abstractions (for example Iceberg'sPositionOutputStream).The native side writes and flushes the sink but never closes it: after
close()returns, all bytes have been written and flushed, and the caller must close the sink to finalize the file.- Parameters:
arrowSchema- describes the exact layout of every batch written
-
writeBatch
public void writeBatch(org.apache.arrow.vector.VectorSchemaRoot root, org.apache.arrow.memory.BufferAllocator allocator) throws IOException Write a Java Arrow batch without copying its data. Native buffers retain their allocations independently, so a retained column does not pin the entire batch. The caller may close or clear the root after this method returns, but must not overwrite its retained buffers.- Parameters:
root- batch to write; dictionary-encoded fields require the address-based APIallocator- allocator for temporary C Data Interface metadata- Throws:
IOException
-
writeBatch
Write a batch directly from Arrow C Data Interface addresses. Native code takes both the array and the schema, and releases them. These buffers share the producer's batch release callback; usewriteBatch(VectorSchemaRoot, BufferAllocator)for independently retained Java allocations.- Throws:
IOException
-
writeBatch
Write a batch from an Arrow C Data Interface array. Native code imports it with the schema of this writer.The array must be a struct array that agrees with the writer schema. Native code rejects incorrect buffer or child counts with an
IOException, but it cannot find all type mismatches (for exampleInt64in the place ofInt32), and such an array can cause incorrect data or a crash.Native code takes the array struct and releases it, also when the call fails.
- Parameters:
arrowArrayAddr- address of an exportedArrowArraystruct- Throws:
IOException
-
bytesWritten
public long bytesWritten()Return the number of bytes successfully written to the underlying sink so far.This count does not include queued batches or data still buffered by layout strategies, so it may lag the amount of input accepted by
writeBatch(long, long). Afterfinish(), it is the exact completed file size and is equal toVortexWriteSummary.fileSize(). -
bufferedBytes
public long bufferedBytes()Return the number of compressed bytes that the writer holds and did not write to the sink yet.The count includes the compressed data that layout strategies hold and the compressed segments that wait for earlier segments. It does not include the data that the writer did not compress yet, such as queued batches and the data that the writer coalesces before compression. Use
estimatedSize()for an estimate of the file size. Afterfinish(), this is zero. -
estimatedSize
public long estimatedSize()Return an estimate of the size of the file if the writer finished now.The estimate is
bytesWritten(), plusbufferedBytes(), plus the bytes that the writer accepted but did not compress yet multiplied bycompressionRatio(). The uncompressed bytes include the queued batches, the data that the writer coalesces before compression, and the chunks that are being compressed. The estimate does not include the footer.Use this to roll files at a target size. The estimate goes up as batches are written, and it can go down a small amount when the measured compression ratio changes. After
finish(), it is the exact completed file size and is equal toVortexWriteSummary.fileSize(). -
compressionRatio
public double compressionRatio()Return the compressed bytes divided by the uncompressed bytes over the data that the writer compressed so far.Before the writer compresses its first full chunk, the ratio comes from the small probes that the writer compresses to choose encodings. Before any compression, the ratio is
1.0. Multiply the uncompressed size of data that the caller holds by this ratio to estimate its compressed size. Afterfinish(), this is the ratio that the writer measured beforefinish()started. -
finish
Flush pending batches, finalize the file, and return its statistics and physical sizes.This method is idempotent. Later calls return the same immutable summary.
- Throws:
IOException
-
finish
Flush pending batches, addmetadatato the file footer, finalize the file, and return its statistics and physical sizes.The segments merge with the segments from
VortexWriter.Builder.metadata(Map), and a key inmetadatareplaces the builder segment with the same key. The native limits apply to the merged set.This method is not idempotent: a call after the writer is finished or closed throws
IllegalStateException.- Parameters:
metadata- the segments to add; keys and values must not be null- Throws:
IllegalStateException- if the writer is already finished or closedIOException- if the file cannot be finalized
-
close
Flush any pending batches and finalize the file. Idempotent.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-