Arrow JS API · batch container
A RecordBatch is one useful chunk of a table.
RecordBatch groups equal-length child vectors under one schema. It is the unit that IPC readers, streaming loaders, and incremental processing pipelines can pass around without materializing an entire table.
The RecordBatch model
Keep rows aligned while data arrives in chunks.
Every child vector in a RecordBatch has the same logical length. Pass batches through a stream, inspect rows, or combine them into a Table when a complete logical result is useful.
Rows
Equal-length records across all child vectors
Columns
Typed Vector children under one Schema
Source
Table chunks or IPC readers
Next step
Process immediately or append to a Table
Detailed guide
RecordBatch reference
The sections below document constructors, schema and data members, child access, row iteration, and chunk behavior.
This page is aligned to Apache Arrow JS v21.x (apache-arrow).
A RecordBatch is a fixed-width row set of equal-length child vectors.
Overview
Use table.batches[i] from a Table, or deserialize IPC input to get RecordBatch instances.
import {Table, Field, Int32, Utf8, tableFromArrays} from 'apache-arrow';
const table = tableFromArrays({
id: [1, 2, 3],
label: ['a', 'b', 'c']
});
const batch = table.batches[0];
Usage
import {tableFromArrays, Field, Int32, Utf8} from 'apache-arrow';
const table = tableFromArrays({
id: [1, 2, 3],
label: ['a', 'b', 'c']
});
const batch = table.batches[0];
console.log(batch?.numRows, batch?.schema?.fields.length);
import {tableFromArrays} from 'apache-arrow';
const batch = tableFromArrays({
id: [1, 2],
label: ['x', 'y']
}).batches[0];
for (const row of batch) {
console.log(row.id, row.label);
}
Constructors
new RecordBatch<T extends TypeMap = any>(columns: { [P in keyof T]: Data<T[P]> })
new RecordBatch<T extends TypeMap = any>(schema: Schema<T>, data?: Data<Struct<T>>).
Build a record batch from a schema and backing struct data.
Members
schema: Schema (readonly)
Batch schema.
data: Data<Struct> (readonly)
Flattened row-major backing data.
numCols: number (readonly)
Number of columns.
numRows: number (readonly)
Number of rows.
nullCount: number (readonly)
Number of null rows.
Methods
isValid(index: number): boolean
Returns whether row at index is non-null.
get(index: number): StructRowProxy<T> | null
Returns row data at index.
at(index: number): StructRowProxy<T> | null
Returns row data at index, with negative indexes counting from the end.
set(index: number, value: Struct<T>['TValue']): void
Assigns one row value at index.
indexOf(element: Struct<T>['TValue'], offset?: number): number
Finds the first row matching element.
[Symbol.iterator](): IterableIterator<StructRowProxy<T>>
Iterates rows in row order.
toArray(): StructRowProxy<T>[]
Converts all rows into a JS array.
toString(): string
Returns a human-readable row dump.
concat(...others: RecordBatch<T>[]): Table<T>
Returns a single table by concatenating same-schema record batches.
slice(begin?: number, end?: number): RecordBatch<T>
Returns a row-range view, end-exclusive.
getChild(name: keyof T): Vector | null
Returns child vector by field name.
getChildAt(index: number): Vector | null
Returns child vector by field position.
setChild(name: keyof T, child: Vector): RecordBatch
Returns a new batch with a named child replaced.
setChildAt(index: number, child?: Vector | null): RecordBatch
Returns a new batch with a child replaced at index.
select<K extends keyof T = any>(columnNames: K[]): RecordBatch<{ [P in K]: T[P] }>
Returns a new batch with only selected names.
selectAt<K extends T = any>(columnIndices: number[]): RecordBatch<{ [P in keyof K]: K[P] }>
Returns a new batch with only selected indexes.