UNPKG

kepler.gl

Version:

kepler.gl is a webgl based application to visualize large scale location data in the browser

101 lines (100 loc) 4.24 kB
import { ProtoDatasetField } from '@kepler.gl/types'; import * as arrow from 'apache-arrow'; import { DATA_TYPES as AnalyzerDATA_TYPES } from 'type-analyzer'; import { DataContainerInterface, RangeOptions } from './data-container-interface'; import { DataRow, SharedRowOptions } from './data-row'; type ArrowDataContainerInput = { cols: arrow.Vector[]; fields?: ProtoDatasetField[]; arrowTable?: arrow.Table; }; /** * Check if table is an ArrowTable object. * * We use duck-typing instead of `instanceof arrow.Table` because DuckDB loads its own * bundled version of Apache Arrow. When DuckDB creates Arrow tables, they are instances * of DuckDB's Arrow.Table class, not the Arrow.Table class from our application's * apache-arrow package. This causes `instanceof` checks to fail even though the objects * are functionally equivalent Arrow tables. * * @param data - object to check * @returns true if data is an ArrowTable object (type guarded) */ export declare function isArrowTable(data: any): data is arrow.Table; /** * Check if data is an ArrowVector object. * Uses duck-typing instead of `instanceof` to handle DuckDB's bundled Arrow version. * * @param data - object to check * @returns true if data is an ArrowVector object (type guarded) */ export declare function isArrowVector(data: any): data is arrow.Vector; /** * Check if data is an Arrow FixedSizeList DataType. * Uses duck-typing instead of `instanceof` to handle DuckDB's bundled Arrow version. * * @param data - object to check * @returns true if data is an Arrow FixedSizeList DataType (type guarded) */ export declare function isArrowFixedSizeList(data: any): data is arrow.FixedSizeList; /** * Check if data is an Arrow Struct DataType. * Uses duck-typing instead of `instanceof` to handle DuckDB's bundled Arrow version. * * @param data - object to check * @returns true if data is an Arrow Struct DataType (type guarded) */ export declare function isArrowStruct(data: any): data is arrow.Struct; /** * A data container where all data is stored in raw Arrow table */ export declare class ArrowDataContainer implements DataContainerInterface { _cols: arrow.Vector[]; _numColumns: number; _numRows: number; _fields: ProtoDatasetField[]; _numChunks: number; /** An arrow table recreated from vectors */ _arrowTable: arrow.Table; constructor(data: ArrowDataContainerInput); /** * Restores internal Arrow table from vectors. * TODO: consider using original arrow table, as it could contain extra metadata, not passed to the fields. */ private _createTable; getTable(): arrow.Table<any>; update(updateData: arrow.Vector<any>[] | arrow.Table): void; numChunks(): number; numRows(): number; numColumns(): number; valueAt(rowIndex: number, columnIndex: number): any; row(rowIndex: number, sharedRow?: SharedRowOptions): DataRow; rowAsArray(rowIndex: number): any[]; rows(sharedRow: SharedRowOptions): Generator<DataRow, void, unknown>; column(columnIndex: number): Generator<any, void, unknown>; getColumn(columnIndex: number): arrow.Vector; getField(columnIndex: number): ProtoDatasetField; flattenData(): any[][]; getPlainIndex(): number[]; map<T>(func: (row: DataRow, index: number) => T, sharedRow?: SharedRowOptions, options?: RangeOptions): T[]; mapIndex<T>(func: ({ index }: { index: any; }, dc: DataContainerInterface) => T, options?: RangeOptions): T[]; find(func: (row: DataRow, index: number) => boolean, sharedRow?: SharedRowOptions): DataRow | undefined; reduce<T>(func: (acc: T, row: DataRow, index: number) => T, initialValue: T, sharedRow?: SharedRowOptions): T; } /** * Convert arrow data type to kepler.gl field types * * @param arrowType the arrow data type * @returns corresponding type in `ALL_FIELD_TYPES` */ export declare function arrowDataTypeToFieldType(arrowType: arrow.DataType): string; /** * Convert arrow data type to analyzer type * * @param arrowType the arrow data type * @returns corresponding type in `AnalyzerDATA_TYPES` */ export declare function arrowDataTypeToAnalyzerDataType(arrowType: arrow.DataType): typeof AnalyzerDATA_TYPES; export {};