Flechette
Flechette is a JavaScript library for reading and writing the Apache Arrow columnar in-memory data format. It provides a faster, lighter, zero-dependency alternative to the Arrow JS reference implementation.
Flechette performs fast extraction and encoding of data columns in the Arrow binary IPC format, supporting ingestion of Arrow data from sources such as DuckDB and Arrow use in JavaScript data analysis tools like Arquero, Mosaic, Observable Plot, and Vega-Lite.
For documentation, see the API Reference. For code, see the Flechette GitHub repo.
Why Flechette?
In the process of developing multiple data analysis packages that consume Arrow data (including Arquero, Mosaic, and Vega), we've had to develop workarounds for the performance and correctness of the Arrow JavaScript reference implementation. Instead of workarounds, Flechette addresses these issues head-on.
-
Speed. Flechette provides better performance. Performance tests show 1.3-1.6x faster value iteration, 2-7x faster array extraction, 7-11x faster row object extraction, and 1.5-3.5x faster building of Arrow columns.
-
Size. Flechette is smaller: ~43k minified (~14k gzip'd) versus 163k minified (~43k gzip'd) for Arrow JS. Flechette's encoders and decoders also tree-shake cleanly, so you only pay for what you need in custom bundles.
-
Coverage. Flechette supports data types unsupported by the reference implementation, including decimal-to-number conversion, month/day/nanosecond time intervals (as used by DuckDB), run-end encoded data, binary views, and list views.
-
Flexibility. Flechette includes options to control data value conversion, such as numerical timestamps vs. Date objects for temporal data, and numbers vs. bigint values for 64-bit integer data.
-
Simplicity. Our goal is to provide a smaller, simpler code base in the hope that it will make it easier for ourselves and others to improve the library. If you'd like to see support for additional Arrow features, please file an issue or open a pull request.
That said, no tool is without limitations or trade-offs. Flechette assumes simpler inputs (byte buffers, no promises or streams), has less strict TypeScript typings, and may have a slightly slower initial parse (as it decodes dictionary data upfront for faster downstream access).
What's with the name?
The project name stems from the French word fléchette, which means "little arrow" or "dart". 🎯
Examples
Load and Access Arrow Data
import { tableFromIPC } from '@uwdata/flechette';
const url = 'https://vega.github.io/vega-datasets/data/flights-200k.arrow';
const ipc = await fetch(url).then(r => r.arrayBuffer());
const table = tableFromIPC(ipc);
console.log(`${table.numRows} x ${table.numCols}`);
console.log(JSON.stringify(table.schema.fields, 0, 2));
const delay = table.getChild('delay').toArray();
const time = [...table.getChild('time')];
const time0 = table.getChild('time').at(0);
const columns = table.toColumns();
const objects = table.toArray();
const subtable = table.select(['delay', 'time']);
Build and Encode Arrow Data
import {
bool, dictionary, float32, int32, tableFromArrays, tableToIPC, utf8
} from '@uwdata/flechette';
const arrays = {
ints: [1, 2, null, 4, 5],
floats: [1.1, 2.2, 3.3, 4.4, 5.5],
bools: [true, true, null, false, true],
strings: ['a', 'b', 'c', 'b', 'a']
};
const tableInfer = tableFromArrays(arrays);
const ipcInfer = tableToIPC(tableInfer);
const tableTyped = tableFromArrays(arrays, {
types: {
ints: int32(),
floats: float32(),
bools: bool(),
strings: dictionary(utf8())
}
});
const ipcTyped = tableToIPC(tableTyped, { format: 'file' });
Data extraction can be customized using options provided to table generation methods. By default, temporal data is returned as numeric timestamps, 64-bit integers are coerced to numbers, map-typed data is returned as an array of [key, value] pairs, and struct/row objects are returned as vanilla JS objects with extracted property values. These defaults can be changed via conversion options that push (or remove) transformations to the underlying data batches.
const table = tableFromIPC(ipc, {
useDate: true,
useDecimalBigInt: true,
useBigInt: true,
useMap: true,
useProxy: true
});
The same extraction options can be passed to tableFromArrays
. For more, see the API Reference.
Build Instructions
To build and develop Flechette locally:
- Clone https://github.com/uwdata/flechette.
- Run
npm i
to install dependencies. - Run
npm test
to run test cases, npm run perf
to run performance benchmarks, and npm run build
to build output files.