Class ColumnWriter

java.lang.Object
dev.hardwood.writer.ColumnWriter

public final class ColumnWriter extends Object

Writes a Parquet file one aligned batch of columns at a time.

This is the columnar API: the shape for a caller that already holds columns — a query engine, an Arrow buffer, a bulk converter. Values are handed over as typed arrays addressed by leaf index or leaf path, an OPTIONAL column carrying its nulls as a Validity alongside them, and the writer shreds, pages, encodes and compresses them into the file.

try (ParquetFileWriter writer = ParquetFileWriter.create(out, schema)) {
    ColumnWriter columns = writer.columnWriter();
    columns.writeBatch(batch -> batch
            .longs("id", ids)
            .doubles("price", prices, priceNulls));
}

A ColumnWriter is not closeable: the ParquetFileWriter it came from owns the file, and closing it flushes the row group still buffered here along with the footer. ParquetFileWriter.endRowGroup() ends a row group where the caller places the boundary.

  • Method Details

    • writeBatch

      public void writeBatch(Consumer<ColumnBatch> filler) throws IOException

      Writes one aligned batch of column values, flushing row groups as the buffered data crosses the row-group target. A batch that would overflow the current row group is split at the boundary.

      The writer creates the batch — bound to the schema — passes it to filler to be populated (columns addressed by index or name), then submits it. There is no separate build or submit step to forget.

      Any exception fails the writer, whether the batch is rejected, its filler throws, or it cannot be written: the writer accepts no more data, and ParquetFileWriter.close() discards the output.

      Parameters:
      filler - populates the batch's columns; must cover every column exactly once
      Throws:
      IOException - if the write fails
      IllegalArgumentException - if the batch does not cover every column, its per-layer inputs do not agree on a record count, or one record's values for a column are more than a column chunk can hold
      UnsupportedOperationException - if the schema has a shape the writer cannot produce
      IllegalStateException - if the writer is closed, or a previous write has failed