@loaders.gl/sql 5.0.0-alpha.9 → 5.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -30
- package/README.md +19 -10
- package/THIRD-PARTY-NOTICES.md +17 -0
- package/dist/arrow-table-source.d.ts +5 -5
- package/dist/arrow-table-source.d.ts.map +1 -1
- package/dist/arrow-table-source.js +3 -3
- package/dist/arrow-table-source.js.map +1 -1
- package/dist/compile-table-query.d.ts +3 -3
- package/dist/compile-table-query.d.ts.map +1 -1
- package/dist/compile-table-query.js +2 -2
- package/dist/compile-table-query.js.map +1 -1
- package/dist/duckdb-sql-source.d.ts +22 -13
- package/dist/duckdb-sql-source.d.ts.map +1 -1
- package/dist/duckdb-sql-source.js +40 -16
- package/dist/duckdb-sql-source.js.map +1 -1
- package/dist/index.cjs +218 -169
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/snowflake-sql-source.d.ts +16 -12
- package/dist/snowflake-sql-source.d.ts.map +1 -1
- package/dist/snowflake-sql-source.js +1 -1
- package/dist/snowflake-sql-source.js.map +1 -1
- package/dist/sql-source.d.ts +9 -9
- package/dist/sql-source.d.ts.map +1 -1
- package/dist/sql-source.js +2 -2
- package/dist/sql-source.js.map +1 -1
- package/dist/sql-types.d.ts +13 -2
- package/dist/sql-types.d.ts.map +1 -1
- package/dist/sql-utils.d.ts +2 -3
- package/dist/sql-utils.d.ts.map +1 -1
- package/dist/sql-utils.js +1 -34
- package/dist/sql-utils.js.map +1 -1
- package/package.json +8 -28
- package/src/arrow-table-source.ts +7 -7
- package/src/compile-table-query.ts +4 -4
- package/src/duckdb-sql-source.ts +47 -19
- package/src/index.ts +16 -11
- package/src/snowflake-sql-source.ts +2 -2
- package/src/sql-source.ts +5 -5
- package/src/sql-types.ts +14 -2
- package/src/sql-utils.ts +2 -40
- package/dist/arrow-query.cjs +0 -1404
- package/dist/arrow-query.cjs.map +0 -6
- package/dist/arrow-query.d.ts +0 -5
- package/dist/arrow-query.d.ts.map +0 -1
- package/dist/arrow-query.js +0 -6
- package/dist/arrow-query.js.map +0 -1
- package/dist/bind-sql-predicate.d.ts +0 -4
- package/dist/bind-sql-predicate.d.ts.map +0 -1
- package/dist/bind-sql-predicate.js +0 -11
- package/dist/bind-sql-predicate.js.map +0 -1
- package/dist/parse-sql-predicate.d.ts +0 -10
- package/dist/parse-sql-predicate.d.ts.map +0 -1
- package/dist/parse-sql-predicate.js +0 -322
- package/dist/parse-sql-predicate.js.map +0 -1
- package/dist/query-arrow-table.d.ts +0 -83
- package/dist/query-arrow-table.d.ts.map +0 -1
- package/dist/query-arrow-table.js +0 -663
- package/dist/query-arrow-table.js.map +0 -1
- package/dist/sql-predicate-schema.d.ts +0 -156
- package/dist/sql-predicate-schema.d.ts.map +0 -1
- package/dist/sql-predicate-schema.js +0 -226
- package/dist/sql-predicate-schema.js.map +0 -1
- package/dist/sql-predicate-types.d.ts +0 -45
- package/dist/sql-predicate-types.d.ts.map +0 -1
- package/dist/sql-predicate-types.js +0 -9
- package/dist/sql-predicate-types.js.map +0 -1
- package/dist/sql-predicate-zod.cjs +0 -54
- package/dist/sql-predicate-zod.cjs.map +0 -6
- package/dist/sql-predicate-zod.d.ts +0 -11
- package/dist/sql-predicate-zod.d.ts.map +0 -1
- package/dist/sql-predicate-zod.js +0 -45
- package/dist/sql-predicate-zod.js.map +0 -1
- package/dist/sql-predicate.cjs +0 -607
- package/dist/sql-predicate.cjs.map +0 -6
- package/dist/sql-predicate.d.ts +0 -6
- package/dist/sql-predicate.d.ts.map +0 -1
- package/dist/sql-predicate.js +0 -8
- package/dist/sql-predicate.js.map +0 -1
- package/dist/table-query-capabilities.d.ts +0 -6
- package/dist/table-query-capabilities.d.ts.map +0 -1
- package/dist/table-query-capabilities.js +0 -26
- package/dist/table-query-capabilities.js.map +0 -1
- package/dist/table-query.cjs +0 -286
- package/dist/table-query.cjs.map +0 -6
- package/dist/table-query.d.ts +0 -29
- package/dist/table-query.d.ts.map +0 -1
- package/dist/table-query.js +0 -30
- package/dist/table-query.js.map +0 -1
- package/src/arrow-query.ts +0 -17
- package/src/bind-sql-predicate.ts +0 -21
- package/src/parse-sql-predicate.ts +0 -381
- package/src/query-arrow-table.ts +0 -846
- package/src/sql-predicate-schema.ts +0 -251
- package/src/sql-predicate-types.ts +0 -87
- package/src/sql-predicate-zod.ts +0 -52
- package/src/sql-predicate.ts +0 -28
- package/src/table-query-capabilities.ts +0 -29
- package/src/table-query.ts +0 -78
package/src/sql-source.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {ArrowTable, Schema} from '@loaders.gl/schema';
|
|
6
|
-
import {DataSource} from '@loaders.gl/loader-utils';
|
|
7
|
-
import type {CoreAPI, RequiredOptions} from '@loaders.gl/loader-utils';
|
|
5
|
+
import type {ArrowTable, Schema} from '@loaders.gl/core/schema';
|
|
6
|
+
import {DataSource} from '@loaders.gl/core/loader-utils';
|
|
7
|
+
import type {CoreAPI, RequiredOptions} from '@loaders.gl/core/loader-utils';
|
|
8
8
|
|
|
9
9
|
import type {
|
|
10
10
|
SQLAdapter,
|
|
@@ -18,9 +18,9 @@ import type {
|
|
|
18
18
|
SQLTableInfo
|
|
19
19
|
} from './sql-types';
|
|
20
20
|
import {compileSQLTableQuery, type SQLTableQueryDialect} from './compile-table-query';
|
|
21
|
-
import type {SQLPredicateParameterValues} from '
|
|
21
|
+
import type {SQLPredicateParameterValues} from '@loaders.gl/core/scan/sql-predicate-types';
|
|
22
22
|
import {convertRowsToArrowTable, isNodeRuntime} from './sql-utils';
|
|
23
|
-
import {SQL_DATA_SOURCE_TABLE_QUERY_CAPABILITIES} from '
|
|
23
|
+
import {SQL_DATA_SOURCE_TABLE_QUERY_CAPABILITIES} from '@loaders.gl/core/scan/table-query-capabilities';
|
|
24
24
|
|
|
25
25
|
const SQL_ADAPTER_FACTORIES = new Map<string, SQLAdapterFactory>();
|
|
26
26
|
|
package/src/sql-types.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {ArrowTable, Schema} from '@loaders.gl/schema';
|
|
6
|
-
import type {CoreAPI, DataSourceOptions} from '@loaders.gl/loader-utils';
|
|
5
|
+
import type {ArrowTable, Schema} from '@loaders.gl/core/schema';
|
|
6
|
+
import type {CoreAPI, DataSourceOptions} from '@loaders.gl/core/loader-utils';
|
|
7
7
|
import type {SQLTableQuery} from './compile-table-query';
|
|
8
8
|
|
|
9
9
|
export type SQLParameterValues = unknown[] | Record<string, unknown>;
|
|
@@ -64,6 +64,16 @@ export type SQLAdapterCapabilities = {
|
|
|
64
64
|
isDynamic?: boolean;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
/** Destination for an Arrow IPC upload. */
|
|
68
|
+
export type SQLArrowInsertOptions = {
|
|
69
|
+
/** Destination table name. */
|
|
70
|
+
tableName: string;
|
|
71
|
+
/** Destination schema, defaulting to DuckDB's default schema. */
|
|
72
|
+
schemaName?: string;
|
|
73
|
+
/** Create a table when true (default); append to an existing table when false. */
|
|
74
|
+
create?: boolean;
|
|
75
|
+
};
|
|
76
|
+
|
|
67
77
|
/** Runtime adapter interface used by SQL-backed data sources. */
|
|
68
78
|
export interface SQLAdapter {
|
|
69
79
|
readonly capabilities: SQLAdapterCapabilities;
|
|
@@ -78,6 +88,8 @@ export interface SQLAdapter {
|
|
|
78
88
|
tableName: string;
|
|
79
89
|
}): Promise<Schema>;
|
|
80
90
|
executeRows(sql: string, options?: SQLQueryOptions): Promise<Record<string, unknown>[]>;
|
|
91
|
+
/** Uploads an Arrow IPC stream without passing Arrow runtime objects. */
|
|
92
|
+
insertArrowIPC?(bytes: Uint8Array, options: SQLArrowInsertOptions): Promise<void>;
|
|
81
93
|
executeArrow?(sql: string, options?: SQLQueryOptions): Promise<ArrowTable>;
|
|
82
94
|
}
|
|
83
95
|
|
package/src/sql-utils.ts
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import type {ArrowTable, DataType, Field, ObjectRowTable, Schema} from '@loaders.gl/schema';
|
|
7
|
-
import {makeTableFromData, getDataTypeFromArray} from '@loaders.gl/schema-utils';
|
|
5
|
+
import type {DataType, Schema} from '@loaders.gl/core/schema';
|
|
8
6
|
|
|
9
7
|
import type {SQLColumnInfo} from './sql-types';
|
|
10
8
|
|
|
@@ -23,28 +21,7 @@ export function quoteSqlIdentifier(identifier: string): string {
|
|
|
23
21
|
return `"${identifier.replace(/"/g, '""')}"`;
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
export function convertRowsToArrowTable(rows: Record<string, unknown>[]): ArrowTable {
|
|
28
|
-
const table: ObjectRowTable =
|
|
29
|
-
rows.length > 0
|
|
30
|
-
? makeTableFromData(rows)
|
|
31
|
-
: {shape: 'object-row-table', schema: {fields: [], metadata: {}}, data: rows};
|
|
32
|
-
const schema = deducePrimitiveAwareSchema(table);
|
|
33
|
-
|
|
34
|
-
if (table.data.length === 0 || schema.fields.length === 0) {
|
|
35
|
-
return {
|
|
36
|
-
shape: 'arrow-table',
|
|
37
|
-
schema,
|
|
38
|
-
data: new arrow.Table(new arrow.Schema([]))
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
shape: 'arrow-table',
|
|
44
|
-
schema,
|
|
45
|
-
data: arrow.tableFromJSON(table.data)
|
|
46
|
-
};
|
|
47
|
-
}
|
|
24
|
+
export {convertRowsToArrowTable} from '@loaders.gl/core/scan/rows-to-arrow';
|
|
48
25
|
|
|
49
26
|
/** Converts normalized SQL columns into a loaders.gl schema. */
|
|
50
27
|
export function convertSQLColumnsToSchema(columns: SQLColumnInfo[]): Schema {
|
|
@@ -109,21 +86,6 @@ function mapSQLTypeToDataType(sqlType: string): DataType {
|
|
|
109
86
|
return 'utf8';
|
|
110
87
|
}
|
|
111
88
|
|
|
112
|
-
function deducePrimitiveAwareSchema(table: ObjectRowTable): Schema {
|
|
113
|
-
return {
|
|
114
|
-
...table.schema!,
|
|
115
|
-
fields: table.schema!.fields.map((field): Field => {
|
|
116
|
-
if (field.type !== 'null') {
|
|
117
|
-
return field;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const columnValues = table.data.map(row => row[field.name]);
|
|
121
|
-
const inferredType = getDataTypeFromArray(columnValues);
|
|
122
|
-
return {...field, type: inferredType.type, nullable: inferredType.nullable};
|
|
123
|
-
})
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
89
|
/** Returns a fully qualified SQL object name. */
|
|
128
90
|
export function getQualifiedTableName(options: {
|
|
129
91
|
catalogName?: string;
|