kepler.gl
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
120 lines (119 loc) • 6.29 kB
TypeScript
import * as arrow from 'apache-arrow';
import { DataType } from 'apache-arrow/type';
import { AsyncDuckDBConnection } from '@duckdb/duckdb-wasm';
import { ProtoDatasetField } from '@kepler.gl/types';
export declare const SUPPORTED_DUCKDB_DROP_EXTENSIONS: string[];
export declare type DuckDBColumnDesc = {
name: string;
type: string;
};
/**
* Queries a DuckDB table for the schema description.
* @param connection An active DuckDB connection.
* @param tableName A name of DuckDB table to query.
* @returns An array of column names and DuckDB types.
*/
export declare function getDuckDBColumnTypes(connection: AsyncDuckDBConnection, tableName: string): Promise<DuckDBColumnDesc[]>;
/**
* Generates a mapping of column names to their corresponding DuckDB data types.
* @param columns An array of column descriptions from DuckDB. Check getDuckDBColumnTypes.
* @returns A record where keys are column names and values are their data types.
*/
export declare function getDuckDBColumnTypesMap(columns: DuckDBColumnDesc[]): Record<string, string>;
/**
* Constructs an SQL query to select all columns from a given table,
* converting specified columns to Well-Known Binary (WKB) format using ST_AsWKB.
* @param tableName The name of the table from which to select data.
* @param columnsToConvertToWKB An array of column names that should be converted to WKB format.
* @returns The constructed SQL query.
*/
export declare function constructST_asWKBQuery(tableName: string, columnsToConvertToWKB: string[]): string;
/**
* Finds the names of columns that have a GEOMETRY type.
* @param columns An array of column descriptors from a DuckDB table.
* @returns An array of column names that are of type GEOMETRY.
*/
export declare function getGeometryColumns(columns: DuckDBColumnDesc[]): string[];
/**
* Sets the GeoArrow WKB extension metadata for columns of type GEOMETRY in an Arrow table.
* @param table The Apache Arrow table whose schema fields will be modified.
* @param columns An array of column descriptors from a DuckDB table.
*/
export declare function setGeoArrowWKBExtension(table: arrow.Table, columns: DuckDBColumnDesc[]): void;
/**
* Creates an arrow table from an array of arrow vectors and fields.
* @param columns An array of arrow vectors.
* @param fields An array of fields per arrow vector.
* @param arrowSchema Optional arrow table schema when available.
* @returns An arrow table.
*/
export declare const restoreArrowTable: (columns: arrow.Vector[], fields: ProtoDatasetField[], arrowSchema?: arrow.Schema) => arrow.Table<any>;
/**
* DuckDb throws when geoarrow extensions are present in metadata.
* @param table An arrow table to clear from extensions.
* @returns A map of removed per field geoarrow extensions.
*/
export declare const removeUnsupportedExtensions: (table: arrow.Table) => Record<string, string>;
/**
* Restore removed metadata extensions after a call to removeUnsupportedExtensions.
* @param table An arrow table to restore geoarrow extensions.
* @param removedExtensions A map of per field geoarrow extensions to restore.
*/
export declare const restoreUnsupportedExtensions: (table: arrow.Table, removedExtensions: Record<string, string>) => void;
/** Checks whether the given Apache Arrow JS type is a Point data type */
export declare function isGeoArrowPoint(type: DataType): boolean;
/** Checks whether the given Apache Arrow JS type is a Point data type */
export declare function isGeoArrowLineString(type: DataType): boolean;
/** Checks whether the given Apache Arrow JS type is a Polygon data type */
export declare function isGeoArrowPolygon(type: DataType): boolean;
/** Checks whether the given Apache Arrow JS type is a Polygon data type */
export declare function isGeoArrowMultiPoint(type: DataType): boolean;
/** Checks whether the given Apache Arrow JS type is a Polygon data type */
export declare function isGeoArrowMultiLineString(type: DataType): boolean;
/** Checks whether the given Apache Arrow JS type is a Polygon data type */
export declare function isGeoArrowMultiPolygon(type: DataType): boolean;
/**
* Checks if the given SQL query is a SELECT query by using the EXPLAIN command.
* @param connection The DuckDB connection instance.
* @param query The SQL query to check.
* @returns Resolves to `true` if the query is a SELECT statement, otherwise `false`.
*/
export declare function checkIsSelectQuery(connection: AsyncDuckDBConnection, query: string): Promise<boolean>;
/**
* Split a string with potentially multiple SQL queries (separated as usual by ';') into an array of queries.
* This implementation:
* - Handles single and double quoted strings with proper escaping
* - Ignores semicolons in line comments (--) and block comments (slash asterisk)
* - Trims whitespace from queries
* - Handles SQL-style escaped quotes ('' inside strings)
* - Returns only non-empty queries
* @param input A string with potentially multiple SQL queries.
* @returns An array of queries.
*/
export declare function splitSqlStatements(input: string): string[];
/**
* Removes SQL comments from a given SQL string.
* @param sql The SQL query string from which comments should be removed.
* @returns The cleaned SQL string without comments.
*/
export declare function removeSQLComments(sql: string): string;
/**
* Drops a table if it exists in the DuckDB database.
* @param connection The DuckDB connection instance.
* @param tableName The name of the table to drop.
* @returns A promise that resolves when the operation is complete.
* @throws Logs an error if the table drop operation fails.
*/
export declare const dropTableIfExists: (connection: AsyncDuckDBConnection, tableName: string) => Promise<void>;
/**
* Imports a file into DuckDB as a table, supporting multiple formats from SUPPORTED_DUCKDB_DROP_EXTENSIONS.
* @param file The file to be imported.
* @returns A promise that resolves when the file has been processed into a DuckDB table.
*/
export declare function tableFromFile(file: File | null): Promise<null | Error>;
/**
* Sanitizes a file name to be a valid DuckDB table name.
* @param fileName The input file name to be sanitized.
* @returns A valid DuckDB table name.
*/
export declare function sanitizeDuckDBTableName(fileName: string): string;