Class VortexWriter

java.lang.Object
dev.vortex.api.VortexWriter
All Implemented Interfaces:
AutoCloseable

public final class VortexWriter extends Object implements AutoCloseable
Writer for Vortex files.

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
    Modifier and Type
    Class
    Description
    static final class 
    Configures and opens a VortexWriter.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Return the number of compressed bytes that the writer holds and did not write to the sink yet.
    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.
    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 at uri through a native storage client.
    long
    Return the number of bytes successfully written to the underlying sink so far.
    void
    Flush any pending batches and finalize the file.
    double
    Return the compressed bytes divided by the uncompressed bytes over the data that the writer compressed so far.
    long
    Return an estimate of the size of the file if the writer finished now.
    Flush pending batches, finalize the file, and return its statistics and physical sizes.
    finish(Map<String,byte[]> metadata)
    Flush pending batches, add metadata to the file footer, finalize the file, and return its statistics and physical sizes.
    void
    writeBatch(long arrowArrayAddr)
    Write a batch from an Arrow C Data Interface array.
    void
    writeBatch(long arrowArrayAddr, long arrowSchemaAddr)
    Write a batch directly from Arrow C Data Interface addresses.
    void
    writeBatch(org.apache.arrow.vector.VectorSchemaRoot root, org.apache.arrow.memory.BufferAllocator allocator)
    Write a Java Arrow batch without copying its data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 at uri through 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's PositionOutputStream).

      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 API
      allocator - allocator for temporary C Data Interface metadata
      Throws:
      IOException
    • writeBatch

      public void writeBatch(long arrowArrayAddr, long arrowSchemaAddr) throws IOException
      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; use writeBatch(VectorSchemaRoot, BufferAllocator) for independently retained Java allocations.
      Throws:
      IOException
    • writeBatch

      public void writeBatch(long arrowArrayAddr) throws IOException
      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 example Int64 in the place of Int32), 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 exported ArrowArray struct
      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). After finish(), it is the exact completed file size and is equal to VortexWriteSummary.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. After finish(), 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(), plus bufferedBytes(), plus the bytes that the writer accepted but did not compress yet multiplied by compressionRatio(). 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 to VortexWriteSummary.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. After finish(), this is the ratio that the writer measured before finish() started.

    • finish

      public VortexWriteSummary finish() throws IOException
      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

      public VortexWriteSummary finish(Map<String,byte[]> metadata) throws IOException
      Flush pending batches, add metadata to 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 in metadata replaces 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 closed
      IOException - if the file cannot be finalized
    • close

      public void close() throws IOException
      Flush any pending batches and finalize the file. Idempotent.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException