Skip to main content

@math.gl/core/arrow

Apache Arrow

@math.gl/core/arrow provides utilities for working with binary columnar tabular data in the Apache Arrow format.

Usageโ€‹

import * as arrow from 'apache-arrow';
import {IndexedArrowTable, dehydrateArrowTable, hydrateArrowTable} from '@math.gl/core/arrow';

const arrowTable = arrow.tableFromArrays({name: ['alpha', 'beta'], score: [10, 20]});
const selected = new IndexedArrowTable(arrowTable, [1, 0, 1]);
selected.getValue(0, 'name'); // 'beta'

const payload = dehydrateArrowTable(selected.materializeArrowTable(), {copy: 'all'});
const restored = hydrateArrowTable(structuredClone(payload));
restored.numRows; // 3

Featuresโ€‹

FeatureSupportNotes
Indexed tables and vectorsโœ…Filter, sort, slice, and gather rows while controlling materialization.
Schema validation and column renamingโœ…Preserve field metadata and compatible physical buffers.
Buffer copying and transportโœ…Explicit ownership, hydration/dehydration, and Arrow IPC.
Apache Arrow versionsโœ…Optional peer supporting 17+; compatibility checks exercise 17โ€“21.
Independent utility entriesโœ…Matrix, color, and UTF-8 entry points work without Apache Arrow.
Projection and geographic calculationsSeparateUse @math.gl/geospatial; CRS metadata remains opaque here.

Why Arrow in math.gl?โ€‹

The vis.gl frameworks are designed to seamlessly produce, interchange, and process binary data in Arrow format. These shared utilities provide schema validation, column renaming, indexed table views, and table transport across those frameworks.

Geometry and GeoArrow processing are available in @math.gl/core/arrow.

Installationโ€‹

npm install @math.gl/core apache-arrow

Apache Arrow is an optional peer dependency, supporting version 17 and newer. Your application supplies one compatible Arrow installation. The combined @math.gl/core/arrow entry point requires Arrow, including its GeoArrow and WKB exports. Matrix, color, and UTF-8 entry points do not require Arrow. Compatibility checks exercise Arrow 17โ€“21 and cross-version IPC.

Entry pointsโ€‹

ImportPurposeApache Arrow required
@math.gl/core/arrowArrow table/vector views, schemas, copying, and transportYes, 17+
@math.gl/core/utf8Byte-oriented string comparison and scalar parsingNo
@math.gl/core/arrowArrow-native GeoArrow adapters and processingYes, 17+
@math.gl/core/arrowPhysical descriptors, geometry kernels, codecs, and streamsYes, 17+
@math.gl/core/arrowWKB/EWKB and WKT parsing, writing, and traversalYes, 17+

CRS metadata is retained opaquely; interpretation, projection, and geographic calculations belong in @math.gl/geospatial. Task scheduling is provided by the separate @math.gl/tasks package.

API referenceโ€‹

APIPurpose
IndexedArrowTable and IndexedArrowVectorFilter, sort, slice, and reorder rows without immediately copying column values.
MappedArrowTableAdd string-keyed lookup while retaining indexed transforms.
Schema utilitiesValidate field structure and rename columns while retaining buffers.
splitArrowBuffersControl ownership of Arrow internal typed-array buffers.
Table transportHydrate/dehydrate column buffers or encode/decode full Arrow IPC.

The table views are read-only APIs, not deeply immutable snapshots. Treat their backing tables, index arrays, and maps as immutable while views are in use. Transport payloads are a math.gl protocol, not loaders.gl table wrappers.

Column projectionโ€‹

Use projectArrowTable(table, selections) to select and reorder top-level columns, with optional aliases. The returned table shares the original column buffers and retains field, schema, and batch metadata. Passing an empty selection keeps the original row count.

import {projectArrowTable} from '@math.gl/core/arrow';

const projected = projectArrowTable(arrowTable, [
{column: 'score', as: 'value'},
'name'
]);

Column inspectionโ€‹

Use isArrowTable(value) and isArrowRecordBatch(value) to narrow an unknown value to an Apache Arrow Table or RecordBatch. Both guards recognize native Arrow values from different package copies. findArrowColumn(table, ['feature', 'position']) looks up a nested column and returns null if the path is missing. Pass a single segment to look up a literal field name that contains a dot. isNumericArrowType and isFixedSizeListArrowType inspect schema types without reading column values.

WKT header inspectionโ€‹

Use inspectWKTHeader(text) to read the root geometry type, declared Z/M dimension, and optional EWKT SRID. It returns null for unrecognized headers and does not parse coordinates or infer the dimensions of unmarked tuples.

Reading UTF-8 without decodingโ€‹

createArrowUtf8Reader(vector) reads Utf8, LargeUtf8 and dictionary-encoded text across chunk boundaries. A null value or invalid row index returns null. An empty string returns a range with equal start and end offsets. The reader reuses its result tuple. Destructure it before reading another row.

import {createArrowUtf8Reader} from '@math.gl/core/arrow';

const readLabel = createArrowUtf8Reader(labels);
const range = readLabel(0);
if (range) {
const [bytes, start, end] = range;
console.log(bytes.subarray(start, end));
}