Skip to main content

Arrow writer

Apache Software Foundation

ArrowWriter

ArrowWriter turns typed arrays and table-oriented data into Apache Arrow IPC bytes. Use it when a result should remain columnar across files, streams, workers, or another language.

Portable output

One application shape. Many destinations.

Writers keep encoding at the edge of the pipeline. Prepare a documented category shape, choose the destination format, and let that writer own its physical layout and compression.

The application chooses the data shape; the writer chooses the bytes.

Encode once, reuse elsewhere

Keep types and column boundaries intact.

The writer accepts table-oriented arrays and emits an IPC representation that Arrow readers can consume. The output can be saved, streamed, or passed to another loaders.gl pipeline.

Input

Typed arrays, dates, strings, and Arrow-compatible fields

Output

Apache Arrow IPC ArrayBuffer data

Use with

encode, writeFile, workers, and table sources

Next step

Read with ArrowLoader or any Arrow implementation

From-v3.0

The ArrowWriter encodes a set of arrays into an Apache Arrow IPC stream or file. The file container is Feather V2 and can optionally use LZ4-frame or Zstandard embedded buffer compression.

Detailed guide

ArrowWriter options and shapes

The sections below cover usage, input arrays, options, and the resulting Arrow IPC data.

Usage​

import {encodeSync} from '@loaders.gl/core';
import {ArrowWriter, VECTOR_TYPES} from '@loaders.gl/tables/arrow';

const LENGTH = 2000;

const rainAmounts = Float32Array.from({length: LENGTH}, () =>
Number((Math.random() * 20).toFixed(1))
);

const rainDates = Array.from(
{length: LENGTH},
(_, i) => new Date(Date.now() - 1000 * 60 * 60 * 24 * i)
);

const arraysData = [
{array: rainAmounts, name: 'precipitation', type: VECTOR_TYPES.FLOAT},
{array: rainDates, name: 'date', type: VECTOR_TYPES.DATE}
];

const arrayBuffer = encodeSync(arraysData, ArrowWriter);

To write a compressed Feather V2 file:

import {encode} from '@loaders.gl/core';

const featherBuffer = await encode(arraysData, ArrowWriter, {
arrow: {
container: 'file',
compression: 'zstd'
}
});

LZ4 and Zstandard encoding use compress-utils. Async encode() preloads the requested codec. Call it once before using encodeSync() with that codec; no external module injection is needed.

Options​

OptionTypeDefaultDescription
arrow.container'stream' | 'file''stream'Selects the Arrow IPC stream or file container. Feather V2 uses 'file'.
arrow.compressionnull | 'lz4' | 'zstd'nullSelects embedded record-batch buffer compression. Compression requires Apache Arrow JS 21.2 or later.

The input arrays determine the Arrow field names and types; use the exported VECTOR_TYPES constants when constructing the input.

Dependencies​

Apache Arrow JS library is included into the bundle.

Compression uses the default compress-utils codecs from @loaders.gl/compression.