Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

fix: preserve progressive Arrow coordinate batches (#3952)

Igor Dykhtaed6ecc527424
diff --git a/src/layers/src/layer-utils.ts b/src/layers/src/layer-utils.ts
index be5feb7ae..7e0d59f99 100644
--- a/src/layers/src/layer-utils.ts
+++ b/src/layers/src/layer-utils.ts
@@ -371,8 +371,8 @@ export function getGeoArrowPointCoords(row: any): [number, number, number] {
/**
* Builds an arrow vector compatible with ARROW:extension:name geoarrow.point.
- * @param getPosition Position accessor.
- * @param numElements Number of elements in the vector.
+ * @param dataContainer Arrow data whose record-batch boundaries must be preserved.
+ * @param getPosition Position accessor using global row indices.
* @returns An arrow vector compatible with ARROW:extension:name geoarrow.point.
*/
export function createGeoArrowPointVector(
@@ -397,17 +397,19 @@ export function createGeoArrowPointVector(
const fixedSizeListBuilder = new arrow.FixedSizeListBuilder({type: fixedSizeList});
fixedSizeListBuilder.addChild(floatBuilder);
- // One record batch, not one per source batch: a batch per parquet/DuckDB
- // chunk would create hundreds of pickable ScatterplotLayers and hit deck.gl's
- // 255-layer picking cap.
+ // Coordinate chunks must match the table, including during progressive loads.
+ // Completed imports compact the table itself to limit pickable sublayers.
const indexData = {index: 0};
- for (let i = 0; i < numElements; ++i) {
- indexData.index = i;
- fixedSizeListBuilder.append(getPosition(indexData));
- }
+ const chunks = dataContainer.getTable().batches.map(batch => {
+ for (let i = 0; i < batch.numRows; ++i) {
+ fixedSizeListBuilder.append(getPosition(indexData));
+ indexData.index++;
+ }
+ return fixedSizeListBuilder.flush();
+ });
- // Flush even for zero rows so Arrow receives typed Data instead of an untyped empty array.
- return arrow.makeVector([fixedSizeListBuilder.flush()]);
+ // A table without batches still needs typed Data to construct an empty vector.
+ return arrow.makeVector(chunks.length ? chunks : [fixedSizeListBuilder.flush()]);
}
/**
diff --git a/test/browser/layer-tests/point-layer-specs.js b/test/browser/layer-tests/point-layer-specs.js
index dfbae035f..07716e24c 100644
--- a/test/browser/layer-tests/point-layer-specs.js
+++ b/test/browser/layer-tests/point-layer-specs.js
@@ -42,6 +42,148 @@ import {
const {PointLayer} = KeplerGlLayers;
+[PointLayer, KeplerGlLayers.ArcLayer, KeplerGlLayers.LineLayer].forEach(LayerClass => {
+ test(`#${LayerClass.name} -> progressive numeric Arrow coordinates render and pick`, async t => {
+ const rows = [
+ [99, 89, 99, 89, 99], // Padding excluded by the Arrow slices below.
+ [10, 20, 30, 40, 5],
+ [0, 0, 50, 60, -5],
+ [null, 25, 70, null, 10],
+ [-10, -20, -30, -40, 15],
+ [99, 89, 99, 89, 99]
+ ];
+ const names = ['lng0', 'lat0', 'lng1', 'lat1', 'altitude'];
+ const makeTable = values =>
+ new arrow.Table(
+ Object.fromEntries(
+ names.map((name, index) => [
+ name,
+ arrow.vectorFromArray(
+ values.map(row => row[index]),
+ new arrow.Float64()
+ )
+ ])
+ )
+ );
+ const source = makeTable(rows);
+ const empty = new arrow.Table(
+ new arrow.RecordBatch(
+ Object.fromEntries(
+ names.map(name => [
+ name,
+ arrow.makeData({type: new arrow.Float64(), data: new Float64Array(0)})
+ ])
+ )
+ )
+ );
+ const first = source.slice(1, 2);
+ const appended = new arrow.Table(source.schema, [
+ ...first.batches,
+ ...empty.batches,
+ ...source.slice(2, 4).batches
+ ]);
+ const complete = new arrow.Table(source.schema, [
+ ...appended.batches,
+ ...source.slice(4, 5).batches
+ ]);
+ const dataset = new KeplerTable({info: {id: 'progressive-numeric'}, color: [0, 0, 0]});
+ await dataset.importData({data: processArrowBatches(first.batches, {compact: false})});
+ const layer = new LayerClass({dataId: dataset.id});
+ const isPoint = LayerClass === PointLayer;
+ layer.updateLayerConfig({
+ columns: Object.fromEntries(
+ (isPoint
+ ? [
+ ['lng', 0],
+ ['lat', 1],
+ ['altitude', 4]
+ ]
+ : names.slice(0, 4).map((name, index) => [name, index])
+ ).map(([key, fieldIdx]) => [key, {value: names[fieldIdx], fieldIdx}])
+ )
+ });
+ let formatted;
+ for (const [label, table, compact] of [
+ ['initial', first, false],
+ ['appended', appended, false],
+ ['appended again', complete, false],
+ ['completed', complete, true],
+ ['empty', empty, false]
+ ]) {
+ const data = processArrowBatches(table.batches, {compact});
+ await dataset.update(compact ? data : {...data, arrowTable: table});
+ dataset.filteredIndex = dataset.allIndexes.filter(index => index !== 1);
+ const actualTable = dataset.dataContainer.getTable();
+ const expectedLengths = compact ? [4] : table.batches.map(batch => batch.numRows);
+ t.deepEqual(
+ actualTable.batches.map(batch => batch.numRows),
+ expectedLengths,
+ `${label}: import batch lengths`
+ );
+ formatted = layer.formatLayerData({[dataset.id]: dataset}, formatted);
+ const [composite] = layer.renderLayer({
+ data: formatted,
+ dataset,
+ idx: 0,
+ layerInteraction: {},
+ mapState: INITIAL_MAP_STATE,
+ gpuFilter: dataset.gpuFilter,
+ interactionConfig: INITIAL_VIS_STATE.interactionConfig,
+ visible: true,
+ layerCallbacks: {}
+ });
+ let sublayers;
+ t.doesNotThrow(() => {
+ sublayers = composite.renderLayers();
+ }, `${label}: constructs every Arrow sublayer without a batch-count assertion`);
+ if (!sublayers) continue;
+ t.deepEqual(
+ sublayers.map(sublayer => sublayer.props.data.length),
+ expectedLengths,
+ `${label}: rendered batch lengths`
+ );
+ let offset = 0;
+ for (const sublayer of sublayers) {
+ const batchData = sublayer.props.data;
+ for (let index = 0; index < batchData.length; index++) {
+ const globalIndex = offset + index;
+ const row = rows[globalIndex + 1];
+ const expected = isPoint
+ ? {getPosition: [row[0], row[1], row[4]]}
+ : {getSourcePosition: [row[0], row[1], 0], getTargetPosition: [row[2], row[3], 0]};
+ for (const [accessor, position] of Object.entries(expected)) {
+ const attribute = batchData.attributes[accessor];
+ t.deepEqual(
+ Array.from(
+ attribute.value.slice(index * attribute.size, (index + 1) * attribute.size)
+ ),
+ position.map(value => Number(value)),
+ `${label}: ${accessor} remains aligned, including nullable coordinates`
+ );
+ }
+ t.equal(
+ sublayer.props.getFiltered(null, {index, data: batchData}),
+ globalIndex === 1 ? 0 : 1,
+ `${label}: filter uses global index`
+ );
+ const picked = composite.getPickingInfo({
+ info: {index, picked: true},
+ sourceLayer: sublayer
+ });
+ t.equal(picked.index, globalIndex, `${label}: picking uses global index`);
+ t.deepEqual(
+ layer.getHoverData(picked.object, dataset.dataContainer, dataset.fields, {}, picked),
+ dataset.dataContainer.row(globalIndex),
+ `${label}: hover reads the picked source row`
+ );
+ }
+ offset += batchData.length;
+ }
+ }
+ t.end();
+ });
+});
+
test('#PointLayer -> native separated points preserve every coordinate through import', async t => {
for (const dimensions of [2, 3]) {
for (const separated of [true, false]) {
diff --git a/test/node/utils/layer-utils-test.js b/test/node/utils/layer-utils-test.js
index 5cf571f4f..b3275ac8d 100644
--- a/test/node/utils/layer-utils-test.js
+++ b/test/node/utils/layer-utils-test.js
@@ -282,6 +282,51 @@ test('layerUtils -> createGeoArrowPointVector handles empty and nonempty coordin
t.end();
});
+test('layerUtils -> coordinate vectors preserve sliced and empty record batches', t => {
+ for (const dimensions of [2, 3]) {
+ const table = new arrow.Table({
+ row: arrow.vectorFromArray([99, 0, 1, 2, 3, 99], new arrow.Float64())
+ });
+ const empty = new arrow.Table(
+ new arrow.RecordBatch({
+ row: arrow.makeData({type: new arrow.Float64(), data: new Float64Array(0)})
+ })
+ );
+ const batched = new arrow.Table(table.schema, [
+ ...empty.batches,
+ ...table.slice(1, 3).batches,
+ ...empty.batches,
+ ...table.slice(3, 5).batches,
+ ...empty.batches
+ ]);
+ const container = new ArrowDataContainer({
+ cols: [table.getChildAt(0)],
+ fields: [{name: 'row', type: 'real', fieldIdx: 0}]
+ });
+ container.update(batched);
+ const vector = createGeoArrowPointVector(container, ({index}) =>
+ [container.valueAt(index, 0), -index, index + 10].slice(0, dimensions)
+ );
+ t.deepEqual(
+ vector.data.map(chunk => chunk.length),
+ [0, 2, 0, 2, 0],
+ 'keeps empty batches'
+ );
+ t.deepEqual(
+ Array.from(vector, point => Array.from(point)),
+ [0, 1, 2, 3].map(index => [index, -index, index + 10].slice(0, dimensions)),
+ 'uses global row indices and logical slice offsets for XY and XYZ'
+ );
+ }
+ const empty = new ArrowDataContainer({cols: [], fields: []});
+ const vector = createGeoArrowPointVector(empty, () => {
+ t.fail('must not access a row in a table without batches');
+ });
+ t.equal(vector.length, 0, 'an empty table still produces a typed empty vector');
+ t.ok(arrow.DataType.isFixedSizeList(vector.type), 'empty vector has point storage');
+ t.end();
+});
+
test('layerUtils -> separated point normalization preserves validity, slices and precision', t => {
for (const FloatType of [arrow.Float32, arrow.Float64]) {
for (const dimensions of [2, 3]) {