@loaders.gl/core 5.0.0-beta.5 → 5.0.0-beta.6

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.
Files changed (188) hide show
  1. package/dist/cluster-source.cjs +45 -1
  2. package/dist/cluster-source.cjs.map +1 -1
  3. package/dist/dist.min.js +2 -2
  4. package/dist/federated-table-scan-source.cjs +272 -201
  5. package/dist/federated-table-scan-source.cjs.map +3 -3
  6. package/dist/index.cjs +1 -1
  7. package/dist/lib/init.js +1 -1
  8. package/dist/loader-utils/index.cjs +233 -12
  9. package/dist/loader-utils/index.cjs.map +2 -2
  10. package/dist/loader-utils/index.d.ts +8 -4
  11. package/dist/loader-utils/index.d.ts.map +1 -1
  12. package/dist/loader-utils/index.js +3 -1
  13. package/dist/loader-utils/index.js.map +1 -1
  14. package/dist/loader-utils/json-loader.js +1 -1
  15. package/dist/loader-utils/lib/files/http-file-transport.d.ts +4 -0
  16. package/dist/loader-utils/lib/files/http-file-transport.d.ts.map +1 -1
  17. package/dist/loader-utils/lib/files/http-file-transport.js +45 -1
  18. package/dist/loader-utils/lib/files/http-file-transport.js.map +1 -1
  19. package/dist/loader-utils/lib/files/http-file-types.d.ts +2 -0
  20. package/dist/loader-utils/lib/files/http-file-types.d.ts.map +1 -1
  21. package/dist/loader-utils/lib/files/read-range-response.d.ts +3 -0
  22. package/dist/loader-utils/lib/files/read-range-response.d.ts.map +1 -0
  23. package/dist/loader-utils/lib/files/read-range-response.js +62 -0
  24. package/dist/loader-utils/lib/files/read-range-response.js.map +1 -0
  25. package/dist/loader-utils/lib/log-utils/log.js +1 -1
  26. package/dist/loader-utils/lib/scan-utils/logical-table-query.d.ts +38 -0
  27. package/dist/loader-utils/lib/scan-utils/logical-table-query.d.ts.map +1 -0
  28. package/dist/loader-utils/lib/scan-utils/logical-table-query.js +96 -0
  29. package/dist/loader-utils/lib/scan-utils/logical-table-query.js.map +1 -0
  30. package/dist/loader-utils/lib/scan-utils/{experimental-scan-options.d.ts → query-options.d.ts} +5 -8
  31. package/dist/loader-utils/lib/scan-utils/query-options.d.ts.map +1 -0
  32. package/dist/loader-utils/lib/scan-utils/{experimental-scan-options.js → query-options.js} +1 -1
  33. package/dist/loader-utils/lib/scan-utils/query-options.js.map +1 -0
  34. package/dist/loader-utils/lib/scan-utils/scan-query-metadata.d.ts +12 -17
  35. package/dist/loader-utils/lib/scan-utils/scan-query-metadata.d.ts.map +1 -1
  36. package/dist/loader-utils/lib/scan-utils/scan-query-metadata.js +5 -5
  37. package/dist/loader-utils/lib/scan-utils/scan-query-metadata.js.map +1 -1
  38. package/dist/loader-utils/lib/scan-utils/table-query.d.ts +33 -3
  39. package/dist/loader-utils/lib/scan-utils/table-query.d.ts.map +1 -1
  40. package/dist/loader-utils/lib/scan-utils/table-query.js.map +1 -1
  41. package/dist/loader-utils/lib/scan-utils/table-scan-batch.d.ts +2 -2
  42. package/dist/loader-utils/lib/scan-utils/table-scan-batch.d.ts.map +1 -1
  43. package/dist/loader-utils/lib/scan-utils/table-scan-batch.js +11 -3
  44. package/dist/loader-utils/lib/scan-utils/table-scan-batch.js.map +1 -1
  45. package/dist/loader-utils/lib/sources/data-source.d.ts +4 -0
  46. package/dist/loader-utils/lib/sources/data-source.d.ts.map +1 -1
  47. package/dist/loader-utils/lib/sources/data-source.js +50 -1
  48. package/dist/loader-utils/lib/sources/data-source.js.map +1 -1
  49. package/dist/loader-utils/lib/sources/table-source-collection.d.ts +30 -0
  50. package/dist/loader-utils/lib/sources/table-source-collection.d.ts.map +1 -0
  51. package/dist/loader-utils/lib/sources/table-source-collection.js +5 -0
  52. package/dist/loader-utils/lib/sources/table-source-collection.js.map +1 -0
  53. package/dist/loader-utils/loader-types.d.ts +5 -5
  54. package/dist/loader-utils/loader-types.d.ts.map +1 -1
  55. package/dist/null-loader.js +1 -1
  56. package/dist/null-worker-node.js +1 -1
  57. package/dist/null-worker.js +1 -1
  58. package/dist/scan/arrow-execution/filter-arrow-table.cjs +254 -0
  59. package/dist/scan/arrow-execution/filter-arrow-table.cjs.map +7 -0
  60. package/dist/scan/arrow-execution/filter-arrow-table.d.ts +16 -0
  61. package/dist/scan/arrow-execution/filter-arrow-table.d.ts.map +1 -0
  62. package/dist/scan/arrow-execution/filter-arrow-table.js +222 -0
  63. package/dist/scan/arrow-execution/filter-arrow-table.js.map +1 -0
  64. package/dist/scan/arrow-execution/project-arrow-table.cjs +70 -0
  65. package/dist/scan/arrow-execution/project-arrow-table.cjs.map +7 -0
  66. package/dist/scan/arrow-execution/project-arrow-table.d.ts +8 -0
  67. package/dist/scan/arrow-execution/project-arrow-table.d.ts.map +1 -0
  68. package/dist/scan/arrow-execution/project-arrow-table.js +39 -0
  69. package/dist/scan/arrow-execution/project-arrow-table.js.map +1 -0
  70. package/dist/scan/arrow-execution.cjs +34 -0
  71. package/dist/scan/arrow-execution.cjs.map +7 -0
  72. package/dist/scan/arrow-execution.d.ts +4 -0
  73. package/dist/scan/arrow-execution.d.ts.map +1 -0
  74. package/dist/scan/arrow-execution.js +6 -0
  75. package/dist/scan/arrow-execution.js.map +1 -0
  76. package/dist/scan/arrow-query.cjs.map +1 -1
  77. package/dist/scan/arrow-query.d.ts +1 -1
  78. package/dist/scan/arrow-query.d.ts.map +1 -1
  79. package/dist/scan/catalog-query-source.cjs +122 -0
  80. package/dist/scan/catalog-query-source.cjs.map +7 -0
  81. package/dist/scan/catalog-query-source.d.ts +6 -0
  82. package/dist/scan/catalog-query-source.d.ts.map +1 -0
  83. package/dist/scan/catalog-query-source.js +115 -0
  84. package/dist/scan/catalog-query-source.js.map +1 -0
  85. package/dist/scan/federated-table-scan-source.cjs +4 -4
  86. package/dist/scan/federated-table-scan-source.cjs.map +2 -2
  87. package/dist/scan/federated-table-scan-source.d.ts +1 -1
  88. package/dist/scan/federated-table-scan-source.d.ts.map +1 -1
  89. package/dist/scan/federated-table-scan-source.js +4 -4
  90. package/dist/scan/federated-table-scan-source.js.map +1 -1
  91. package/dist/scan/index.cjs +188 -4
  92. package/dist/scan/index.cjs.map +4 -4
  93. package/dist/scan/index.d.ts +9 -2
  94. package/dist/scan/index.d.ts.map +1 -1
  95. package/dist/scan/index.js +4 -0
  96. package/dist/scan/index.js.map +1 -1
  97. package/dist/scan/parse-sql-predicate.cjs +3 -3
  98. package/dist/scan/parse-sql-predicate.cjs.map +2 -2
  99. package/dist/scan/parse-sql-predicate.d.ts +5 -2
  100. package/dist/scan/parse-sql-predicate.d.ts.map +1 -1
  101. package/dist/scan/parse-sql-predicate.js +3 -10
  102. package/dist/scan/parse-sql-predicate.js.map +1 -1
  103. package/dist/scan/parse-sql-query.cjs +70 -0
  104. package/dist/scan/parse-sql-query.cjs.map +7 -0
  105. package/dist/scan/parse-sql-query.d.ts +5 -0
  106. package/dist/scan/parse-sql-query.d.ts.map +1 -0
  107. package/dist/scan/parse-sql-query.js +49 -0
  108. package/dist/scan/parse-sql-query.js.map +1 -0
  109. package/dist/scan/parse-sql-select.cjs +215 -0
  110. package/dist/scan/parse-sql-select.cjs.map +7 -0
  111. package/dist/scan/parse-sql-select.d.ts +38 -0
  112. package/dist/scan/parse-sql-select.d.ts.map +1 -0
  113. package/dist/scan/parse-sql-select.js +208 -0
  114. package/dist/scan/parse-sql-select.js.map +1 -0
  115. package/dist/scan/query-arrow-table-in-batches.cjs +65 -0
  116. package/dist/scan/query-arrow-table-in-batches.cjs.map +7 -0
  117. package/dist/scan/query-arrow-table-in-batches.d.ts +8 -0
  118. package/dist/scan/query-arrow-table-in-batches.d.ts.map +1 -0
  119. package/dist/scan/query-arrow-table-in-batches.js +44 -0
  120. package/dist/scan/query-arrow-table-in-batches.js.map +1 -0
  121. package/dist/scan/query-arrow-table.cjs +52 -179
  122. package/dist/scan/query-arrow-table.cjs.map +3 -3
  123. package/dist/scan/query-arrow-table.d.ts +4 -37
  124. package/dist/scan/query-arrow-table.d.ts.map +1 -1
  125. package/dist/scan/query-arrow-table.js +37 -188
  126. package/dist/scan/query-arrow-table.js.map +1 -1
  127. package/dist/scan/query.cjs +257 -0
  128. package/dist/scan/query.cjs.map +7 -0
  129. package/dist/scan/query.d.ts +44 -0
  130. package/dist/scan/query.d.ts.map +1 -0
  131. package/dist/scan/query.js +246 -0
  132. package/dist/scan/query.js.map +1 -0
  133. package/dist/scan/resolve-query-source.cjs +59 -0
  134. package/dist/scan/resolve-query-source.cjs.map +7 -0
  135. package/dist/scan/resolve-query-source.d.ts +6 -0
  136. package/dist/scan/resolve-query-source.d.ts.map +1 -0
  137. package/dist/scan/resolve-query-source.js +37 -0
  138. package/dist/scan/resolve-query-source.js.map +1 -0
  139. package/dist/scan/sql-catalog.cjs +110 -0
  140. package/dist/scan/sql-catalog.cjs.map +7 -0
  141. package/dist/scan/sql-catalog.d.ts +47 -0
  142. package/dist/scan/sql-catalog.d.ts.map +1 -0
  143. package/dist/scan/sql-catalog.js +97 -0
  144. package/dist/scan/sql-catalog.js.map +1 -0
  145. package/dist/scan/table-query.cjs.map +2 -2
  146. package/dist/scan/table-query.d.ts +4 -1
  147. package/dist/scan/table-query.d.ts.map +1 -1
  148. package/dist/scan/table-query.js.map +1 -1
  149. package/dist/vector-table-scan-source.cjs +281 -193
  150. package/dist/vector-table-scan-source.cjs.map +3 -3
  151. package/dist/worker-utils/index.cjs +2 -1
  152. package/dist/worker-utils/index.cjs.map +1 -1
  153. package/dist/worker-utils/lib/env-utils/version.js +1 -1
  154. package/dist/worker-utils/lib/library-utils/library-utils.js +1 -1
  155. package/dist/worker-utils/lib/library-utils/library-utils.js.map +1 -1
  156. package/package.json +17 -7
  157. package/src/loader-utils/index.ts +30 -6
  158. package/src/loader-utils/lib/files/http-file-transport.ts +65 -1
  159. package/src/loader-utils/lib/files/http-file-types.ts +2 -0
  160. package/src/loader-utils/lib/files/read-range-response.ts +66 -0
  161. package/src/loader-utils/lib/scan-utils/logical-table-query.ts +164 -0
  162. package/src/loader-utils/lib/scan-utils/query-options.ts +44 -0
  163. package/src/loader-utils/lib/scan-utils/scan-query-metadata.ts +17 -26
  164. package/src/loader-utils/lib/scan-utils/table-query.ts +49 -8
  165. package/src/loader-utils/lib/scan-utils/table-scan-batch.ts +25 -9
  166. package/src/loader-utils/lib/sources/data-source.ts +54 -1
  167. package/src/loader-utils/lib/sources/table-source-collection.ts +38 -0
  168. package/src/loader-utils/loader-types.ts +5 -5
  169. package/src/scan/arrow-execution/filter-arrow-table.ts +293 -0
  170. package/src/scan/arrow-execution/project-arrow-table.ts +53 -0
  171. package/src/scan/arrow-execution.ts +7 -0
  172. package/src/scan/arrow-query.ts +3 -0
  173. package/src/scan/catalog-query-source.ts +132 -0
  174. package/src/scan/federated-table-scan-source.ts +19 -19
  175. package/src/scan/index.ts +28 -4
  176. package/src/scan/parse-sql-predicate.ts +9 -3
  177. package/src/scan/parse-sql-query.ts +53 -0
  178. package/src/scan/parse-sql-select.ts +220 -0
  179. package/src/scan/query-arrow-table-in-batches.ts +58 -0
  180. package/src/scan/query-arrow-table.ts +60 -237
  181. package/src/scan/query.ts +339 -0
  182. package/src/scan/resolve-query-source.ts +47 -0
  183. package/src/scan/sql-catalog.ts +167 -0
  184. package/src/scan/table-query.ts +6 -1
  185. package/src/worker-utils/lib/library-utils/library-utils.ts +1 -1
  186. package/dist/loader-utils/lib/scan-utils/experimental-scan-options.d.ts.map +0 -1
  187. package/dist/loader-utils/lib/scan-utils/experimental-scan-options.js.map +0 -1
  188. package/src/loader-utils/lib/scan-utils/experimental-scan-options.ts +0 -46
@@ -0,0 +1,66 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /** Reads a bounded exact byte-range response without requiring total-size discovery. */
6
+ export async function readRangeResponse(
7
+ response: Response,
8
+ offset: number | bigint,
9
+ length: number,
10
+ signal?: AbortSignal
11
+ ): Promise<Uint8Array> {
12
+ if (
13
+ (typeof offset === 'number' && (!Number.isSafeInteger(offset) || offset < 0)) ||
14
+ (typeof offset === 'bigint' && offset < 0n) ||
15
+ !Number.isSafeInteger(length) ||
16
+ length <= 0
17
+ ) {
18
+ await response.body?.cancel().catch(() => {});
19
+ throw new RangeError('Invalid HTTP byte range');
20
+ }
21
+ const start = BigInt(offset);
22
+ const end = start + BigInt(length) - 1n;
23
+ const value = response.headers.get('Content-Range');
24
+ const match = value === null ? null : /^bytes (\d+)-(\d+)\/(\d+|\*)$/.exec(value);
25
+ // CORS may hide metadata while still allowing a safelisted single Range.
26
+ // Never treat empty/malformed visible metadata as an absent header.
27
+ if (
28
+ response.status !== 206 ||
29
+ (value !== null &&
30
+ (!match ||
31
+ BigInt(match[1]) !== start ||
32
+ BigInt(match[2]) !== end ||
33
+ (match[3] !== '*' && BigInt(match[3]) <= end)))
34
+ ) {
35
+ await response.body?.cancel().catch(() => {});
36
+ throw new Error('HTTP range requires 206 and matching Content-Range when visible');
37
+ }
38
+ const reader = response.body?.getReader();
39
+ if (!reader) throw new Error('HTTP range response has no body');
40
+ let received = 0;
41
+ const abort = () => {
42
+ void reader.cancel(signal?.reason).catch(() => {});
43
+ };
44
+ signal?.addEventListener('abort', abort, {once: true});
45
+ try {
46
+ signal?.throwIfAborted();
47
+ const bytes = new Uint8Array(length);
48
+ for (;;) {
49
+ const chunk = await reader.read();
50
+ signal?.throwIfAborted();
51
+ if (chunk.done) break;
52
+ if (received + chunk.value.byteLength > length)
53
+ throw new Error('HTTP range body exceeds requested length');
54
+ bytes.set(chunk.value, received);
55
+ received += chunk.value.byteLength;
56
+ }
57
+ if (received !== length) throw new Error('HTTP range body has truncated length');
58
+ return bytes;
59
+ } catch (error) {
60
+ await reader.cancel(error).catch(() => {});
61
+ throw error;
62
+ } finally {
63
+ signal?.removeEventListener('abort', abort);
64
+ reader.releaseLock();
65
+ }
66
+ }
@@ -0,0 +1,164 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {
6
+ validateColumnarPredicate,
7
+ type ColumnarPredicate,
8
+ type ColumnarPredicateProperty
9
+ } from './columnar-predicate';
10
+ import {
11
+ planTableQuery,
12
+ validateTableQueryLimit,
13
+ type TableQuery,
14
+ type TableReference,
15
+ type TableQueryPlanStep
16
+ } from './table-query';
17
+
18
+ /** Explicit source-to-output mapping for one selected field. */
19
+ export type NormalizedTableSelection = Readonly<{
20
+ /** Column read from the source. */
21
+ column: string;
22
+ /** Name of the returned field. */
23
+ as: string;
24
+ }>;
25
+
26
+ /** Logical query with all output selections expanded into explicit mappings. */
27
+ export type NormalizedTableQuery<PredicateT = ColumnarPredicate> = Readonly<{
28
+ /** Optional source reference preserved separately from physical scan operations. */
29
+ from?: TableReference;
30
+ /** Output mappings in caller-specified order. */
31
+ select: readonly NormalizedTableSelection[];
32
+ /** Predicate resolved against source names before aliases. */
33
+ where?: PredicateT;
34
+ /** Global post-filter row limit. */
35
+ limit?: number;
36
+ }>;
37
+
38
+ /** Logical projection retaining source names separately from output names. */
39
+ export type LogicalTableQueryProjectStep = Readonly<{
40
+ /** Plan discriminator. */
41
+ kind: 'project';
42
+ /** Output mappings applied after filtering. */
43
+ select: readonly NormalizedTableSelection[];
44
+ }>;
45
+
46
+ /** Scan, filter, aliased projection, and limit operations in execution order. */
47
+ export type LogicalTableQueryPlan<PredicateT = ColumnarPredicate> = readonly (
48
+ | Exclude<TableQueryPlanStep<PredicateT>, {kind: 'project'}>
49
+ | LogicalTableQueryProjectStep
50
+ )[];
51
+
52
+ /** Validates logical query fields and expands selections without modifying caller input. */
53
+ export function normalizeTableQuery<
54
+ PredicateT extends ColumnarPredicate<unknown, ColumnarPredicateProperty> = ColumnarPredicate
55
+ >(
56
+ sourceColumnNames: readonly string[],
57
+ query: TableQuery<PredicateT> = {}
58
+ ): NormalizedTableQuery<PredicateT> {
59
+ if (!query || typeof query !== 'object' || Array.isArray(query)) {
60
+ throw new Error('Table query must be an object.');
61
+ }
62
+ for (const key of Object.keys(query)) {
63
+ if (!['from', 'select', 'where', 'limit'].includes(key)) {
64
+ throw new Error(`Unsupported table query option: ${key}`);
65
+ }
66
+ }
67
+ if (query.select !== undefined && (!Array.isArray(query.select) || query.select.length === 0)) {
68
+ throw new Error('Table query select must be a non-empty array.');
69
+ }
70
+ validateTableReference(query.from);
71
+ validateTableQueryLimit(query.limit);
72
+ if (query.where !== undefined) {
73
+ validateColumnarPredicate(query.where, new Set(sourceColumnNames));
74
+ }
75
+ const outputNames = new Set<string>();
76
+ const select = (query.select ?? sourceColumnNames).map(selection => {
77
+ if (
78
+ typeof selection !== 'string' &&
79
+ (!selection || typeof selection !== 'object' || Array.isArray(selection))
80
+ ) {
81
+ throw new Error('Table query selection must be a column name or {column, as}.');
82
+ }
83
+ if (
84
+ typeof selection !== 'string' &&
85
+ Object.keys(selection).some(key => key !== 'column' && key !== 'as')
86
+ ) {
87
+ throw new Error('Unsupported table query selection field.');
88
+ }
89
+ const column = typeof selection === 'string' ? selection : selection.column;
90
+ const outputName =
91
+ typeof selection === 'string'
92
+ ? selection
93
+ : selection.as === undefined
94
+ ? column
95
+ : selection.as;
96
+ if (typeof column !== 'string' || !sourceColumnNames.includes(column)) {
97
+ throw new Error(`Table query column not found: ${column}`);
98
+ }
99
+ if (typeof outputName !== 'string' || outputName.length === 0) {
100
+ throw new Error('Table query output name must be a non-empty string.');
101
+ }
102
+ if (outputNames.has(outputName)) {
103
+ throw new Error(`Duplicate table query output name: ${outputName}`);
104
+ }
105
+ outputNames.add(outputName);
106
+ return Object.freeze({column, as: outputName});
107
+ });
108
+ // Reuse source-column and predicate validation; aliases never participate in WHERE resolution.
109
+ planTableQuery(sourceColumnNames, {
110
+ columns: [...new Set(select.map(selection => selection.column))],
111
+ predicate: query.where,
112
+ limit: query.limit
113
+ });
114
+ return Object.freeze({
115
+ select: Object.freeze(select),
116
+ ...(query.from === undefined
117
+ ? {}
118
+ : {from: typeof query.from === 'string' ? query.from : Object.freeze({...query.from})}),
119
+ ...(query.where === undefined ? {} : {where: query.where}),
120
+ ...(query.limit === undefined ? {} : {limit: query.limit})
121
+ });
122
+ }
123
+
124
+ /** Builds a logical plan using the shared scan planner and an explicit aliased projection. */
125
+ export function planLogicalTableQuery<
126
+ PredicateT extends ColumnarPredicate<unknown, ColumnarPredicateProperty> = ColumnarPredicate
127
+ >(
128
+ sourceColumnNames: readonly string[],
129
+ query: TableQuery<PredicateT> = {}
130
+ ): LogicalTableQueryPlan<PredicateT> {
131
+ const normalized = normalizeTableQuery(sourceColumnNames, query);
132
+ const plan = planTableQuery(sourceColumnNames, {
133
+ columns: [...new Set(normalized.select.map(selection => selection.column))],
134
+ predicate: normalized.where,
135
+ limit: normalized.limit
136
+ });
137
+ return Object.freeze(
138
+ plan.map(step =>
139
+ step.kind === 'project'
140
+ ? Object.freeze({kind: 'project' as const, select: normalized.select})
141
+ : step
142
+ )
143
+ );
144
+ }
145
+
146
+ /** Validates identifiers without interpreting dots or rewriting quoted names. */
147
+ export function validateTableReference(
148
+ reference: unknown
149
+ ): asserts reference is TableReference | undefined {
150
+ if (reference === undefined) return;
151
+ if (typeof reference === 'string' && reference.trim()) return;
152
+ if (reference && typeof reference === 'object' && !Array.isArray(reference)) {
153
+ const value = reference as Record<string, unknown>;
154
+ if (
155
+ Object.keys(value).every(key => key === 'source' || key === 'table') &&
156
+ typeof value.source === 'string' &&
157
+ value.source.trim() &&
158
+ typeof value.table === 'string' &&
159
+ value.table.trim()
160
+ )
161
+ return;
162
+ }
163
+ throw new Error('FROM must be a source name or {source, table} with non-empty names.');
164
+ }
@@ -0,0 +1,44 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {ColumnarPredicate} from './columnar-predicate';
6
+ import type {ScanBounds} from './scan-query-metadata';
7
+ import type {TableQueryExecutionOptions} from './table-query';
8
+
9
+ /**
10
+ * Common query request accepted by loaders that implement the scan protocol.
11
+ *
12
+ * Format loaders apply the fields relevant to their query family and must reject unsupported
13
+ * fields rather than silently ignoring them. This intentionally remains a common superset in 5.0
14
+ * so applications and Deck.gl adapters can forward one stable option object.
15
+ */
16
+ export type QueryOptions = TableQueryExecutionOptions &
17
+ Readonly<{
18
+ /** Portable predicate for table-like sources. */
19
+ predicate?: ColumnarPredicate;
20
+ /** Output columns or bands selected by the caller. */
21
+ columns?: readonly string[];
22
+ /** Maximum number of rows or points retained after filtering. */
23
+ limit?: number;
24
+ /** Source-coordinate bounds for spatial, raster, and point-cloud scans. */
25
+ bounds?: ScanBounds;
26
+ /** Raster overview or point-cloud hierarchy level. */
27
+ level?: number;
28
+ /** Shallowest point-cloud hierarchy level to read. */
29
+ minimumLevel?: number;
30
+ /** Deepest point-cloud hierarchy level to read. */
31
+ maximumLevel?: number;
32
+ /** Desired maximum point spacing for point-cloud scans. */
33
+ targetSpacing?: number;
34
+ /** Requested raster output width in pixels. */
35
+ width?: number;
36
+ /** Requested raster output height in pixels. */
37
+ height?: number;
38
+ /** Named raster variables or bands. */
39
+ variables?: readonly string[];
40
+ /** Numeric raster channel indices. */
41
+ channels?: readonly number[];
42
+ /** Raster dimension indices or half-open ranges. */
43
+ slices?: Readonly<Record<string, number | readonly [number, number]>>;
44
+ }>;
@@ -7,7 +7,8 @@ import type {ColumnarPredicate, ColumnarPredicateProperty} from './columnar-pred
7
7
  import type {
8
8
  TableQueryCapabilities,
9
9
  TableQueryOperatorSupport,
10
- TableQueryOptions
10
+ TableQueryOptions,
11
+ TableQueryExecutionOptions
11
12
  } from './table-query';
12
13
  import type {PointCloudQueryOptions} from './point-cloud-query';
13
14
  import type {RasterQueryCapabilities} from './raster-query';
@@ -153,14 +154,10 @@ export type ScanQueryMetadataOptions = Readonly<{
153
154
  }>;
154
155
 
155
156
  /** Terminal state of one observable scan execution. */
156
- export type ScanExecutionTelemetryStatus =
157
- | 'completed'
158
- | 'early-terminated'
159
- | 'cancelled'
160
- | 'failed';
157
+ export type TableQueryExecutionStatus = 'completed' | 'early-terminated' | 'cancelled' | 'failed';
161
158
 
162
159
  /** Portable execution counters for one physical source in a federated scan. */
163
- export type ScanSourceExecutionTelemetry = Readonly<{
160
+ export type TableQuerySourceExecutionSummary = Readonly<{
164
161
  /** Stable registry id when the source was resolved through a DataSourceManager. */
165
162
  sourceId?: string;
166
163
  /** Format or adapter type reported by scan metadata. */
@@ -168,7 +165,7 @@ export type ScanSourceExecutionTelemetry = Readonly<{
168
165
  /** Zero-based append position for a federated source. */
169
166
  sourceIndex?: number;
170
167
  /** Terminal state of this physical source iterator. */
171
- status: ScanExecutionTelemetryStatus;
168
+ status: TableQueryExecutionStatus;
172
169
  /** Physical files opened by this source, when measurable. */
173
170
  filesOpened?: number;
174
171
  /** Independently scheduled physical tasks opened by this source, when measurable. */
@@ -196,9 +193,9 @@ export type ScanSourceExecutionTelemetry = Readonly<{
196
193
  }>;
197
194
 
198
195
  /** Portable execution counters reported when a table scan terminates. */
199
- export type ScanExecutionTelemetry = Readonly<{
196
+ export type TableQueryExecutionSummary = Readonly<{
200
197
  /** Terminal state distinguishing completion, early return, cancellation, and failure. */
201
- status: ScanExecutionTelemetryStatus;
198
+ status: TableQueryExecutionStatus;
202
199
  /** Number of physical sources included in the resolved plan. */
203
200
  sourcesPlanned: number;
204
201
  /** Number of physical source iterators that were opened. */
@@ -230,7 +227,7 @@ export type ScanExecutionTelemetry = Readonly<{
230
227
  /** Why a successfully shortened execution stopped before exhausting its plan. */
231
228
  earlyTerminationReason?: 'limit' | 'consumer-return';
232
229
  /** Per-source physical counters in deterministic append order. */
233
- sources?: readonly ScanSourceExecutionTelemetry[];
230
+ sources?: readonly TableQuerySourceExecutionSummary[];
234
231
  /** Source-specific immutable counters retained for detailed diagnostics. */
235
232
  details?: Readonly<Record<string, unknown>>;
236
233
  /** Failure or cancellation reason when one terminated the scan. */
@@ -238,21 +235,21 @@ export type ScanExecutionTelemetry = Readonly<{
238
235
  }>;
239
236
 
240
237
  /** Receives the immutable final counters for one table scan execution. */
241
- export type ScanExecutionTelemetryCallback = (telemetry: ScanExecutionTelemetry) => void;
238
+ export type TableQueryCompleteCallback = (summary: TableQueryExecutionSummary) => void;
242
239
 
243
240
  /**
244
- * Delivers a scan telemetry snapshot without allowing an observer failure to alter scan results.
245
- * Telemetry is best-effort by design: exporters and diagnostics must not become query failures.
241
+ * Delivers a terminal query summary without allowing an observer failure to alter scan results.
242
+ * Completion observers are best-effort and must not become query failures.
246
243
  */
247
- export function emitScanExecutionTelemetry(
248
- callback: ScanExecutionTelemetryCallback | undefined,
249
- telemetry: ScanExecutionTelemetry
244
+ export function emitQueryComplete(
245
+ callback: TableQueryCompleteCallback | undefined,
246
+ summary: TableQueryExecutionSummary
250
247
  ): void {
251
248
  if (!callback) return;
252
249
  try {
253
- callback(telemetry);
250
+ callback(summary);
254
251
  } catch {
255
- // Telemetry observers must never change scan behavior.
252
+ // Completion observers must never change query behavior.
256
253
  }
257
254
  }
258
255
 
@@ -268,13 +265,7 @@ export type TableScanReadOptions<
268
265
  unknown,
269
266
  ColumnarPredicateProperty
270
267
  >
271
- > = TableQueryOptions<PredicateT> &
272
- Readonly<{
273
- /** Cooperatively cancels source discovery and execution. */
274
- signal?: AbortSignal;
275
- /** Receives one terminal execution snapshot without changing query semantics. */
276
- onTelemetry?: ScanExecutionTelemetryCallback;
277
- }>;
268
+ > = TableQueryOptions<PredicateT> & TableQueryExecutionOptions;
278
269
 
279
270
  /**
280
271
  * Shared table-scan contract implemented by format-specific executors.
@@ -9,20 +9,61 @@ import {
9
9
  type ColumnarPredicateProperty
10
10
  } from './columnar-predicate';
11
11
 
12
- /** Immutable, backend-neutral request for a scan, filter, projection, and limit. */
13
- export type TableQueryOptions<
12
+ /** One source column selected for logical output, optionally under a new name. */
13
+ export type TableSelection =
14
+ | string
15
+ | Readonly<{
16
+ /** Source column name, resolved before aliases are applied. */
17
+ column: string;
18
+ /** Output field name. Defaults to the source column name. */
19
+ as?: string;
20
+ }>;
21
+
22
+ /** Named source, or a named table exposed by a source. Strings are literal names, not dotted paths. */
23
+ export type TableReference =
24
+ | string
25
+ | Readonly<{
26
+ /** Name of a registered data source. */
27
+ source: string;
28
+ /** Name of a table exposed by that source. */
29
+ table: string;
30
+ }>;
31
+
32
+ /** Logical query description, independent of cancellation and execution observers. */
33
+ export type TableQuery<
14
34
  PredicateT extends ColumnarPredicate<unknown, ColumnarPredicateProperty> = ColumnarPredicate
15
35
  > = Readonly<{
16
- /** Portable predicate applied before projection. */
17
- predicate?: PredicateT;
18
- /** Output columns in caller-specified order. Defaults to every source column. */
19
- columns?: readonly string[];
20
- /** Maximum number of rows retained after filtering and projection. */
36
+ /** Optional named source or qualified table selected before planning. */
37
+ from?: TableReference;
38
+ /** Output columns in selection order. Omission selects all source columns. */
39
+ select?: readonly TableSelection[];
40
+ /** Predicate evaluated against source columns before output aliases are applied. */
41
+ where?: PredicateT;
42
+ /** Maximum number of rows retained after filtering. */
21
43
  limit?: number;
22
- /** Cancels discovery and batch production. */
44
+ }>;
45
+
46
+ /** Controls one execution without becoming part of the logical query. */
47
+ export type TableQueryExecutionOptions = Readonly<{
48
+ /** Cooperatively cancels source discovery and execution. */
23
49
  signal?: AbortSignal;
50
+ /** Receives one terminal summary, including cancellation, failure, and early termination. */
51
+ onQueryComplete?: import('./scan-query-metadata').TableQueryCompleteCallback;
24
52
  }>;
25
53
 
54
+ /** Immutable, backend-neutral request for a scan, filter, projection, and limit. */
55
+ export type TableQueryOptions<
56
+ PredicateT extends ColumnarPredicate<unknown, ColumnarPredicateProperty> = ColumnarPredicate
57
+ > = Pick<TableQueryExecutionOptions, 'signal'> &
58
+ Readonly<{
59
+ /** Portable predicate applied before projection. */
60
+ predicate?: PredicateT;
61
+ /** Output columns in caller-specified order. Defaults to every source column. */
62
+ columns?: readonly string[];
63
+ /** Maximum number of rows retained after filtering and projection. */
64
+ limit?: number;
65
+ }>;
66
+
26
67
  /** Reads the minimum source columns required by the remaining table-query plan. */
27
68
  export type TableQueryScanStep = Readonly<{
28
69
  /** Plan discriminator. */
@@ -3,8 +3,8 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {ArrowTable, ArrowTableBatch, TableBatch} from '@loaders.gl/core/schema';
6
- import type {TableScanReadOptions, ScanExecutionTelemetry} from './scan-query-metadata';
7
- import {emitScanExecutionTelemetry} from './scan-query-metadata';
6
+ import type {TableScanReadOptions, TableQueryExecutionSummary} from './scan-query-metadata';
7
+ import {emitQueryComplete} from './scan-query-metadata';
8
8
  import {filterColumnarRowIndices, validateColumnarPredicate} from './columnar-predicate';
9
9
  import {validateTableQueryLimit} from './table-query';
10
10
 
@@ -16,8 +16,12 @@ export type TableScanBatchReader = (
16
16
 
17
17
  /** Optional batch kernels for formats with a native vectorized predicate implementation. */
18
18
  export type TableScanBatchOperators = Readonly<{
19
- /** Applies a residual predicate while preserving the source batch shape. */
20
- filter?: (batch: TableBatch, predicate: TableScanReadOptions['predicate']) => TableBatch;
19
+ /** Applies a residual predicate locally or on a worker; async kernels must observe the signal. */
20
+ filter?: (
21
+ batch: TableBatch,
22
+ predicate: TableScanReadOptions['predicate'],
23
+ signal?: AbortSignal
24
+ ) => TableBatch | Promise<TableBatch>;
21
25
  /** Applies a projection while preserving the source batch shape. */
22
26
  project?: (batch: TableBatch, columns?: readonly string[]) => TableBatch;
23
27
  }>;
@@ -48,12 +52,13 @@ export async function* executeTableScanBatches(
48
52
  let rowsRetained = 0;
49
53
  let rowsReturned = 0;
50
54
  let bytesFetched = 0;
51
- let status: ScanExecutionTelemetry['status'] = 'early-terminated';
52
- let earlyTerminationReason: ScanExecutionTelemetry['earlyTerminationReason'];
55
+ let status: TableQueryExecutionSummary['status'] = 'early-terminated';
56
+ let earlyTerminationReason: TableQueryExecutionSummary['earlyTerminationReason'];
53
57
  let executionError: unknown;
54
58
  let remaining =
55
59
  options.limit === undefined ? Number.POSITIVE_INFINITY : Math.max(0, options.limit);
56
60
  try {
61
+ options.signal?.throwIfAborted();
57
62
  if (remaining <= 0) {
58
63
  earlyTerminationReason = 'limit';
59
64
  return;
@@ -67,9 +72,15 @@ export async function* executeTableScanBatches(
67
72
  earlyTerminationReason = 'limit';
68
73
  return;
69
74
  }
75
+ options.signal?.throwIfAborted();
70
76
  batchesRead++;
71
77
  rowsRead += batch.length;
72
- const filteredBatch = (operators.filter || filterTableBatch)(batch, options.predicate);
78
+ const filteredBatch = await (operators.filter || filterTableBatch)(
79
+ batch,
80
+ options.predicate,
81
+ options.signal
82
+ );
83
+ options.signal?.throwIfAborted();
73
84
  if (options.predicate) {
74
85
  rowsTested += batch.length;
75
86
  rowsRetained += filteredBatch.length;
@@ -82,6 +93,11 @@ export async function* executeTableScanBatches(
82
93
  remaining -= projectedBatch.length;
83
94
  rowsReturned += projectedBatch.length;
84
95
  yield projectedBatch;
96
+ if (remaining === 0) {
97
+ earlyTerminationReason = 'limit';
98
+ return;
99
+ }
100
+ options.signal?.throwIfAborted();
85
101
  } else {
86
102
  const outputBatch = truncateTableBatch(projectedBatch, remaining);
87
103
  rowsReturned += outputBatch.length;
@@ -99,8 +115,8 @@ export async function* executeTableScanBatches(
99
115
  if (status === 'early-terminated' && !earlyTerminationReason) {
100
116
  earlyTerminationReason = 'consumer-return';
101
117
  }
102
- emitScanExecutionTelemetry(
103
- options.onTelemetry,
118
+ emitQueryComplete(
119
+ options.onQueryComplete,
104
120
  Object.freeze({
105
121
  status,
106
122
  sourcesPlanned: 1,
@@ -18,6 +18,8 @@ export type DataSourceOptions = StrictLoaderOptions & {
18
18
  core?: StrictLoaderOptions['core'] & {
19
19
  /** Allows application to specify which source should be selected. Matches `Source.type`. Defaults to 'auto' */
20
20
  type?: string;
21
+ /** Stable query-visible source name. Defaults to an available data or file name. */
22
+ name?: string;
21
23
  /** Any dataset attributions (in case underlying metadata does not include attributions) */
22
24
  attributions?: string[];
23
25
  /** Removed in v5. Move these options to `core` and the root loader namespaces. */
@@ -95,6 +97,8 @@ export abstract class DataSource<DataT, OptionsT extends DataSourceOptions> {
95
97
  options: Required<OptionsT & DataSourceOptions>;
96
98
  readonly data: DataT;
97
99
  readonly url: string;
100
+ /** Stable query-visible name, resolved without fetching source data. */
101
+ readonly name: string;
98
102
 
99
103
  /** Shared parser options derived from the source options, excluding source-only core controls. */
100
104
  loadOptions: StrictLoaderOptions;
@@ -118,6 +122,7 @@ export abstract class DataSource<DataT, OptionsT extends DataSourceOptions> {
118
122
  ) as Required<OptionsT & DataSourceOptions>;
119
123
  this.data = data;
120
124
  this.url = typeof data === 'string' ? resolvePath(data) : '';
125
+ this.name = getDataSourceName(data, this.options);
121
126
  const loadOptions = resolveAuthenticationOptions(getSourceLoaderOptions(this.options));
122
127
  this.loadOptions = loadOptions;
123
128
  const fetch = getFetchFunction(loadOptions);
@@ -127,6 +132,8 @@ export abstract class DataSource<DataT, OptionsT extends DataSourceOptions> {
127
132
  }
128
133
 
129
134
  setProps(options: OptionsT) {
135
+ if (options.core?.name !== undefined && options.core.name !== this.name)
136
+ throw new Error('Data source names are fixed at creation.');
130
137
  const mergedOptions = mergeOptions<DataSourceOptions>(this.options, options) as Required<
131
138
  OptionsT & DataSourceOptions
132
139
  >;
@@ -193,7 +200,7 @@ export function getSourceLoaderOptions(options: DataSourceOptions): StrictLoader
193
200
  if (options?.core) {
194
201
  loadOptions.core = {...options.core};
195
202
  const parserCore = loadOptions.core as Record<string, unknown>;
196
- for (const key of ['type', 'attributions', 'loaders', 'onError', 'loadOptions']) {
203
+ for (const key of ['type', 'name', 'attributions', 'loaders', 'onError', 'loadOptions']) {
197
204
  delete parserCore[key];
198
205
  }
199
206
  if (Object.keys(parserCore).length === 0) {
@@ -234,3 +241,49 @@ function unavailableCoreApiMethod(methodName: keyof CoreAPI) {
234
241
  );
235
242
  };
236
243
  }
244
+
245
+ /** Derives a stable identifier from explicit options or already available data metadata. */
246
+ function getDataSourceName(data: unknown, options: DataSourceOptions): string {
247
+ const explicitName = options.core?.name;
248
+ if (explicitName !== undefined) {
249
+ if (typeof explicitName !== 'string' || !explicitName.trim())
250
+ throw new Error('Data source name must be a non-empty string.');
251
+ return explicitName;
252
+ }
253
+ if (data && typeof data === 'object') {
254
+ const named = data as {
255
+ name?: unknown;
256
+ schema?: {metadata?: Map<string, unknown> | Record<string, unknown>};
257
+ };
258
+ if (typeof named.name === 'string' && named.name.trim())
259
+ return data instanceof Blob ? removeFileExtension(named.name) : named.name;
260
+ const metadata = named.schema?.metadata;
261
+ const embeddedName = metadata instanceof Map ? metadata.get('name') : metadata?.name;
262
+ if (typeof embeddedName === 'string' && embeddedName.trim()) return embeddedName;
263
+ }
264
+ if (typeof data === 'string') {
265
+ try {
266
+ const url = new URL(data.replace(/\\/g, '/'), 'https://source.invalid/');
267
+ if (!['data:', 'blob:'].includes(url.protocol)) {
268
+ let basename = url.pathname.split('/').filter(Boolean).pop();
269
+ if (basename) {
270
+ try {
271
+ basename = decodeURIComponent(basename);
272
+ } catch {
273
+ /* Keep malformed encoded names literal. */
274
+ }
275
+ return removeFileExtension(basename);
276
+ }
277
+ }
278
+ } catch {
279
+ /* Invalid URLs still receive a source-type fallback name. */
280
+ }
281
+ }
282
+ return options.core?.type && options.core.type !== 'auto' ? options.core.type : 'source';
283
+ }
284
+
285
+ /** Removes a filename suffix without erasing a hidden filename. */
286
+ function removeFileExtension(name: string): string {
287
+ const extension = name.lastIndexOf('.');
288
+ return extension > 0 ? name.slice(0, extension) : name;
289
+ }
@@ -0,0 +1,38 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {ArrowTable, Schema} from '@loaders.gl/core/schema';
6
+ import type {TableScanSource} from '../scan-utils/scan-query-metadata';
7
+
8
+ /** Source exposing named tables. Returned handles remain owned by the source or caller. */
9
+ export interface TableSourceCollection {
10
+ /** Resolves one table without loading unrelated tables. */
11
+ getTable(
12
+ name: string,
13
+ options?: {signal?: AbortSignal}
14
+ ): ArrowTable | TableScanSource | Promise<ArrowTable | TableScanSource>;
15
+ }
16
+
17
+ /** Metadata for one named table without reading its result rows. */
18
+ export type TableMetadata = Readonly<{
19
+ /** Unique loaded table name within its parent source. */
20
+ name: string;
21
+ /** Already available schema; table listings may omit it for lazy discovery. */
22
+ schema?: Schema;
23
+ /** Whether the source exposes this table through the common query contract. */
24
+ queryable?: boolean;
25
+ }>;
26
+
27
+ /** Metadata-only discovery implemented by sources exposing multiple tables. */
28
+ export interface TableDiscoverySource {
29
+ /** Lists table names without opening their row readers. */
30
+ getTablesMetadata(options?: {
31
+ signal?: AbortSignal;
32
+ }): readonly TableMetadata[] | Promise<readonly TableMetadata[]>;
33
+ /** Discovers one table schema without materializing its rows. */
34
+ getTableMetadata?(
35
+ name: string,
36
+ options?: {signal?: AbortSignal}
37
+ ): TableMetadata | Promise<TableMetadata>;
38
+ }