Skip to main content

MappedArrowTable

MappedArrowTable provides a cheap key-value map view of an arrow.Table without copying column data. MappedArrowTable<T> extends IndexedArrowTable<T>, where T is the Arrow column type map. Mapped transforms preserve visible keys and duplicate entries; keyed lookup resolves the last visible occurrence of a key.

Propertiesโ€‹

PropertyTypeDescription
rowIndexMapMap<string, number>Key-to-raw-row map owned by the view; duplicate keys use last-wins lookup. Treat as immutable.
rowKeysstring[]Keys in visible row order, including duplicates. Treat as immutable.
table, schema, indexesInheritedBacking Arrow data, schema, and visible-to-raw index mapping.
numRows, numColsnumberVisible row count and backing column count. Readonly.

Constructorโ€‹

new MappedArrowTable(arrowTable, rowIndexMap);
ParameterTypeDescription
arrowTablearrow.Table<T>Backing table in raw row order.
rowIndexMapReadonlyMap<string, number>String-key-to-raw-row mapping; copied into the view.

Methodsโ€‹

getRowIndex(rowKey)โ€‹

Returns the raw backing-table row index for a mapped key, or null when the key is absent.

getRowKey(rowIndex)โ€‹

Returns the mapped key for a visible row index, or null when the index is invalid.

getByKey(rowKey)โ€‹

Returns a materialized Arrow row for a mapped key, or null when the key is absent.

atMapped(rowIndex)โ€‹

Reads a mapped row using Array.prototype.at semantics. Negative indexes count backward from the end of the visible mapped view.

slice(begin, end)โ€‹

Returns a sliced mapped view over the same backing table and preserves mapped key entries.

filter(predicate)โ€‹

Returns a filtered mapped view over the same backing table and preserves mapped key entries.

sort(compare)โ€‹

Returns a sorted mapped view over the same backing table and preserves mapped key entries.

concat(...others)โ€‹

Concatenates this mapped view with other mapped views sharing an identical Arrow schema. The result owns a new backing Arrow table, preserves visible mapped-row order including duplicate keys, and keeps last-wins keyed lookup behavior.

All other IndexedArrowTable methods, including getValue(), getChild(), materializeArrowTable(), toArray(), and iteration, are inherited.

Key Semanticsโ€‹

  • rowKeys stores keys in visible row order.
  • Duplicate keys are preserved in visible row order.
  • Keyed lookups are last-wins. If the same key appears multiple times, getRowIndex(key) and getByKey(key) resolve to the last visible occurrence.

Usageโ€‹

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

const rowIndexMap = new Map([
['gamma', 2],
['alpha', 0]
]);

const mappedTable = new MappedArrowTable(arrowTable, rowIndexMap);

mappedTable.getByKey('gamma')?.name; // 'gamma'
mappedTable.getRowIndex('alpha'); // 0
mappedTable.getRowKey(1); // 'alpha'

Filtering and Sortingโ€‹

Mapped transforms preserve key entries instead of collapsing them into a plain indexed table.

const filteredTable = mappedTable.filter(
(currentTable, rowIndex) => (currentTable.getValue(rowIndex, 'score') ?? 0) >= 20
);

const sortedTable = filteredTable.sort(
(currentTable, leftRowIndex, rightRowIndex) =>
(currentTable.getValue(rightRowIndex, 'score') ?? 0) -
(currentTable.getValue(leftRowIndex, 'score') ?? 0)
);