Skip to content

Commit f66ab3c

Browse files
ilyaboigorDykhta
andauthored
fix: Allow passing arrow tables to ArrowDataContainer (#3242)
* fix: copy geometry when geometry is of binary format (#3236) * fix: copy geometry when geometry is of binary format Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com> * nit Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com> --------- Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com> Signed-off-by: Ilya Boyandin <ilyabo@gmail.com> * fix: Allow passing arrow tables to ArrowDataContainer Signed-off-by: Ilya Boyandin <ilyabo@gmail.com> * only add arrowTable prop to CREATE_TABLE_TASK when set Signed-off-by: Ilya Boyandin <ilyabo@gmail.com> --------- Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com> Signed-off-by: Ilya Boyandin <ilyabo@gmail.com> Co-authored-by: Igor Dykhta <igorDykhta@users.noreply.github.com>
1 parent e2efa50 commit f66ab3c

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/table/src/dataset-utils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function createNewDataEntry(
9898
info,
9999
color,
100100
opts,
101-
data: validatedData
101+
data: data.arrowTable ? {...validatedData, arrowTable: data.arrowTable} : validatedData
102102
});
103103
}
104104

@@ -136,7 +136,12 @@ async function createTable(datasetInfo: CreateTableProps) {
136136
...opts,
137137
metadata
138138
});
139-
await table.importData({data});
139+
try {
140+
await table.importData({data});
141+
} catch (error) {
142+
console.error('Failed to create table', error);
143+
throw error;
144+
}
140145

141146
return table;
142147
}

src/table/src/kepler-table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class KeplerTable<F extends Field = Field> {
211211

212212
const dataContainer = createDataContainer(dataContainerData, {
213213
fields: data.fields,
214+
arrowTable: data.arrowTable,
214215
inputDataFormat
215216
});
216217

src/types/actions.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type ProtoDataset = {
5454
fields: ProtoDatasetField[];
5555
rows: any[][];
5656
cols?: any[];
57+
arrowTable?: arrow.Table;
5758
};
5859

5960
// table-injected metadata

src/utils/src/arrow-data-container.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright contributors to the kepler.gl project
33

4+
import { ALL_FIELD_TYPES } from '@kepler.gl/constants';
5+
import { ProtoDatasetField } from '@kepler.gl/types';
46
import * as arrow from 'apache-arrow';
5-
import {console as globalConsole} from 'global/window';
6-
import {DATA_TYPES as AnalyzerDATA_TYPES} from 'type-analyzer';
7-
import {ProtoDatasetField} from '@kepler.gl/types';
8-
import {ALL_FIELD_TYPES} from '@kepler.gl/constants';
7+
import { console as globalConsole } from 'global/window';
8+
import { DATA_TYPES as AnalyzerDATA_TYPES } from 'type-analyzer';
99

10-
import {DataRow, SharedRowOptions} from './data-row';
11-
import {DataContainerInterface, RangeOptions} from './data-container-interface';
10+
import { DataContainerInterface, RangeOptions } from './data-container-interface';
11+
import { DataRow, SharedRowOptions } from './data-row';
1212

1313
type ArrowDataContainerInput = {
1414
cols: arrow.Vector[];
1515
fields?: ProtoDatasetField[];
16+
arrowTable?: arrow.Table;
1617
};
1718

19+
1820
/**
1921
* @param dataContainer
2022
* @param sharedRow
@@ -68,7 +70,7 @@ export class ArrowDataContainer implements DataContainerInterface {
6870
this._numChunks = data.cols[0].data.length;
6971
// this._colData = data.cols.map(c => c.toArray());
7072

71-
this._arrowTable = this._createTable();
73+
this._arrowTable = data.arrowTable || this._createTable();
7274
}
7375

7476
/**

src/utils/src/data-container-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import {IndexedDataContainer} from './indexed-data-container';
77

88
import {DataContainerInterface} from './data-container-interface';
99
import {ProtoDatasetField} from '@kepler.gl/types';
10+
import * as arrow from 'apache-arrow';
1011

1112
export type DataContainerOptions = {
1213
inputDataFormat?: string; // one of DataForm
1314
fields?: ProtoDatasetField[];
15+
arrowTable?: arrow.Table;
1416
};
1517

1618
export const DataForm = {
@@ -37,7 +39,7 @@ export function createDataContainer(
3739
if (options.inputDataFormat === DataForm.ROWS_ARRAY) {
3840
return new RowDataContainer({rows: data, fields: options.fields});
3941
} else if (options.inputDataFormat === DataForm.COLS_ARRAY) {
40-
return new ArrowDataContainer({cols: data, fields: options.fields});
42+
return new ArrowDataContainer({cols: data, fields: options.fields, arrowTable: options.arrowTable});
4143
}
4244

4345
throw Error('Failed to create a data container: not implemented format');

0 commit comments

Comments
 (0)