Arrow Table Conversion
Universal Arrow-to-GPU Planning​
planArrowGPUConversion() and convertArrowToGPUVector() are the common
schema-to-storage boundary for Arrow-backed GPU inputs. The planner is side-effect
free. It reports the selected semantic family, physical strategy, execution
backend, source and target formats, preserved chunk count, estimated bytes and
passes, ownership, reasons, and lossy-conversion warnings before any GPU resource
is allocated.
import {convertArrowToGPUVector, planArrowGPUConversion} from '@luma.gl/graph/arrow';
const plan = planArrowGPUConversion(device, sourceVector, {
semantic: 'color',
format: 'unorm8x4'
});
const prepared = await convertArrowToGPUVector(device, sourceVector, {
name: 'instanceColors',
semantic: 'color',
format: 'unorm8x4'
});
// prepared.vector is ready for a GPU table or model.
prepared.destroy();
The planner selects among:
- zero-copy borrowing when an input
GPUVectoralready has the exact format; - direct Arrow upload when the physical bytes already match;
- reinterpret upload when only GPU normalization metadata changes, such as
Uint8x4tounorm8x4; - chunk-preserving numeric conversion for bit-packed Boolean, 64-bit numeric, normalized, and format-changing scalar/list inputs;
- semantic color, temporal, and matrix conversion using their specialized conversion implementations.
Use policy: 'require-zero-copy' or policy: 'require-direct' to turn a
performance expectation into a checked invariant. prefer-gpu and prefer-cpu
control converter families that offer both paths. Unsupported types, incompatible
shapes, and nullable matrix or temporal inputs are rejected during planning.
Caller-owned GPU inputs are never destroyed by a borrowed prepared result.
On WebGPU, directly uploadable numeric casts run through the reusable GPGPU
castData() operation instead of converting every value on the CPU. Float64 is
handled specially: Arrow's binary64 bytes upload unchanged and Xiaoji's
fround() operation splits each value into adjacent high and residual-low
Float32 lanes in one compute pass. prepared.vector is a strided view of the
high lanes and prepared.residualVector is a zero-copy view of the low lanes.
Both views preserve Arrow chunks and null/readback metadata; destroying the
prepared result releases their shared allocation. Non-WebGPU devices, or
policy: 'prefer-cpu', use the equivalent chunk-preserving CPU fallback.
planArrowTableGPUConversion() and convertArrowTableToGPUTable() apply the same
decisions to an ordered output schema. Each output column names an Arrow source
path and its semantic/format contract. The result preserves Arrow record-batch
boundaries, source row offsets, field metadata, null metadata, and one owned GPU
allocation per output chunk; it never implicitly packs streaming batches.
convertArrowRecordBatchesToGPURecordBatches() accepts sync or async record-batch
streams (or bare async iterators) and yields independently owned GPU batches. It preserves batch/row source
identity and carries the first resolved temporal origin into later batches, so a
long timestamp stream does not silently change coordinate systems at each batch.
Pass an optional fourth argument {signal} to cancel pending input reads and stop
further conversion. Cancellation does not forcibly stop source I/O or an in-flight
GPU conversion. A conversion already underway finishes and its unyielded result is
destroyed. Iterator cleanup is requested without waiting for a stalled next() on
abort. Consumers still own all previously yielded batches.
Each output column must retain the first batch's GPU format. A format change destroys the unyielded batch and throws an error identifying the column and expected/actual formats. Arrow source types may differ if they convert to the same GPU format.
for await (const prepared of convertArrowRecordBatchesToGPURecordBatches(
device, source, schema, {signal: controller.signal}
)) {
try {
await consumeBatch(prepared.batch);
} finally {
prepared.destroy();
}
}
Streaming pulls one input per requested output; it does not prefetch or concatenate batches. Early consumer exit closes the source iterator.
const prepared = await convertArrowTableToGPUTable(device, arrowTable, {
columns: [
{name: 'instancePositions', source: 'geometry.position'},
{
name: 'instanceColors',
source: 'style.color',
semantic: 'color',
format: 'unorm8x4'
},
{name: 'eventTime', source: 'event.timestamp', semantic: 'temporal'}
]
});
The direct makeGPUVectorFromArrow() and makeGPUTableFromArrowTable() factories
remain useful when the source layout is already known to be GPU-compatible. Use
the planner boundary when schemas vary, diagnostics matter, or a semantic
conversion may be required.
Arrow Vector Factories​
Fixed-Size-List Storage Columns​
makeGPUVectorFromArrow() and makeGPUTableFromArrowTable() upload numeric
Arrow FixedSizeList columns wider than four elements as ordinary
GPUVector<'fixed-size-list<format,size>'> values. The vector remains aligned
with its containing table: length counts source rows, valueLength counts
flattened elements, and original Arrow record batches remain separate GPU
record batches.
When calling makeGPUVectorFromArrow() directly, provide
{format: 'fixed-size-list<float32,768>'} to retain that exact fixed-list
generic in TypeScript; Arrow's runtime FixedSizeList type cannot otherwise
encode the numeric width in its compile-time type.
import {makeGPUTableFromArrowTable} from '@luma.gl/graph/arrow';
const table = makeGPUTableFromArrowTable(device, arrowTable, {
shaderLayout: {
attributes: [],
bindings: [
{name: 'embedding', type: 'read-only-storage', group: 0, location: 0},
{name: 'sourceIds', type: 'read-only-storage', group: 0, location: 1}
]
},
validityColumns: {embedding: 'embeddingValidity'}
});
The optional validityColumns mapping materializes a named, table-owned Uint32
column that combines nullable parent rows and nullable child values. Stable row
identifiers remain ordinary non-null sibling columns. Use
fixedSizeListColumns: ['embedding'] when a short one-to-four-element column
should intentionally retain fixed-size-list storage semantics instead of its
default vertex format. For physically padded rows, specify
validityColumns: {embedding: {name: 'embeddingValidity', dimensions: 3}} to
ignore nullable padding after the three meaningful coordinates.
List Columns​
Arrow vector factories also support variable-length Arrow list columns whose nested elements contain one to four numeric components. This covers scalar lists plus tuple-style data such as XY, XYZ, and XYZM coordinates, while copying only compact list-offset metadata needed for readback instead of retaining the uploaded Arrow value arrays.
Path Columns​
Path Vectors are list of coordinates that are interpreted as a open paths or closed paths. Closed paths are often used to represent polygon outlines.
closeArrowPaths()​
closeArrowPaths() normalizes Float32 path rows before rendering or expansion:
closed paths whose first and last vertices differ by more than an epsilon receive
an appended copy of their first vertex, while already-closed, open, empty, and
single-point paths remain unchanged.
The Float32 rows can be absolute path coordinates or origin-relative deltas produced from Float64 path conversion. WebGPU uses compute classification and scatter passes; other devices use equivalent CPU fallback semantics.
ArrowPathRenderer.convertToGPUVectors() and convertArrowPathToGPUVectors() are the
path-attribute conversion boundary. Float32 XY, XYZ, and XYZM path rows upload
unchanged unless closure is requested. Float64 path rows convert on the CPU into
stable per-row Float32 deltas from the first point; CPU Float64 origins are kept
separately, and updateViewOrigins() refreshes the per-row view-origin buffers
when the view or model matrix changes.
ArrowPathRenderer.convertToGPUVectors(..., {model: 'storage'}) and
convertArrowPathStorageToGPUVectors() provide the storage-only WebGPU boundary:
Float64 rows upload temporarily, convert once into Float32 deltas with
sub_fp64u32_to_f32, then release the transient Float64 GPU payload before
returning storage path props.
PathAttributeModel consumes prepared path props and expands one logical path row
into packed per-segment render records. PathStorageModel is the WebGPU
storage-backed counterpart. It expands nested path rows into compact indexed
segment records through compute using the GPU-resident prepared path values plus
copied list-offset metadata. Render shaders fetch coordinates from path-value
storage and add per-row view origins, while per-path color and width rows remain
storage-buffer bindings instead of being duplicated per generated segment.
Default storage records use three u32 words per segment
(segmentStartPointIndex, segmentFlags, and globalRowIndex) plus one
persistent vec4<u32> path range per source row. Shaders that request legacy
end, previous, or next segment index attributes automatically keep the older
six-word record layout.
Reusable storage state can be built separately with createArrowPathStorageState.
PathTripsStorageModel layers Trips-style temporal filtering over that
storage path surface by reading prepared List<Float32> timestamps aligned with
path vertices.
Color Columns​
convertColors(device, gpuVector, options) and convertArrowColors(device, arrowVector, options)
convert fixed-width RGB/RGBA columns to unorm8x4 (default), float16x4, or float32x4.
Arrow inputs support FixedSizeList<Uint8 | Float16 | Float32, 3 | 4>.
canConvertColors(source) checks the input representation, not device rendering capabilities.
import {convertArrowToGPUVector} from '@luma.gl/graph/arrow';
// The consumer declares its supported storage representations.
const acceptedFormats = ['unorm8x4', 'float16x4', 'float32x4'] as const;
const prepared = await convertArrowToGPUVector(device, colors, {
semantic: 'color',
acceptedFormats,
format: 'preserve'
});
// Use prepared.vector until the consumer has finished; then prepared.destroy().
// Explicitly halve Float32 RGBA storage from 16 to 8 bytes per row.
const compact = await convertArrowToGPUVector(device, colors, {
semantic: 'color', acceptedFormats, format: 'float16x4'
});
| Output policy | Behavior |
|---|---|
unorm8x4 | 4 bytes per row. Uint8 channels are preserved; floats clamp to [0, 1], scale to 255 and round. |
float16x4 | 8 bytes per row. Uint8 divides by 255; floats retain negative/HDR values with binary16 rounding. |
float32x4 | 16 bytes per row. Uint8 divides by 255; floating channels retain their numeric interpretation. |
preserve | Preserve the source channel representation: Uint8 → unorm8, Float16 → Float16, Float32 → Float32. RGB expands to RGBA. Compatible GPU storage is borrowed; compatible Arrow payloads upload directly. |
Missing alpha is 255 in RGBA8 and 1 in floating output. These are storage conversions: no sRGB/linear transfer function, premultiplication, tone mapping, or implicit display-range clamping is applied to floating output. Binary16 has less precision than binary32 and a maximum finite magnitude of 65,504; rounding can overflow to infinity. Applications must choose an appropriate representation for their data and renderer. Normalized bytes do not identify a color space.
The optional acceptedFormats constraint is independent of the requested format. An unsupported
preserved representation throws unless fallbackFormat explicitly names an accepted output.
An explicit output that the consumer does not accept also throws. The existing planner formats
option still selects the first supported color target in the supplied order; use acceptedFormats
with format to distinguish a conversion policy from consumer capabilities. Omitting these
options retains the existing RGBA8 behavior.
planArrowGPUConversion() reports the resolved format, bytes, upload/pass counts, and precision
warnings before allocation. policy: 'prefer-cpu' converts Arrow payloads on CPU before uploading
only the final output. WebGL/CPU-backed Arrow conversion uses that path automatically; WebGPU
otherwise converts on GPU. GPU-resident WebGL input still requires the CPU/readback fallback.
Conversion preserves chunk boundaries and row validity, including empty chunks. Format-changing
results own output buffers. convertColors(..., {format: 'preserve'}) returns a borrowed wrapper
when GPU storage already matches; destroying that wrapper does not destroy the source. Keep the
source alive while consuming it. The planner's prepared result reports ownsVector and its
idempotent destroy() releases only owned storage. convertArrowColorsToArrow() reads the selected
output representation back into Arrow; use the CPUVector helper for a CPU-only pipeline.
import {convertCPUColors} from '@luma.gl/graph/gpu-data';
const compactCPU = convertCPUColors(cpuColors, {format: 'float16x4'});
// No device allocation, upload, or readback; chunks and validity remain separate.
The Arrow-free convertCPUColors(source, options) accepts Uint8/unorm8, Float16, or Float32
RGB/RGBA CPUVector rows and the same format/preservation constraints. Packed Float16 RGB
stored as uint16x3-webgl requires inputFormat: 'float16x3' to distinguish half-float
bits from unsigned integer channels. Compatible preservation
borrows the existing chunks; conversion allocates CPU payloads only. Low-level
convertColorData(source, {format}) returns a lazy evaluator; the WebGPU handler supports
GPUEvaluationScope, encoding into its caller-owned command stream without private submission.
Existing Arrow path/polygon/text consumers still request RGBA8. Requesting floating output does not make a renderer support HDR automatically. Shared named-operation graph descriptors currently cover packed 32-bit rows; compact color formats are available through CPUVector helpers, conversion planning and evaluator/scoped execution. Extending those descriptor formats is a separate change.
Matrix Columns​
Matrix Arrow columns can carry explicit vis.gl matrix shape, order, and physical
layout metadata through makeArrowMatrixVector() and the shape-specific matrix
builders.
convertArrowMatrixToGPUVector() accepts metadata-tagged
FixedSizeList<Float32> or FixedSizeList<Float64> rows, then returns one
canonical Float32 column-major wgsl-storage GPU vector. Canonical Float32 GPU
vectors pass through, raw Arrow Float64 rows truncate to Float32 during CPU
conversion, and non-canonical GPU-resident rows normalize with WebGPU compute.
Arrow source chunks remain separate prepared GPU chunks.
The same prepared column can lower into matrix attribute columns or bind as
array<matCxR<f32>>.
Time Columns​
Temporal Arrow columns can be converted with convertArrowTemporalToGPUVector() or
convertArrowTemporalToGPUVectors(). Supported v1 leaves are Date, Time,
Timestamp, and Duration, including List<...> leaves for Trips-style
streams. Conversion emits relative Float32 values in the original Arrow unit,
persists the selected origin metadata on the prepared field, chooses the first
valid absolute value when no origin is stored, and uses origin 0 for
durations. Raw Arrow inputs use CPU fallback where WebGPU is unavailable;
GPU-resident temporal inputs use WebGPU compute.
Global Grid Columns​
DGGS helpers keep compact global grid keys on the GPU. convertDggsCellIdsToGPUKeys()
parses UTF-8 geohash, quadkey, S2, A5, or H3 cell IDs into Uint64 GPU keys on
WebGPU, while convertDggsCellKeysToGPUPaths() expands prepared Uint64 keys into
closed Float32 cell boundary paths for path-style rendering. Its optional
coordinateFormat: 'fp64-split' mode emits
[longitudeHigh, latitudeHigh, longitudeLow, latitudeLow] Float32 components,
but DGGS boundary math still runs in Float32 today, so the low components are
zero until true higher-precision decode math is added. The dggs shader module
provides the matching WGSL Uint64 word and DGGS boundary helpers.
Columnar Geometries​
ArrowTableGeometry and makeGPUGeometryFromArrow() can convert
loaders.gl-compatible Mesh Arrow tables through the local structural
ArrowMeshTable type. Mesh Arrow attributes are uploaded as table-backed GPU
geometry, defaulting to one interleaved vertex buffer plus a separate optional
index buffer.
For lower-level table pipelines, import GPUTableBufferPlanner from
@luma.gl/graph/gpu-tables to produce deterministic GPU allocation plans from column
descriptors while respecting device vertex and storage buffer limits.
GPU Input Programming Guidelines​
Keep the final GPU contract separate from Arrow conversion policy:
GPUInputSchema
-> validates final GPUVector props
ArrowInputSchema
-> resolves Arrow columns
-> converts Arrow vectors
-> generates internal vectors
-> validates the result against GPUInputSchema
GPUInputSchema belongs to @luma.gl/graph/gpu-tables. It declares required and optional
prepared vector names, accepted GPUVector.format values, semantic kinds, and
which inputs are internal. It deliberately does not mention Arrow DataType
objects, source column paths, temporal origins, tessellation, text dictionaries,
or fallback-vector generation.
ArrowInputSchema belongs to @luma.gl/graph/arrow. It combines an Arrow-free
gpuInputSchema with adapter-owned resolveSourceVectors,
convertToGPUVectors, and getGPUInputVectors functions. The
prepareArrowInput() helper runs that pipeline and calls
validateGPUInputVectors() before returning the prepared result.
Use a simple Arrow input schema for direct one-column uploads. Keep model-family
adapters for cross-column conversions such as path normalization, polygon
tessellation, temporal conversion, and text glyph preparation. Do not make
@luma.gl/graph/gpu-simple-graph or @luma.gl/graph depend on Apache Arrow to describe those policies.
BufferLayouts​
The module can derive GPU BufferLayout entries from Arrow schemas and create primitive GPU data
and experimental table objects from compatible Arrow columns through
makeGPUDataFromArrowData(), makeGPUVectorFromArrow(), makeGPURecordBatchFromArrowRecordBatch(), and
makeGPUTableFromArrowTable(). Primitive storage is documented in the
GPGPU data reference, while the higher-level object model is
documented in Experimental GPU Tables and
GPU Table Structure.
Arrow upload helpers now produce format-first GPU objects:
- fixed Arrow columns become
GPUVector.formatvalues such asfloat32x3orunorm8x4; - list-of-vertex Arrow columns become
vertex-list<...>formats; GPUSchemarecords the selected GPU fields;- Arrow
DataTypevalues remain adapter metadata for migration and readback.
Streaming helpers preserve batch and buffer boundaries by creating one immutable
GPURecordBatch per incoming Arrow record batch. Each Arrow data chunk is
uploaded into a new GPUData with its own buffer, and GPUTable aggregate
vectors expose the logical column through GPUVector.data[].
instead of merging previous batches into one larger buffer.
Checking a column schema​
getArrowConversionFormat(type, options) checks Arrow type metadata against
the numeric vertex conversion rules and returns the GPU format. Pass
semantic: 'position' to require numeric XY or XYZ rows, or
semantic: 'color' to require RGB or RGBA rows. The check needs no device
and reads no row values. Conversion still checks nulls and transformed widths.
Budgeted batch consumption​
Use consumeArrowGPURecordBatches(device, source, schema, consume, {maxBatchPayloadBytes, signal}) to await each consumer callback and release its GPU batch before reading the next. The callback borrows the batch until its promise settles and should await any GPU work that uses it.
The budget checks estimated prepared payload bytes before conversion. Transient conversion allocations, metadata, and unrelated GPU memory are outside that estimate. The iterator API also accepts the budget option and transfers batch ownership to the caller.
Set maxBatchGPUBytes to check estimated peak conversion memory as well. The estimate includes already prepared columns, the active column output, temporary GPU source uploads, and temporal configuration buffers. It excludes driver overhead and allocations made by the consumer. Set both limits to enforce both checks.
Use splitOversizedBatches: true to retry oversized batches as smaller contiguous row slices before upload. Slices retain the original source batch index and carry their own global row offsets. A single row that cannot fit stops the stream with a budget error.
Fixed-width column streams​
convertArrowColumnsToGPUVectors(device, source, columnOptions, {signal}) converts
an iterable, async iterable, or bare async iterator of Arrow vectors. Each yielded
result supports format inference and position, scalar, or color validation through
semantic. Null rows are rejected unless preserveNulls is enabled. Each yielded
result has the same vector, optional residualVector and validityVector, and
destroy() contract as convertArrowColumnToGPUVector, plus
sourceBatchIndex and sourceRowIndexOffset. Column options retain format,
color, preserveNulls, fp64, and per-row transform behavior.
convertArrowRecordBatchesToGPUColumns(device, source, columns, {signal}) applies
those options to named fields in each record batch. Each column descriptor adds a
unique name and optional source field path. Results contain a columns map,
length, sourceBatchIndex, sourceRowIndexOffset, and an idempotent destroy()
that releases all column outputs, including residual and validity buffers.
import {convertArrowRecordBatchesToGPUColumns} from '@luma.gl/graph/arrow';
for await (const prepared of convertArrowRecordBatchesToGPUColumns(device, batches, [
{name: 'position', format: 'float32x3', color: false, preserveNulls: false, fp64: true}
], {signal})) {
try {
// Consume prepared.columns.position.vector and its residualVector here.
} finally {
prepared.destroy();
}
}
Both APIs share the generic record-batch converter's abortable iterator. They read
one input per pull and yield one result per input. Byte budgets and automatic batch
splitting are available on the generic record-batch converter only. To cap memory
for a fixed-width column stream, supply smaller input chunks or batches. Empty inputs retain their stream
positions. Output formats and the presence of companion vectors must remain stable;
a mismatch releases the rejected result. Failure partway through a batch releases
columns already converted for that batch. Abort interrupts pending reads and requests
source cleanup without waiting for a stalled iterator's return(). Synchronous
conversion cannot be interrupted mid-call; its result is released if abort is observed
before yielding. Already yielded results always remain caller-owned, including when
the consumer breaks out of the loop.