@loaders.gl/core 5.0.0 → 5.0.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.
Files changed (219) hide show
  1. package/dist/api.cjs +4129 -0
  2. package/dist/api.cjs.map +6 -0
  3. package/dist/api.d.ts +34 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/api.js +50 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/arrow-geometry/index.cjs +5 -2
  8. package/dist/arrow-geometry/index.cjs.map +2 -2
  9. package/dist/arrow-geometry/index.d.ts +1 -0
  10. package/dist/arrow-geometry/index.d.ts.map +1 -1
  11. package/dist/arrow-geometry/index.js +1 -0
  12. package/dist/arrow-geometry/index.js.map +1 -1
  13. package/dist/arrow-geometry/triangulate-wkb-geometry-column.cjs +100 -0
  14. package/dist/arrow-geometry/triangulate-wkb-geometry-column.cjs.map +7 -0
  15. package/dist/arrow-geometry/triangulate-wkb-geometry-column.d.ts +15 -0
  16. package/dist/arrow-geometry/triangulate-wkb-geometry-column.d.ts.map +1 -0
  17. package/dist/arrow-geometry/triangulate-wkb-geometry-column.js +87 -0
  18. package/dist/arrow-geometry/triangulate-wkb-geometry-column.js.map +1 -0
  19. package/dist/dist.dev.js +458 -539
  20. package/dist/dist.min.js +3 -3
  21. package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts +1 -1
  22. package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts.map +1 -1
  23. package/dist/geoarrow/index.cjs +1 -1
  24. package/dist/geoarrow/index.cjs.map +1 -1
  25. package/dist/geoarrow/index.d.ts +2 -2
  26. package/dist/geoarrow/index.d.ts.map +1 -1
  27. package/dist/geoarrow/index.js +1 -1
  28. package/dist/geoarrow/index.js.map +1 -1
  29. package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs +1 -1
  30. package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs.map +1 -1
  31. package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts +1 -1
  32. package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts.map +1 -1
  33. package/dist/geoarrow/lib/kernels/decode-wkt-native.js +1 -1
  34. package/dist/geoarrow/lib/kernels/decode-wkt-native.js.map +1 -1
  35. package/dist/index.cjs +67 -4114
  36. package/dist/index.cjs.map +3 -3
  37. package/dist/index.d.ts +1 -33
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +2 -46
  40. package/dist/index.js.map +1 -1
  41. package/dist/lib/api/encode-table.d.ts +4 -4
  42. package/dist/lib/api/encode-table.d.ts.map +1 -1
  43. package/dist/lib/api/encode-table.js +21 -3
  44. package/dist/lib/api/encode-table.js.map +1 -1
  45. package/dist/lib/api/encode.d.ts +6 -6
  46. package/dist/lib/api/encode.d.ts.map +1 -1
  47. package/dist/lib/api/encode.js +46 -7
  48. package/dist/lib/api/encode.js.map +1 -1
  49. package/dist/lib/init.js +1 -1
  50. package/dist/loader-utils/index.cjs +94 -24
  51. package/dist/loader-utils/index.cjs.map +3 -3
  52. package/dist/loader-utils/index.d.ts +3 -2
  53. package/dist/loader-utils/index.d.ts.map +1 -1
  54. package/dist/loader-utils/index.js +2 -1
  55. package/dist/loader-utils/index.js.map +1 -1
  56. package/dist/loader-utils/json-loader-metadata.cjs +85 -0
  57. package/dist/loader-utils/json-loader-metadata.cjs.map +6 -0
  58. package/dist/loader-utils/json-loader-metadata.d.ts +51 -0
  59. package/dist/loader-utils/json-loader-metadata.d.ts.map +1 -0
  60. package/dist/loader-utils/json-loader-metadata.js +31 -0
  61. package/dist/loader-utils/json-loader-metadata.js.map +1 -0
  62. package/dist/loader-utils/json-loader.cjs +80 -0
  63. package/dist/loader-utils/json-loader.cjs.map +6 -0
  64. package/dist/loader-utils/json-loader.d.ts +4 -4
  65. package/dist/loader-utils/json-loader.d.ts.map +1 -1
  66. package/dist/loader-utils/json-loader.js +3 -17
  67. package/dist/loader-utils/json-loader.js.map +1 -1
  68. package/dist/loader-utils/lib/log-utils/log.js +1 -1
  69. package/dist/loader-utils/lib/request-utils/authentication.d.ts +2 -0
  70. package/dist/loader-utils/lib/request-utils/authentication.d.ts.map +1 -1
  71. package/dist/loader-utils/lib/request-utils/authentication.js +12 -0
  72. package/dist/loader-utils/lib/request-utils/authentication.js.map +1 -1
  73. package/dist/loader-utils/lib/scan-utils/table-query.d.ts +1 -1
  74. package/dist/loader-utils/lib/scan-utils/table-query.d.ts.map +1 -1
  75. package/dist/loader-utils/lib/sources/data-source.d.ts +1 -1
  76. package/dist/loader-utils/lib/sources/data-source.d.ts.map +1 -1
  77. package/dist/loader-utils/lib/sources/raster-source.d.ts +21 -1
  78. package/dist/loader-utils/lib/sources/raster-source.d.ts.map +1 -1
  79. package/dist/loader-utils/lib/sources/raster-source.js.map +1 -1
  80. package/dist/loader-utils/lib/sources/raster-tile.d.ts +7 -0
  81. package/dist/loader-utils/lib/sources/raster-tile.d.ts.map +1 -0
  82. package/dist/loader-utils/lib/sources/raster-tile.js +34 -0
  83. package/dist/loader-utils/lib/sources/raster-tile.js.map +1 -0
  84. package/dist/loader-utils/lib/sources/utils/utils.d.ts +1 -1
  85. package/dist/loader-utils/lib/sources/utils/utils.d.ts.map +1 -1
  86. package/dist/loader-utils/tile-grid.d.ts +2 -1
  87. package/dist/loader-utils/tile-grid.d.ts.map +1 -1
  88. package/dist/loader-utils/tile-grid.js +1 -1
  89. package/dist/loader-utils/tile-grid.js.map +1 -1
  90. package/dist/loader-utils/writer-types.d.ts +2 -0
  91. package/dist/loader-utils/writer-types.d.ts.map +1 -1
  92. package/dist/null-loader-metadata.cjs +89 -0
  93. package/dist/null-loader-metadata.cjs.map +6 -0
  94. package/dist/null-loader-metadata.d.ts +48 -0
  95. package/dist/null-loader-metadata.d.ts.map +1 -0
  96. package/dist/null-loader-metadata.js +30 -0
  97. package/dist/null-loader-metadata.js.map +1 -0
  98. package/dist/null-loader.cjs +84 -0
  99. package/dist/null-loader.cjs.map +6 -0
  100. package/dist/null-loader.d.ts +6 -6
  101. package/dist/null-loader.d.ts.map +1 -1
  102. package/dist/null-loader.js +2 -15
  103. package/dist/null-loader.js.map +1 -1
  104. package/dist/null-worker-node.js +58 -28
  105. package/dist/null-worker.js +58 -28
  106. package/dist/scan/arrow-execution/expressions.d.ts +1 -1
  107. package/dist/scan/arrow-execution/expressions.d.ts.map +1 -1
  108. package/dist/scan/arrow-query.cjs +2 -0
  109. package/dist/scan/arrow-query.cjs.map +2 -2
  110. package/dist/scan/arrow-query.d.ts +1 -1
  111. package/dist/scan/arrow-query.d.ts.map +1 -1
  112. package/dist/scan/arrow-query.js +1 -1
  113. package/dist/scan/arrow-query.js.map +1 -1
  114. package/dist/scan/index.cjs +16 -22
  115. package/dist/scan/index.cjs.map +2 -2
  116. package/dist/scan/index.d.ts +7 -7
  117. package/dist/scan/index.d.ts.map +1 -1
  118. package/dist/scan/index.js +4 -6
  119. package/dist/scan/index.js.map +1 -1
  120. package/dist/scan/plan-arrow-table-query.d.ts +1 -1
  121. package/dist/scan/plan-arrow-table-query.d.ts.map +1 -1
  122. package/dist/scan/query-arrow-table-in-batches.cjs +7 -19
  123. package/dist/scan/query-arrow-table-in-batches.cjs.map +2 -2
  124. package/dist/scan/query-arrow-table-in-batches.d.ts.map +1 -1
  125. package/dist/scan/query-arrow-table-in-batches.js +7 -22
  126. package/dist/scan/query-arrow-table-in-batches.js.map +1 -1
  127. package/dist/scan/query-executor.cjs +202 -0
  128. package/dist/scan/query-executor.cjs.map +7 -0
  129. package/dist/scan/query-executor.d.ts +27 -0
  130. package/dist/scan/query-executor.d.ts.map +1 -0
  131. package/dist/scan/query-executor.js +203 -0
  132. package/dist/scan/query-executor.js.map +1 -0
  133. package/dist/scan/query.cjs +92 -205
  134. package/dist/scan/query.cjs.map +3 -3
  135. package/dist/scan/query.d.ts +5 -4
  136. package/dist/scan/query.d.ts.map +1 -1
  137. package/dist/scan/query.js +94 -238
  138. package/dist/scan/query.js.map +1 -1
  139. package/dist/schema-utils/index.cjs +182 -0
  140. package/dist/schema-utils/index.cjs.map +3 -3
  141. package/dist/schema-utils/index.d.ts +3 -0
  142. package/dist/schema-utils/index.d.ts.map +1 -1
  143. package/dist/schema-utils/index.js +3 -0
  144. package/dist/schema-utils/index.js.map +1 -1
  145. package/dist/schema-utils/lib/arrow/arrow-converter.d.ts +24 -0
  146. package/dist/schema-utils/lib/arrow/arrow-converter.d.ts.map +1 -0
  147. package/dist/schema-utils/lib/arrow/arrow-converter.js +43 -0
  148. package/dist/schema-utils/lib/arrow/arrow-converter.js.map +1 -0
  149. package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.d.ts +29 -0
  150. package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.d.ts.map +1 -0
  151. package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.js +89 -0
  152. package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.js.map +1 -0
  153. package/dist/schema-utils/lib/arrow/convert-arrow.d.ts +17 -0
  154. package/dist/schema-utils/lib/arrow/convert-arrow.d.ts.map +1 -0
  155. package/dist/schema-utils/lib/arrow/convert-arrow.js +24 -0
  156. package/dist/schema-utils/lib/arrow/convert-arrow.js.map +1 -0
  157. package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.d.ts +4 -0
  158. package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.d.ts.map +1 -0
  159. package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.js +51 -0
  160. package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.js.map +1 -0
  161. package/dist/worker-utils/index.cjs +2 -2
  162. package/dist/worker-utils/lib/env-utils/version.js +1 -1
  163. package/package.json +49 -23
  164. package/src/api.ts +99 -0
  165. package/src/arrow-geometry/index.ts +5 -0
  166. package/src/arrow-geometry/triangulate-wkb-geometry-column.ts +122 -0
  167. package/src/geoarrow/index.ts +2 -2
  168. package/src/geoarrow/lib/kernels/decode-wkt-native.ts +1 -1
  169. package/src/index.ts +2 -94
  170. package/src/lib/api/encode-table.ts +31 -6
  171. package/src/lib/api/encode.ts +61 -11
  172. package/src/loader-utils/index.ts +3 -0
  173. package/src/loader-utils/json-loader-metadata.ts +35 -0
  174. package/src/loader-utils/json-loader.ts +3 -18
  175. package/src/loader-utils/lib/request-utils/authentication.ts +17 -0
  176. package/src/loader-utils/lib/sources/raster-source.ts +22 -1
  177. package/src/loader-utils/lib/sources/raster-tile.ts +46 -0
  178. package/src/loader-utils/tile-grid.ts +16 -1
  179. package/src/loader-utils/writer-types.ts +2 -0
  180. package/src/null-loader-metadata.ts +32 -0
  181. package/src/null-loader.ts +2 -17
  182. package/src/scan/arrow-query.ts +1 -1
  183. package/src/scan/index.ts +24 -13
  184. package/src/scan/query-arrow-table-in-batches.ts +7 -24
  185. package/src/scan/query-executor.ts +286 -0
  186. package/src/scan/query.ts +112 -299
  187. package/src/schema-utils/index.ts +14 -0
  188. package/src/schema-utils/lib/arrow/arrow-converter.ts +74 -0
  189. package/src/schema-utils/lib/arrow/convert-arrow-variable-width.ts +121 -0
  190. package/src/schema-utils/lib/arrow/convert-arrow.ts +52 -0
  191. package/src/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.ts +83 -0
  192. package/dist/cluster-source.cjs +0 -6360
  193. package/dist/cluster-source.cjs.map +0 -6
  194. package/dist/cluster-source.d.ts +0 -2
  195. package/dist/cluster-source.d.ts.map +0 -1
  196. package/dist/cluster-source.js +0 -2
  197. package/dist/cluster-source.js.map +0 -1
  198. package/dist/federated-table-scan-source.cjs +0 -1905
  199. package/dist/federated-table-scan-source.cjs.map +0 -6
  200. package/dist/federated-table-scan-source.d.ts +0 -2
  201. package/dist/federated-table-scan-source.d.ts.map +0 -1
  202. package/dist/federated-table-scan-source.js +0 -2
  203. package/dist/federated-table-scan-source.js.map +0 -1
  204. package/dist/geoarrow/geoarrow-builder.cjs +0 -31
  205. package/dist/geoarrow/geoarrow-builder.cjs.map +0 -7
  206. package/dist/geoarrow/geoarrow-builder.d.ts +0 -3
  207. package/dist/geoarrow/geoarrow-builder.d.ts.map +0 -1
  208. package/dist/geoarrow/geoarrow-builder.js +0 -5
  209. package/dist/geoarrow/geoarrow-builder.js.map +0 -1
  210. package/dist/vector-table-scan-source.cjs +0 -1200
  211. package/dist/vector-table-scan-source.cjs.map +0 -6
  212. package/dist/vector-table-scan-source.d.ts +0 -2
  213. package/dist/vector-table-scan-source.d.ts.map +0 -1
  214. package/dist/vector-table-scan-source.js +0 -2
  215. package/dist/vector-table-scan-source.js.map +0 -1
  216. package/src/cluster-source.ts +0 -1
  217. package/src/federated-table-scan-source.ts +0 -1
  218. package/src/geoarrow/geoarrow-builder.ts +0 -21
  219. package/src/vector-table-scan-source.ts +0 -1
@@ -1,1200 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res, err) => function __init() {
9
- if (err) throw err[0];
10
- try {
11
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
- } catch (e) {
13
- throw err = [e], e;
14
- }
15
- };
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
-
38
- // src/loader-utils/lib/scan-utils/columnar-predicate.ts
39
- var import_columnar_predicate, import_columnar_predicate2;
40
- var init_columnar_predicate = __esm({
41
- "src/loader-utils/lib/scan-utils/columnar-predicate.ts"() {
42
- "use strict";
43
- import_columnar_predicate = require("@math.gl/sql/columnar-predicate");
44
- import_columnar_predicate2 = require("@math.gl/sql/columnar-predicate");
45
- }
46
- });
47
-
48
- // src/loader-utils/lib/scan-utils/scan-query-metadata.ts
49
- function createScanQueryMetadata(options) {
50
- validateScanExecutionSupport(options.queryType, options.execution);
51
- const schema = Object.freeze({
52
- fields: Object.freeze(
53
- options.schema.fields.map(
54
- (field) => Object.freeze({ ...field, metadata: Object.freeze({ ...field.metadata }) })
55
- )
56
- ),
57
- metadata: Object.freeze({ ...options.schema.metadata })
58
- });
59
- const columns = schema.fields.map(
60
- (field) => {
61
- var _a;
62
- return Object.freeze({
63
- name: field.name,
64
- type: field.type,
65
- nullable: field.nullable !== false,
66
- role: ((_a = options.columnRoles) == null ? void 0 : _a[field.name]) || "attribute",
67
- title: getNonEmptyMetadataValue(field.metadata, "title"),
68
- description: getNonEmptyMetadataValue(field.metadata, "description"),
69
- metadata: field.metadata || Object.freeze({})
70
- });
71
- }
72
- );
73
- const queryCapabilities = Object.freeze({ ...options.capabilities });
74
- return Object.freeze({
75
- sourceType: options.sourceType,
76
- queryType: options.queryType,
77
- execution: Object.freeze({ ...options.execution }),
78
- name: options.name,
79
- description: options.description,
80
- schema,
81
- columns: Object.freeze(columns),
82
- capabilities: queryCapabilities,
83
- queryCapabilities,
84
- ...options.hasDefaultRowWindow ? { hasDefaultRowWindow: true } : {},
85
- spatial: options.spatial ? Object.freeze({
86
- ...options.spatial,
87
- bounds: options.spatial.bounds ? Object.freeze({
88
- minimum: Object.freeze([...options.spatial.bounds.minimum]),
89
- maximum: Object.freeze([...options.spatial.bounds.maximum])
90
- }) : void 0,
91
- coordinateReferenceSystems: options.spatial.coordinateReferenceSystems ? Object.freeze([...options.spatial.coordinateReferenceSystems]) : void 0,
92
- spatialReference: options.spatial.spatialReference ? (0, import_crs.createSpatialReference)(options.spatial.spatialReference) : void 0
93
- }) : void 0,
94
- statistics: options.statistics ? Object.freeze({ ...options.statistics }) : void 0,
95
- levels: options.levels ? Object.freeze(
96
- options.levels.map(
97
- (level) => Object.freeze({
98
- ...level,
99
- scale: level.scale ? Object.freeze([...level.scale]) : void 0
100
- })
101
- )
102
- ) : void 0
103
- });
104
- }
105
- function validateScanExecutionSupport(queryType, execution) {
106
- if (execution.status === "metadata-only") {
107
- if (!execution.reason.trim()) {
108
- throw new Error("Metadata-only scan support requires a concrete reason");
109
- }
110
- return;
111
- }
112
- const validMethods = {
113
- table: ["read", "query"],
114
- raster: ["getRaster"],
115
- "point-cloud": ["scan"]
116
- };
117
- if (!validMethods[queryType].includes(execution.method)) {
118
- throw new Error(
119
- `Scan execution method "${execution.method}" is not valid for ${queryType} queries`
120
- );
121
- }
122
- }
123
- function getNonEmptyMetadataValue(metadata, key) {
124
- const value = metadata == null ? void 0 : metadata[key];
125
- return value || void 0;
126
- }
127
- var import_crs;
128
- var init_scan_query_metadata = __esm({
129
- "src/loader-utils/lib/scan-utils/scan-query-metadata.ts"() {
130
- "use strict";
131
- import_crs = require("@math.gl/geospatial/crs");
132
- }
133
- });
134
-
135
- // src/loader-utils/lib/scan-utils/table-query.ts
136
- function planTableQuery(sourceColumnNames, options = {}) {
137
- validateTableQueryOptions(sourceColumnNames, options);
138
- const outputColumnNames = options.columns ? [...options.columns] : [...sourceColumnNames];
139
- const predicateColumnNames = options.predicate ? (0, import_columnar_predicate2.getColumnarPredicateColumns)(options.predicate) : [];
140
- const requiredColumnNames = /* @__PURE__ */ new Set([...outputColumnNames, ...predicateColumnNames]);
141
- const scanColumnNames = sourceColumnNames.filter(
142
- (columnName) => requiredColumnNames.has(columnName)
143
- );
144
- const steps = [
145
- Object.freeze({ kind: "scan", columns: Object.freeze(scanColumnNames) })
146
- ];
147
- if (options.predicate) {
148
- steps.push(Object.freeze({ kind: "filter", predicate: options.predicate }));
149
- }
150
- steps.push(Object.freeze({ kind: "project", columns: Object.freeze(outputColumnNames) }));
151
- if (options.limit !== void 0) {
152
- steps.push(Object.freeze({ kind: "limit", limit: options.limit }));
153
- }
154
- return Object.freeze(steps);
155
- }
156
- function validateTableQueryOptions(sourceColumnNames, options) {
157
- const availableColumnNames = new Set(sourceColumnNames);
158
- const outputColumnNames = options.columns ?? sourceColumnNames;
159
- const seenColumnNames = /* @__PURE__ */ new Set();
160
- for (const columnName of outputColumnNames) {
161
- if (!availableColumnNames.has(columnName)) {
162
- throw new Error(`Table query column not found: ${columnName}`);
163
- }
164
- if (seenColumnNames.has(columnName)) {
165
- throw new Error(`Table query column was selected more than once: ${columnName}`);
166
- }
167
- seenColumnNames.add(columnName);
168
- }
169
- validateTableQueryLimit(options.limit);
170
- if (options.predicate) {
171
- (0, import_columnar_predicate2.validateColumnarPredicate)(options.predicate, availableColumnNames);
172
- }
173
- }
174
- function validateTableQueryLimit(limit) {
175
- if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 0)) {
176
- throw new Error("Table query limit must be a non-negative safe integer.");
177
- }
178
- }
179
- var init_table_query = __esm({
180
- "src/loader-utils/lib/scan-utils/table-query.ts"() {
181
- "use strict";
182
- init_columnar_predicate();
183
- }
184
- });
185
-
186
- // src/loader-utils/lib/scan-utils/relational-query.ts
187
- function planRelationalQuery(sourceColumnNames, options = {}) {
188
- var _a, _b, _c, _d, _e, _f;
189
- const available = new Set(sourceColumnNames);
190
- const expressionNames = /* @__PURE__ */ new Set();
191
- for (const expression of options.expressions || []) {
192
- if (!expression.name) throw new Error("Relational expression names must be non-empty.");
193
- if (available.has(expression.name) || expressionNames.has(expression.name)) {
194
- throw new Error(`Relational expression duplicates column: ${expression.name}`);
195
- }
196
- expressionNames.add(expression.name);
197
- }
198
- const aggregateNames = new Set((options.aggregates || []).map((aggregate) => aggregate.name));
199
- const requiredColumns = /* @__PURE__ */ new Set();
200
- const availableColumns = new Set(sourceColumnNames);
201
- for (const expression of options.expressions || []) {
202
- const definition = expression.expression;
203
- if (definition.op === "column") {
204
- validateRelationalColumnReference(definition.column, availableColumns);
205
- if (available.has(definition.column)) requiredColumns.add(definition.column);
206
- }
207
- if ("left" in definition) {
208
- validateRelationalColumnReference(definition.left, availableColumns);
209
- validateRelationalColumnReference(definition.right, availableColumns);
210
- if (available.has(definition.left)) requiredColumns.add(definition.left);
211
- if (available.has(definition.right)) requiredColumns.add(definition.right);
212
- }
213
- availableColumns.add(expression.name);
214
- }
215
- for (const key of options.orderBy || []) requiredColumns.add(key.column);
216
- for (const key of options.groupBy || []) requiredColumns.add(key);
217
- for (const aggregate of options.aggregates || []) {
218
- if (aggregate.column) requiredColumns.add(aggregate.column);
219
- }
220
- const outputColumns = (_a = options.columns) == null ? void 0 : _a.filter(
221
- (column) => !expressionNames.has(column) && !aggregateNames.has(column)
222
- );
223
- const tablePlan = [
224
- ...planTableQuery(sourceColumnNames, {
225
- ...options,
226
- columns: outputColumns,
227
- predicate: options.predicate
228
- })
229
- ];
230
- const scanStep = tablePlan[0];
231
- if ((scanStep == null ? void 0 : scanStep.kind) === "scan") {
232
- const scanColumns = new Set(scanStep.columns);
233
- for (const column of requiredColumns) {
234
- if (available.has(column)) scanColumns.add(column);
235
- }
236
- tablePlan[0] = Object.freeze({ kind: "scan", columns: Object.freeze([...scanColumns]) });
237
- }
238
- for (const expression of expressionNames) available.add(expression);
239
- for (const aggregate of aggregateNames) available.add(aggregate);
240
- for (const key of options.orderBy || []) {
241
- if (!available.has(key.column))
242
- throw new Error(`Relational order column not found: ${key.column}`);
243
- }
244
- for (const key of options.groupBy || []) {
245
- if (!available.has(key)) throw new Error(`Relational group column not found: ${key}`);
246
- }
247
- for (const aggregate of options.aggregates || []) {
248
- if (!aggregate.name) throw new Error("Relational aggregate names must be non-empty.");
249
- if (aggregate.function !== "count" && !aggregate.column) {
250
- throw new Error(`Relational aggregate ${aggregate.function} requires a column.`);
251
- }
252
- if (aggregate.column && !available.has(aggregate.column)) {
253
- throw new Error(`Relational aggregate column not found: ${aggregate.column}`);
254
- }
255
- }
256
- const relationalSteps = [];
257
- if ((_b = options.expressions) == null ? void 0 : _b.length)
258
- relationalSteps.push({ kind: "expression", detail: options.expressions });
259
- if ((_c = options.orderBy) == null ? void 0 : _c.length) relationalSteps.push({ kind: "order", detail: options.orderBy });
260
- if (((_d = options.aggregates) == null ? void 0 : _d.length) || ((_e = options.groupBy) == null ? void 0 : _e.length)) {
261
- relationalSteps.push({
262
- kind: "aggregate",
263
- detail: { groupBy: options.groupBy, aggregates: options.aggregates }
264
- });
265
- }
266
- if ((_f = options.union) == null ? void 0 : _f.length) relationalSteps.push({ kind: "union", detail: options.union });
267
- if (options.join) relationalSteps.push({ kind: "join", detail: options.join });
268
- return { tablePlan, relationalSteps: Object.freeze(relationalSteps) };
269
- }
270
- function validateRelationalColumnReference(columnName, availableColumns) {
271
- if (!availableColumns.has(columnName)) {
272
- throw new Error(`Relational expression column not found: ${columnName}`);
273
- }
274
- }
275
- var init_relational_query = __esm({
276
- "src/loader-utils/lib/scan-utils/relational-query.ts"() {
277
- "use strict";
278
- init_table_query();
279
- }
280
- });
281
-
282
- // src/loader-utils/lib/scan-utils/table-query-explain.ts
283
- function explainTableQuery(sourceColumnNames, options, capabilities) {
284
- const plan = planTableQuery(sourceColumnNames, options);
285
- const outputColumns = options.columns ? [...options.columns] : [...sourceColumnNames];
286
- const predicateColumns = options.predicate ? (0, import_columnar_predicate2.getColumnarPredicateColumns)(options.predicate) : [];
287
- const requiredColumns = [...plan[0].kind === "scan" ? plan[0].columns : []];
288
- return Object.freeze({
289
- sourceColumns: Object.freeze([...sourceColumnNames]),
290
- outputColumns: Object.freeze(outputColumns),
291
- requiredColumns: Object.freeze(requiredColumns),
292
- predicateColumns: Object.freeze(predicateColumns),
293
- plan,
294
- capabilities: Object.freeze({ ...capabilities }),
295
- operators: Object.freeze({
296
- projection: createOperatorExplanation(options.columns !== void 0, capabilities.projection),
297
- predicate: createOperatorExplanation(options.predicate !== void 0, capabilities.predicate),
298
- limit: createOperatorExplanation(options.limit !== void 0, capabilities.limit)
299
- })
300
- });
301
- }
302
- function createOperatorExplanation(enabled, support) {
303
- return Object.freeze({ enabled, support });
304
- }
305
- var init_table_query_explain = __esm({
306
- "src/loader-utils/lib/scan-utils/table-query-explain.ts"() {
307
- "use strict";
308
- init_columnar_predicate();
309
- init_table_query();
310
- }
311
- });
312
-
313
- // src/loader-utils/index.ts
314
- var init_loader_utils = __esm({
315
- "src/loader-utils/index.ts"() {
316
- "use strict";
317
- init_columnar_predicate();
318
- init_relational_query();
319
- init_scan_query_metadata();
320
- init_table_query();
321
- init_table_query_explain();
322
- }
323
- });
324
-
325
- // dist/scan/table-query-capabilities.js
326
- var ARROW_TABLE_QUERY_CAPABILITIES, SQL_DATA_SOURCE_TABLE_QUERY_CAPABILITIES;
327
- var init_table_query_capabilities = __esm({
328
- "dist/scan/table-query-capabilities.js"() {
329
- "use strict";
330
- ARROW_TABLE_QUERY_CAPABILITIES = Object.freeze({
331
- projection: "residual",
332
- predicate: "residual",
333
- limit: "residual",
334
- streaming: false,
335
- cancellation: true,
336
- expressions: "residual",
337
- orderBy: "residual",
338
- aggregates: "residual"
339
- });
340
- SQL_DATA_SOURCE_TABLE_QUERY_CAPABILITIES = Object.freeze({
341
- projection: "pushdown",
342
- predicate: "pushdown",
343
- limit: "pushdown",
344
- streaming: false,
345
- cancellation: false,
346
- expressions: "pushdown",
347
- orderBy: "pushdown",
348
- aggregates: "pushdown"
349
- });
350
- }
351
- });
352
-
353
- // dist/scan/arrow-execution/filter-arrow-table.js
354
- function filterArrowTable(source, predicate, options = {}) {
355
- (0, import_columnar_predicate2.validateColumnarPredicate)(predicate, new Set(source.schema.fields.map((field) => field.name)));
356
- const boundPredicate = normalizeArrowDatePredicate(predicate);
357
- return filterArrowRows(source, (batch) => {
358
- const evaluate = (0, import_columnar_predicate6.compileColumnarPredicate)(boundPredicate, (path) => bindPredicateColumn(batch, path));
359
- return (rowIndex) => evaluate(rowIndex) === true;
360
- }, options);
361
- }
362
- function bindPredicateColumn(batch, [name, ...properties]) {
363
- const column = batch.getChild(name);
364
- if (!column)
365
- throw new Error(`Arrow query column not found: ${name}`);
366
- return (rowIndex) => {
367
- let value = column.get(rowIndex);
368
- for (const property of properties) {
369
- if (value == null)
370
- return null;
371
- value = value[property];
372
- }
373
- return dateToMilliseconds(value);
374
- };
375
- }
376
- function normalizeArrowDatePredicate(predicate) {
377
- switch (predicate.op) {
378
- case "and":
379
- case "or":
380
- return { ...predicate, args: predicate.args.map(normalizeArrowDatePredicate) };
381
- case "not":
382
- return { ...predicate, args: [normalizeArrowDatePredicate(predicate.args[0])] };
383
- case "isNull":
384
- return predicate;
385
- case "in":
386
- return { ...predicate, args: [predicate.args[0], predicate.args[1].map(dateToMilliseconds)] };
387
- default:
388
- return { ...predicate, args: [predicate.args[0], dateToMilliseconds(predicate.args[1])] };
389
- }
390
- }
391
- function dateToMilliseconds(value) {
392
- return value instanceof Date ? value.getTime() : value;
393
- }
394
- function filterArrowRows(source, selectBatch, options = {}) {
395
- var _a, _b, _c;
396
- let remaining = options.limit ?? Infinity;
397
- if (remaining !== Infinity && (!Number.isSafeInteger(remaining) || remaining < 0)) {
398
- throw new Error("Arrow filter limit must be a non-negative safe integer.");
399
- }
400
- (_a = options.signal) == null ? void 0 : _a.throwIfAborted();
401
- const batches = [];
402
- for (const batch of source.batches) {
403
- if (remaining === 0)
404
- break;
405
- (_b = options.signal) == null ? void 0 : _b.throwIfAborted();
406
- const selectRow = selectBatch(batch);
407
- const indices = [];
408
- for (let rowIndex = 0; rowIndex < batch.numRows && indices.length < remaining; rowIndex++) {
409
- (_c = options.signal) == null ? void 0 : _c.throwIfAborted();
410
- if (selectRow(rowIndex))
411
- indices.push(rowIndex);
412
- }
413
- remaining -= indices.length;
414
- const selected = (0, import_arrow2.selectArrowBatchRows)(batch, indices);
415
- if (selected)
416
- batches.push(selected);
417
- }
418
- return new arrow3.Table(source.schema, batches);
419
- }
420
- var arrow3, import_arrow2, import_columnar_predicate6;
421
- var init_filter_arrow_table = __esm({
422
- "dist/scan/arrow-execution/filter-arrow-table.js"() {
423
- "use strict";
424
- arrow3 = __toESM(require("apache-arrow"), 1);
425
- import_arrow2 = require("@math.gl/core/arrow");
426
- import_columnar_predicate6 = require("@math.gl/sql/columnar-predicate");
427
- init_loader_utils();
428
- }
429
- });
430
-
431
- // dist/scan/arrow-execution.js
432
- var import_arrow3;
433
- var init_arrow_execution = __esm({
434
- "dist/scan/arrow-execution.js"() {
435
- "use strict";
436
- import_arrow3 = require("@math.gl/core/arrow");
437
- init_filter_arrow_table();
438
- }
439
- });
440
-
441
- // dist/scan/sql-predicate-schema.js
442
- function validateSQLPredicate(value) {
443
- (0, import_parser.validateSQLPredicate)(value);
444
- rejectPredicateCasts(value, "$");
445
- }
446
- function rejectPredicateCasts(predicate, path) {
447
- if (predicate.op === "and" || predicate.op === "or" || predicate.op === "not") {
448
- predicate.args.forEach((child, index) => rejectPredicateCasts(child, path + ".args[" + index + "]"));
449
- } else if (Object.hasOwn(predicate.args[0], "casts")) {
450
- throw new Error("SQL predicate " + path + ".args[0] requires a non-empty property reference");
451
- }
452
- }
453
- var import_parser;
454
- var init_sql_predicate_schema = __esm({
455
- "dist/scan/sql-predicate-schema.js"() {
456
- "use strict";
457
- import_parser = require("@math.gl/sql/parser");
458
- }
459
- });
460
-
461
- // dist/scan/table-query.js
462
- function planTableQuery2(sourceColumnNames, options = {}) {
463
- if (options.predicate) {
464
- validateSQLPredicate(options.predicate);
465
- }
466
- return planTableQuery(sourceColumnNames, options);
467
- }
468
- var init_table_query2 = __esm({
469
- "dist/scan/table-query.js"() {
470
- "use strict";
471
- init_loader_utils();
472
- init_sql_predicate_schema();
473
- }
474
- });
475
-
476
- // dist/scan/plan-arrow-table-query.js
477
- function explainArrowTableQuery(sourceTable, options = {}) {
478
- if (options.select !== void 0) {
479
- if (options.columns !== void 0 || hasRelationalOperators(options) || options.join) {
480
- throw new Error("Arrow select cannot be combined with columns or relational operators.");
481
- }
482
- const projected = (0, import_arrow3.projectArrowTable)(sourceTable, options.select);
483
- const columns = [
484
- ...new Set(options.select.map((selection) => typeof selection === "string" ? selection : selection.column))
485
- ];
486
- const { select, ...remainingOptions } = options;
487
- const explanation = explainArrowTableQuery(sourceTable, { ...remainingOptions, columns });
488
- const outputColumns = Object.freeze(projected.schema.fields.map((field) => field.name));
489
- return Object.freeze({
490
- ...explanation,
491
- outputColumns,
492
- plan: Object.freeze(explanation.plan.map((step) => step.kind === "project" ? Object.freeze({ ...step, columns: outputColumns, select }) : step))
493
- });
494
- }
495
- if (options.predicate) {
496
- validateSQLPredicate(options.predicate);
497
- }
498
- return explainTableQuery(sourceTable.schema.fields.map((field) => field.name), options, ARROW_TABLE_QUERY_CAPABILITIES);
499
- }
500
- function queryArrowTable(sourceTable, options = {}, execute) {
501
- throwIfAborted(options.signal);
502
- if (options.select !== void 0) {
503
- if (options.columns !== void 0 || hasRelationalOperators(options) || options.join) {
504
- throw new Error("Arrow select cannot be combined with columns or relational operators.");
505
- }
506
- return (execute ?? executePortableArrowQuery)(sourceTable, {
507
- where: options.predicate,
508
- select: options.select,
509
- limit: options.limit,
510
- signal: options.signal
511
- });
512
- }
513
- if (options.join || hasRelationalOperators(options)) {
514
- if (options.join) {
515
- validateArrowJoinQuery(sourceTable, options);
516
- if (hasRelationalOperators(options)) {
517
- throw new Error("Arrow joins cannot yet be combined with other relational operators.");
518
- }
519
- }
520
- if (!execute)
521
- throw new Error("Relational queries require the SQL executor.");
522
- return options.join ? queryArrowJoin(sourceTable, options, execute) : queryArrowTableRelational(sourceTable, options, execute);
523
- }
524
- const plan = planTableQuery2(sourceTable.schema.fields.map((field) => field.name), options);
525
- const projection = plan.find((step) => step.kind === "project");
526
- return (execute ?? executePortableArrowQuery)(sourceTable, {
527
- where: options.predicate,
528
- select: projection == null ? void 0 : projection.columns,
529
- limit: options.limit,
530
- signal: options.signal
531
- });
532
- }
533
- function queryArrowTableRelational(sourceTable, options, execute) {
534
- var _a, _b, _c;
535
- const sourceColumns = sourceTable.schema.fields.map((field) => field.name);
536
- const grouped = ((_a = options.groupBy) == null ? void 0 : _a.length) || ((_b = options.aggregates) == null ? void 0 : _b.length);
537
- const outputColumns = options.columns ?? (grouped ? [...options.groupBy ?? [], ...(options.aggregates ?? []).map((aggregate) => aggregate.name)] : sourceColumns);
538
- const plan = planRelationalQuery(sourceColumns, { ...options, columns: outputColumns });
539
- const scan = plan.tablePlan.find((step) => step.kind === "scan");
540
- let table = execute(sourceTable, {
541
- where: options.predicate,
542
- select: scan.columns,
543
- signal: options.signal
544
- });
545
- if ((_c = options.union) == null ? void 0 : _c.length) {
546
- const childPlan = planRelationalQuery(sourceColumns, {
547
- ...options,
548
- columns: outputColumns,
549
- predicate: void 0
550
- });
551
- const columns = childPlan.tablePlan.find((step) => step.kind === "scan").columns;
552
- const union = options.union.map((child) => {
553
- var _a2;
554
- const input = (_a2 = options.tables) == null ? void 0 : _a2[child.source];
555
- if (!input)
556
- throw new Error("Arrow union source not found: " + child.source);
557
- return queryArrowTable(input, { ...child.query, columns, signal: options.signal }, execute);
558
- });
559
- table = execute((0, import_arrow3.projectArrowTable)(table, columns), { union, signal: options.signal });
560
- }
561
- for (const { name, expression } of options.expressions ?? []) {
562
- const select = [
563
- ...table.schema.fields.map((field) => field.name),
564
- expression.op === "column" ? { column: expression.column, as: name } : { expression: toArrowExpression(expression), as: name }
565
- ];
566
- table = execute(table, { select, signal: options.signal });
567
- }
568
- return execute(table, {
569
- select: outputColumns,
570
- groupBy: options.groupBy,
571
- aggregates: Object.fromEntries((options.aggregates ?? []).map((aggregate) => {
572
- const expression = aggregate.column === void 0 ? void 0 : identifier(aggregate.column);
573
- if (aggregate.function === "count")
574
- return [aggregate.name, { operation: "COUNT", expression }];
575
- const operations = { sum: "SUM", min: "MIN", max: "MAX", avg: "AVG" };
576
- return [
577
- aggregate.name,
578
- { operation: operations[aggregate.function], expression }
579
- ];
580
- })),
581
- orderBy: options.orderBy,
582
- limit: options.limit,
583
- signal: options.signal
584
- });
585
- }
586
- function identifier(name) {
587
- return { type: "Identifier", name };
588
- }
589
- function toArrowExpression(expression) {
590
- if (expression.op === "literal")
591
- return literal(expression.value);
592
- const operators = { add: "+", subtract: "-", multiply: "*", divide: "/" };
593
- const binary = {
594
- type: "BinaryExpression",
595
- operator: operators[expression.op],
596
- left: identifier(expression.left),
597
- right: identifier(expression.right)
598
- };
599
- if (expression.op !== "divide")
600
- return binary;
601
- return {
602
- type: "ConditionalExpression",
603
- test: { ...binary, operator: "===", left: binary.right, right: literal(0) },
604
- consequent: literal(null),
605
- alternate: binary
606
- };
607
- }
608
- function literal(value) {
609
- return { type: "Literal", value };
610
- }
611
- function hasRelationalOperators(options) {
612
- var _a, _b, _c, _d, _e;
613
- return Boolean(((_a = options.expressions) == null ? void 0 : _a.length) || ((_b = options.orderBy) == null ? void 0 : _b.length) || ((_c = options.groupBy) == null ? void 0 : _c.length) || ((_d = options.aggregates) == null ? void 0 : _d.length) || ((_e = options.union) == null ? void 0 : _e.length));
614
- }
615
- function queryArrowJoin(sourceTable, options, executeRelational) {
616
- var _a, _b, _c, _d;
617
- const join = options.join;
618
- const childTable = (_a = options.tables) == null ? void 0 : _a[join.child.source];
619
- if (!childTable)
620
- throw new Error(`Arrow join source not found: ${join.child.source}`);
621
- const left = executeRelational(sourceTable, {
622
- where: options.predicate,
623
- signal: options.signal
624
- });
625
- const right = executeRelational(childTable, {
626
- where: (_b = join.child.query) == null ? void 0 : _b.predicate,
627
- select: (_c = join.child.query) == null ? void 0 : _c.columns,
628
- limit: (_d = join.child.query) == null ? void 0 : _d.limit,
629
- signal: options.signal
630
- });
631
- return executeRelational(left, {
632
- join: {
633
- table: right,
634
- type: join.type,
635
- left: join.left,
636
- right: join.right,
637
- rightPrefix: `${join.child.source}.`
638
- },
639
- select: options.columns,
640
- limit: options.limit,
641
- signal: options.signal
642
- });
643
- }
644
- function validateArrowJoinQuery(sourceTable, options) {
645
- var _a, _b, _c;
646
- const join = options.join;
647
- if (!join)
648
- return;
649
- const sourceColumnNames = sourceTable.schema.fields.map((field) => field.name);
650
- const childTable = (_a = options.tables) == null ? void 0 : _a[join.child.source];
651
- if (!childTable)
652
- throw new Error(`Arrow join source not found: ${join.child.source}`);
653
- const childColumnNames = childTable.schema.fields.map((field) => field.name);
654
- if (!sourceColumnNames.includes(join.left)) {
655
- throw new Error(`Arrow join column not found: ${join.left}`);
656
- }
657
- if (!childColumnNames.includes(join.right)) {
658
- throw new Error(`Arrow join column not found: ${join.right}`);
659
- }
660
- const childPrefix = `${join.child.source}.`;
661
- const rootColumns = (_b = options.columns) == null ? void 0 : _b.filter((column) => !column.startsWith(childPrefix));
662
- planTableQuery2(sourceColumnNames, {
663
- predicate: options.predicate,
664
- columns: (rootColumns == null ? void 0 : rootColumns.length) ? rootColumns : void 0,
665
- limit: options.limit,
666
- signal: options.signal
667
- });
668
- const childQuery = join.child.query || {};
669
- planTableQuery2(childColumnNames, childQuery);
670
- const childOutputColumns = childQuery.columns || childColumnNames;
671
- if (!childOutputColumns.includes(join.right)) {
672
- throw new Error(`Arrow join child projection must include: ${join.right}`);
673
- }
674
- const projectedChildColumns = ((_c = options.columns) == null ? void 0 : _c.filter((column) => column.startsWith(childPrefix))) || [];
675
- const seenChildColumns = /* @__PURE__ */ new Set();
676
- for (const projectedColumn of projectedChildColumns) {
677
- const childColumn = projectedColumn.slice(childPrefix.length);
678
- if (!childColumnNames.includes(childColumn)) {
679
- throw new Error(`Arrow join column not found: ${projectedColumn}`);
680
- }
681
- if (seenChildColumns.has(childColumn)) {
682
- throw new Error(`Arrow query column was selected more than once: ${projectedColumn}`);
683
- }
684
- seenChildColumns.add(childColumn);
685
- if (!childOutputColumns.includes(childColumn)) {
686
- throw new Error(`Arrow join child projection does not include: ${childColumn}`);
687
- }
688
- }
689
- }
690
- function throwIfAborted(signal) {
691
- if (signal == null ? void 0 : signal.aborted) {
692
- const error = new Error("Arrow query was aborted.");
693
- error.name = "AbortError";
694
- throw error;
695
- }
696
- }
697
- var executePortableArrowQuery;
698
- var init_plan_arrow_table_query = __esm({
699
- "dist/scan/plan-arrow-table-query.js"() {
700
- "use strict";
701
- init_arrow_execution();
702
- init_table_query2();
703
- init_loader_utils();
704
- init_table_query_capabilities();
705
- init_sql_predicate_schema();
706
- executePortableArrowQuery = (table, { select, where, limit, signal }) => {
707
- if (where)
708
- table = filterArrowTable(table, where, { limit, signal });
709
- const projected = select ? (0, import_arrow3.projectArrowTable)(table, select) : table;
710
- return projected.numRows === 0 || limit === void 0 ? projected : projected.slice(0, limit);
711
- };
712
- }
713
- });
714
-
715
- // dist/scan/query-arrow-table.js
716
- var query_arrow_table_exports = {};
717
- __export(query_arrow_table_exports, {
718
- ARROW_TABLE_QUERY_CAPABILITIES: () => ARROW_TABLE_QUERY_CAPABILITIES,
719
- explainArrowTableQuery: () => explainArrowTableQuery,
720
- queryArrowTable: () => queryArrowTable2
721
- });
722
- function queryArrowTable2(source, options) {
723
- return queryArrowTable(source, options, import_query.queryArrowTable);
724
- }
725
- var import_query;
726
- var init_query_arrow_table = __esm({
727
- "dist/scan/query-arrow-table.js"() {
728
- "use strict";
729
- import_query = require("@math.gl/sql/query");
730
- init_plan_arrow_table_query();
731
- init_plan_arrow_table_query();
732
- }
733
- });
734
-
735
- // dist/vector-table-scan-source.js
736
- var vector_table_scan_source_exports = {};
737
- __export(vector_table_scan_source_exports, {
738
- AddressedVectorTableScanSource: () => AddressedVectorTableScanSource,
739
- VectorFeatureTableScanSource: () => VectorFeatureTableScanSource,
740
- VectorTileTableScanSource: () => VectorTileTableScanSource
741
- });
742
- module.exports = __toCommonJS(vector_table_scan_source_exports);
743
-
744
- // src/schema-utils/lib/schema/convert-arrow-schema.ts
745
- var arrow = __toESM(require("apache-arrow"), 1);
746
- function convertArrowToSchema(arrowSchema) {
747
- return serializeArrowSchema(arrowSchema);
748
- }
749
- function serializeArrowSchema(arrowSchema) {
750
- return {
751
- fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
752
- metadata: serializeArrowMetadata(arrowSchema.metadata)
753
- };
754
- }
755
- function serializeArrowMetadata(arrowMetadata) {
756
- return Object.fromEntries(arrowMetadata);
757
- }
758
- function serializeArrowField(field) {
759
- return {
760
- name: field.name,
761
- type: serializeArrowType(field.type),
762
- nullable: field.nullable,
763
- metadata: serializeArrowMetadata(field.metadata)
764
- };
765
- }
766
- function serializeArrowType(arrowType) {
767
- if (isArrowViewType(arrowType, "BinaryView")) {
768
- return "binary-view";
769
- }
770
- if (isArrowViewType(arrowType, "Utf8View")) {
771
- return "utf8-view";
772
- }
773
- if (isOptionalArrowType(arrowType, "LargeList")) {
774
- const largeListType = arrowType;
775
- return {
776
- type: "large-list",
777
- children: [serializeArrowField(largeListType.valueField)]
778
- };
779
- }
780
- switch (arrowType.constructor) {
781
- case arrow.Null:
782
- return "null";
783
- case arrow.Binary:
784
- return "binary";
785
- case arrow.FixedSizeBinary:
786
- return {
787
- type: "fixed-size-binary",
788
- byteWidth: arrowType.byteWidth
789
- };
790
- case arrow.Bool:
791
- return "bool";
792
- case arrow.Int:
793
- const intType = arrowType;
794
- return `${intType.isSigned ? "" : "u"}int${intType.bitWidth}`;
795
- case arrow.Int8:
796
- return "int8";
797
- case arrow.Int16:
798
- return "int16";
799
- case arrow.Int32:
800
- return "int32";
801
- case arrow.Int64:
802
- return "int64";
803
- case arrow.Uint8:
804
- return "uint8";
805
- case arrow.Uint16:
806
- return "uint16";
807
- case arrow.Uint32:
808
- return "uint32";
809
- case arrow.Uint64:
810
- return "uint64";
811
- case arrow.Float:
812
- const precision = arrowType.precision;
813
- switch (precision) {
814
- case arrow.Precision.HALF:
815
- return "float16";
816
- case arrow.Precision.SINGLE:
817
- return "float32";
818
- case arrow.Precision.DOUBLE:
819
- return "float64";
820
- default:
821
- return "float16";
822
- }
823
- case arrow.Float16:
824
- return "float16";
825
- case arrow.Float32:
826
- return "float32";
827
- case arrow.Float64:
828
- return "float64";
829
- case arrow.Utf8:
830
- return "utf8";
831
- case arrow.Decimal:
832
- const decimal = arrowType;
833
- return {
834
- type: "decimal",
835
- bitWidth: decimal.bitWidth,
836
- precision: decimal.precision,
837
- scale: decimal.scale
838
- };
839
- case arrow.Date_:
840
- const dateUnit = arrowType.unit;
841
- return dateUnit === arrow.DateUnit.DAY ? "date-day" : "date-millisecond";
842
- case arrow.DateDay:
843
- return "date-day";
844
- case arrow.DateMillisecond:
845
- return "date-millisecond";
846
- case arrow.Time:
847
- const timeUnit = arrowType.unit;
848
- switch (timeUnit) {
849
- case arrow.TimeUnit.SECOND:
850
- return "time-second";
851
- case arrow.TimeUnit.MILLISECOND:
852
- return "time-millisecond";
853
- case arrow.TimeUnit.MICROSECOND:
854
- return "time-microsecond";
855
- case arrow.TimeUnit.NANOSECOND:
856
- return "time-nanosecond";
857
- default:
858
- return "time-second";
859
- }
860
- case arrow.TimeMillisecond:
861
- return "time-millisecond";
862
- case arrow.TimeSecond:
863
- return "time-second";
864
- case arrow.TimeMicrosecond:
865
- return "time-microsecond";
866
- case arrow.TimeNanosecond:
867
- return "time-nanosecond";
868
- case arrow.Timestamp:
869
- const timeStampUnit = arrowType.unit;
870
- switch (timeStampUnit) {
871
- case arrow.TimeUnit.SECOND:
872
- return "timestamp-second";
873
- case arrow.TimeUnit.MILLISECOND:
874
- return "timestamp-millisecond";
875
- case arrow.TimeUnit.MICROSECOND:
876
- return "timestamp-microsecond";
877
- case arrow.TimeUnit.NANOSECOND:
878
- return "timestamp-nanosecond";
879
- default:
880
- return "timestamp-second";
881
- }
882
- case arrow.TimestampSecond:
883
- return "timestamp-second";
884
- case arrow.TimestampMillisecond:
885
- return "timestamp-millisecond";
886
- case arrow.TimestampMicrosecond:
887
- return "timestamp-microsecond";
888
- case arrow.TimestampNanosecond:
889
- return "timestamp-nanosecond";
890
- case arrow.Interval:
891
- const intervalUnit = arrowType.unit;
892
- switch (intervalUnit) {
893
- case arrow.IntervalUnit.DAY_TIME:
894
- return "interval-daytime";
895
- case arrow.IntervalUnit.YEAR_MONTH:
896
- return "interval-yearmonth";
897
- default:
898
- return "interval-daytime";
899
- }
900
- case arrow.IntervalDayTime:
901
- return "interval-daytime";
902
- case arrow.IntervalYearMonth:
903
- return "interval-yearmonth";
904
- case arrow.Map_:
905
- const mapType = arrowType;
906
- return {
907
- type: "map",
908
- keysSorted: mapType.keysSorted,
909
- children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
910
- };
911
- case arrow.List:
912
- const listType = arrowType;
913
- const listField = listType.valueField;
914
- return {
915
- type: "list",
916
- children: [serializeArrowField(listField)]
917
- };
918
- case arrow.FixedSizeList:
919
- const fixedSizeList = arrowType;
920
- return {
921
- type: "fixed-size-list",
922
- listSize: fixedSizeList.listSize,
923
- children: [serializeArrowField(fixedSizeList.children[0])]
924
- };
925
- case arrow.Struct:
926
- const structType = arrowType;
927
- return {
928
- type: "struct",
929
- children: structType.children.map((arrowField) => serializeArrowField(arrowField))
930
- };
931
- case arrow.SparseUnion:
932
- case arrow.DenseUnion:
933
- const unionType = arrowType;
934
- return {
935
- type: unionType instanceof arrow.DenseUnion ? "dense-union" : "sparse-union",
936
- typeIds: unionType.typeIds,
937
- children: unionType.children.map((arrowField) => serializeArrowField(arrowField)),
938
- typeIdToChildIndex: { ...unionType.typeIdToChildIndex }
939
- };
940
- case arrow.Dictionary:
941
- const dictionaryType = arrowType;
942
- return {
943
- type: "dictionary",
944
- id: dictionaryType.id,
945
- indices: serializeArrowDictionaryKeyType(dictionaryType.indices),
946
- dictionary: serializeArrowType(dictionaryType.dictionary),
947
- isOrdered: dictionaryType.isOrdered
948
- };
949
- default:
950
- throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
951
- }
952
- }
953
- function getOptionalArrowConstructor(typeName) {
954
- return arrow[typeName];
955
- }
956
- function isArrowViewType(arrowType, viewTypeName) {
957
- const constructor = getOptionalArrowConstructor(viewTypeName);
958
- if (constructor && arrowType instanceof constructor) {
959
- return true;
960
- }
961
- const guards = arrow.DataType;
962
- const guard = viewTypeName === "BinaryView" ? guards.isBinaryView : guards.isUtf8View;
963
- return Boolean(guard == null ? void 0 : guard(arrowType));
964
- }
965
- function isOptionalArrowType(arrowType, typeName) {
966
- const constructor = getOptionalArrowConstructor(typeName);
967
- return Boolean(constructor && arrowType instanceof constructor);
968
- }
969
- function serializeArrowDictionaryKeyType(arrowType) {
970
- if (arrowType instanceof arrow.Int) {
971
- const prefix = arrowType.isSigned ? "int" : "uint";
972
- const keyType = `${prefix}${arrowType.bitWidth}`;
973
- if (isSchemaDictionaryKeyType(keyType)) {
974
- return keyType;
975
- }
976
- }
977
- switch (arrowType.constructor) {
978
- case arrow.Int8:
979
- return "int8";
980
- case arrow.Int16:
981
- return "int16";
982
- case arrow.Int32:
983
- return "int32";
984
- case arrow.Uint8:
985
- return "uint8";
986
- case arrow.Uint16:
987
- return "uint16";
988
- case arrow.Uint32:
989
- return "uint32";
990
- default:
991
- throw new Error(`arrow dictionary index type not supported: ${arrowType.constructor.name}`);
992
- }
993
- }
994
- function isSchemaDictionaryKeyType(keyType) {
995
- return ["int8", "int16", "int32", "uint8", "uint16", "uint32"].includes(keyType);
996
- }
997
-
998
- // src/schema-utils/lib/arrow/arrow-metadata.ts
999
- var arrow2 = __toESM(require("apache-arrow"), 1);
1000
- var import_arrow = require("@math.gl/core/arrow");
1001
- function makeArrowMetadataBatch(schema) {
1002
- return new arrow2.RecordBatch((0, import_arrow.snapshotArrowSchema)(schema), void 0);
1003
- }
1004
-
1005
- // dist/lib/loader-utils/native-arrow.js
1006
- function isArrowTable(value) {
1007
- return Boolean(value && typeof value === "object" && "schema" in value && "batches" in value && Array.isArray(value.batches) && "numRows" in value && typeof value.numRows === "number" && "getChildAt" in value && typeof value.getChildAt === "function");
1008
- }
1009
-
1010
- // dist/scan/vector-table-scan-source.js
1011
- init_loader_utils();
1012
- init_table_query_capabilities();
1013
- init_plan_arrow_table_query();
1014
- var AddressedVectorTableScanSource = class {
1015
- /** Stable adapter type reported by `getQueryMetadata()`. */
1016
- sourceType;
1017
- /** Optional display name shown by query controls. */
1018
- name;
1019
- /** Human-readable description of the bound physical selection. */
1020
- description;
1021
- /** Spatial extent of the bound physical selection. */
1022
- spatial;
1023
- tablePromise = null;
1024
- /** Creates a table-scan view over one immutable physical selection. */
1025
- constructor(options, defaults) {
1026
- this.sourceType = options.sourceType || defaults.sourceType;
1027
- this.name = options.name;
1028
- this.description = options.description || defaults.description;
1029
- this.spatial = defaults.spatial;
1030
- }
1031
- /** Discovers the addressed result schema and portable residual-query capabilities. */
1032
- async getQueryMetadata(options = {}) {
1033
- const table = await this.getTable(options.signal);
1034
- const schema = convertArrowToSchema(table.schema);
1035
- return createScanQueryMetadata({
1036
- sourceType: this.sourceType,
1037
- queryType: "table",
1038
- execution: { status: "supported", method: "read" },
1039
- name: this.name,
1040
- description: this.description,
1041
- schema,
1042
- capabilities: {
1043
- table: ARROW_TABLE_QUERY_CAPABILITIES,
1044
- bounds: "unsupported",
1045
- levelOfDetail: "unsupported"
1046
- },
1047
- columnRoles: inferVectorColumnRoles(schema.fields.map((field) => field.name)),
1048
- spatial: this.spatial,
1049
- statistics: { rowCount: table.numRows }
1050
- });
1051
- }
1052
- /** Applies the portable Arrow query to the addressed feature table. */
1053
- async query(options = {}) {
1054
- const table = await this.getTable(options.signal);
1055
- const { queryArrowTable: queryArrowTable3 } = await Promise.resolve().then(() => (init_query_arrow_table(), query_arrow_table_exports));
1056
- return queryArrowTable3(table, options);
1057
- }
1058
- /** Explains the residual Arrow plan after resolving the addressed feature table. */
1059
- async explain(options = {}) {
1060
- const table = await this.getTable(options.signal);
1061
- return explainArrowTableQuery(table, options);
1062
- }
1063
- /** Emits the portable query result as one bounded Arrow batch. */
1064
- async *read(options = {}) {
1065
- const data = await this.query(options);
1066
- if (data.batches.length)
1067
- yield* data.batches;
1068
- else
1069
- yield makeArrowMetadataBatch(data.schema);
1070
- }
1071
- /** Scans the addressed query result through the same batch contract as `read()`. */
1072
- scan(options = {}) {
1073
- return this.read(options);
1074
- }
1075
- /** Resolves and caches the addressed table while allowing failed loads to be retried. */
1076
- async getTable(signal) {
1077
- throwIfAborted2(signal);
1078
- if (!this.tablePromise) {
1079
- this.tablePromise = this.loadTable().then((table) => {
1080
- if (!table) {
1081
- throw new Error("The addressed vector selection did not return a feature table.");
1082
- }
1083
- return table;
1084
- }).catch((error) => {
1085
- this.tablePromise = null;
1086
- throw error;
1087
- });
1088
- }
1089
- return await waitForPromise(this.tablePromise, signal);
1090
- }
1091
- };
1092
- var VectorTileTableScanSource = class extends AddressedVectorTableScanSource {
1093
- /** Specialized tile source that owns tile addressing and decoding. */
1094
- source;
1095
- /** Immutable tile address bound to this table view. */
1096
- tile;
1097
- /** Creates a portable table view over one vector tile. */
1098
- constructor(source, options) {
1099
- const tile = Object.freeze({
1100
- ...options.tile,
1101
- layers: cloneAndFreezeLayers(options.tile.layers)
1102
- });
1103
- super(options, {
1104
- sourceType: "vector-tile-table",
1105
- description: `Vector tile ${tile.z}/${tile.x}/${tile.y}`,
1106
- spatial: {
1107
- bounds: getWGS84TileBounds(tile),
1108
- coordinateReferenceSystems: ["EPSG:4326"]
1109
- }
1110
- });
1111
- this.source = source;
1112
- this.tile = tile;
1113
- }
1114
- /** Loads the bound vector tile using the source's requested Arrow output shape. */
1115
- async loadTable(signal) {
1116
- const tile = await this.source.getVectorTile({ ...this.tile, signal });
1117
- if (tile === null || isArrowTable(tile))
1118
- return tile;
1119
- throw new Error('The addressed vector selection must return an Arrow table. Configure the source with shape "arrow".');
1120
- }
1121
- };
1122
- var VectorFeatureTableScanSource = class extends AddressedVectorTableScanSource {
1123
- /** Specialized vector source that owns service request construction and parsing. */
1124
- source;
1125
- /** Immutable bounded feature request bound to this table view. */
1126
- request;
1127
- /** Creates a portable table view over one bounded vector-service request. */
1128
- constructor(source, options) {
1129
- const request = Object.freeze({
1130
- ...options.request,
1131
- layers: cloneAndFreezeLayers(options.request.layers),
1132
- boundingBox: Object.freeze([
1133
- Object.freeze([...options.request.boundingBox[0]]),
1134
- Object.freeze([...options.request.boundingBox[1]])
1135
- ])
1136
- });
1137
- const boundsCrs = request.requestCrs || request.crs;
1138
- const coordinateReferenceSystems = typeof boundsCrs === "string" ? [boundsCrs] : void 0;
1139
- super(options, {
1140
- sourceType: "vector-feature-table",
1141
- description: `Vector feature request for ${normalizeLayers(request.layers).join(", ")}`,
1142
- spatial: {
1143
- bounds: {
1144
- minimum: Object.freeze([...request.boundingBox[0]]),
1145
- maximum: Object.freeze([...request.boundingBox[1]])
1146
- },
1147
- coordinateReferenceSystems
1148
- }
1149
- });
1150
- this.source = source;
1151
- this.request = request;
1152
- }
1153
- /** Loads the bound service request through the source's Arrow feature output. */
1154
- async loadTable(signal) {
1155
- const data = await this.source.getFeatures({ ...this.request, format: "arrow", signal });
1156
- return isArrowTable(data) ? data : null;
1157
- }
1158
- };
1159
- function getWGS84TileBounds(tile) {
1160
- const scale = 2 ** tile.z;
1161
- return {
1162
- minimum: [tile.x / scale * 360 - 180, tileYToLatitude(tile.y + 1, scale)],
1163
- maximum: [(tile.x + 1) / scale * 360 - 180, tileYToLatitude(tile.y, scale)]
1164
- };
1165
- }
1166
- function tileYToLatitude(tileY, scale) {
1167
- return Math.atan(Math.sinh(Math.PI * (1 - 2 * tileY / scale))) * 180 / Math.PI;
1168
- }
1169
- function inferVectorColumnRoles(columnNames) {
1170
- return Object.fromEntries(columnNames.map((columnName) => [
1171
- columnName,
1172
- columnName.toLowerCase() === "geometry" ? "geometry" : "attribute"
1173
- ]));
1174
- }
1175
- function normalizeLayers(layers) {
1176
- return Array.isArray(layers) ? layers : [layers];
1177
- }
1178
- function cloneAndFreezeLayers(layers) {
1179
- return Array.isArray(layers) ? Object.freeze([...layers]) : layers;
1180
- }
1181
- async function waitForPromise(promise, signal) {
1182
- if (!signal) {
1183
- return await promise;
1184
- }
1185
- throwIfAborted2(signal);
1186
- return await new Promise((resolve, reject) => {
1187
- const abort = () => reject(getAbortReason(signal));
1188
- signal.addEventListener("abort", abort, { once: true });
1189
- void promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
1190
- });
1191
- }
1192
- function throwIfAborted2(signal) {
1193
- if (signal == null ? void 0 : signal.aborted) {
1194
- throw getAbortReason(signal);
1195
- }
1196
- }
1197
- function getAbortReason(signal) {
1198
- return signal.reason || new DOMException("Request aborted", "AbortError");
1199
- }
1200
- //# sourceMappingURL=vector-table-scan-source.cjs.map