Skip to content

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

feat: getDuckDBColumnTypes improvements (#3304)

Ilya Boyandin192f0fd2b91f
diff --git a/src/duckdb/src/table/duckdb-table-utils.ts b/src/duckdb/src/table/duckdb-table-utils.ts
index a1a60994a..5d46e800f 100644
--- a/src/duckdb/src/table/duckdb-table-utils.ts
+++ b/src/duckdb/src/table/duckdb-table-utils.ts
@@ -32,18 +32,45 @@ export async function getDuckDBColumnTypes(
tableName: string
): Promise<DuckDBColumnDesc[]> {
const quotedTableName = quoteTableName(tableName);
- const resDescribe = await connection.query(`DESCRIBE ${quotedTableName}`);
-
const duckDbTypes: DuckDBColumnDesc[] = [];
- const numRows = resDescribe.numRows;
- for (let i = 0; i < numRows; ++i) {
- const columnName = resDescribe.getChildAt(0)?.get(i);
- const columnType = resDescribe.getChildAt(1)?.get(i);
-
- duckDbTypes.push({
- name: columnName,
- type: columnType
- });
+ try {
+ // PRAGMA table_info is less likely to bind/execute view SQL than DESCRIBE,
+ // so it avoids triggering remote access (e.g., S3) for view-backed schemas.
+ const resInfo = await connection.query(
+ `PRAGMA table_info(${quotedTableName})`
+ );
+ const numRows = resInfo.numRows;
+ const columnNames = resInfo.getChild('name');
+ const columnTypes = resInfo.getChild('type');
+ for (let i = 0; i < numRows; ++i) {
+ duckDbTypes.push({
+ name: columnNames?.get(i),
+ type: columnTypes?.get(i)
+ });
+ }
+ } catch (primaryError) {
+ try {
+ const resDescribe = await connection.query(`DESCRIBE ${quotedTableName}`);
+ const numRows = resDescribe.numRows;
+ for (let i = 0; i < numRows; ++i) {
+ const columnName = resDescribe.getChildAt(0)?.get(i);
+ const columnType = resDescribe.getChildAt(1)?.get(i);
+
+ duckDbTypes.push({
+ name: columnName,
+ type: columnType
+ });
+ }
+ } catch (fallbackError) {
+ const error = new Error(
+ `[DuckDB] Failed to load column types for ${tableName} (PRAGMA + DESCRIBE).`
+ );
+ (error as Error & {cause?: unknown}).cause = {
+ primaryError,
+ fallbackError
+ };
+ throw error;
+ }
}
return duckDbTypes;