@loaders.gl/sql 5.0.0-alpha.8 → 5.0.0-beta.1

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 (102) hide show
  1. package/LICENSE +2 -30
  2. package/README.md +15 -10
  3. package/THIRD-PARTY-NOTICES.md +17 -0
  4. package/dist/arrow-table-source.d.ts +5 -5
  5. package/dist/arrow-table-source.d.ts.map +1 -1
  6. package/dist/arrow-table-source.js +3 -3
  7. package/dist/arrow-table-source.js.map +1 -1
  8. package/dist/compile-table-query.d.ts +3 -3
  9. package/dist/compile-table-query.d.ts.map +1 -1
  10. package/dist/compile-table-query.js +2 -2
  11. package/dist/compile-table-query.js.map +1 -1
  12. package/dist/duckdb-sql-source.d.ts +22 -13
  13. package/dist/duckdb-sql-source.d.ts.map +1 -1
  14. package/dist/duckdb-sql-source.js +40 -16
  15. package/dist/duckdb-sql-source.js.map +1 -1
  16. package/dist/index.cjs +218 -169
  17. package/dist/index.cjs.map +2 -2
  18. package/dist/index.d.ts +12 -12
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +7 -7
  21. package/dist/index.js.map +1 -1
  22. package/dist/snowflake-sql-source.d.ts +16 -12
  23. package/dist/snowflake-sql-source.d.ts.map +1 -1
  24. package/dist/snowflake-sql-source.js +1 -1
  25. package/dist/snowflake-sql-source.js.map +1 -1
  26. package/dist/sql-source.d.ts +9 -9
  27. package/dist/sql-source.d.ts.map +1 -1
  28. package/dist/sql-source.js +2 -2
  29. package/dist/sql-source.js.map +1 -1
  30. package/dist/sql-types.d.ts +13 -2
  31. package/dist/sql-types.d.ts.map +1 -1
  32. package/dist/sql-utils.d.ts +2 -3
  33. package/dist/sql-utils.d.ts.map +1 -1
  34. package/dist/sql-utils.js +1 -34
  35. package/dist/sql-utils.js.map +1 -1
  36. package/package.json +5 -26
  37. package/src/arrow-table-source.ts +7 -7
  38. package/src/compile-table-query.ts +4 -4
  39. package/src/duckdb-sql-source.ts +47 -19
  40. package/src/index.ts +16 -11
  41. package/src/snowflake-sql-source.ts +2 -2
  42. package/src/sql-source.ts +5 -5
  43. package/src/sql-types.ts +14 -2
  44. package/src/sql-utils.ts +2 -40
  45. package/dist/arrow-query.cjs +0 -1404
  46. package/dist/arrow-query.cjs.map +0 -6
  47. package/dist/arrow-query.d.ts +0 -5
  48. package/dist/arrow-query.d.ts.map +0 -1
  49. package/dist/arrow-query.js +0 -6
  50. package/dist/arrow-query.js.map +0 -1
  51. package/dist/bind-sql-predicate.d.ts +0 -4
  52. package/dist/bind-sql-predicate.d.ts.map +0 -1
  53. package/dist/bind-sql-predicate.js +0 -11
  54. package/dist/bind-sql-predicate.js.map +0 -1
  55. package/dist/parse-sql-predicate.d.ts +0 -10
  56. package/dist/parse-sql-predicate.d.ts.map +0 -1
  57. package/dist/parse-sql-predicate.js +0 -322
  58. package/dist/parse-sql-predicate.js.map +0 -1
  59. package/dist/query-arrow-table.d.ts +0 -83
  60. package/dist/query-arrow-table.d.ts.map +0 -1
  61. package/dist/query-arrow-table.js +0 -663
  62. package/dist/query-arrow-table.js.map +0 -1
  63. package/dist/sql-predicate-schema.d.ts +0 -156
  64. package/dist/sql-predicate-schema.d.ts.map +0 -1
  65. package/dist/sql-predicate-schema.js +0 -226
  66. package/dist/sql-predicate-schema.js.map +0 -1
  67. package/dist/sql-predicate-types.d.ts +0 -45
  68. package/dist/sql-predicate-types.d.ts.map +0 -1
  69. package/dist/sql-predicate-types.js +0 -9
  70. package/dist/sql-predicate-types.js.map +0 -1
  71. package/dist/sql-predicate-zod.cjs +0 -54
  72. package/dist/sql-predicate-zod.cjs.map +0 -6
  73. package/dist/sql-predicate-zod.d.ts +0 -11
  74. package/dist/sql-predicate-zod.d.ts.map +0 -1
  75. package/dist/sql-predicate-zod.js +0 -45
  76. package/dist/sql-predicate-zod.js.map +0 -1
  77. package/dist/sql-predicate.cjs +0 -607
  78. package/dist/sql-predicate.cjs.map +0 -6
  79. package/dist/sql-predicate.d.ts +0 -6
  80. package/dist/sql-predicate.d.ts.map +0 -1
  81. package/dist/sql-predicate.js +0 -8
  82. package/dist/sql-predicate.js.map +0 -1
  83. package/dist/table-query-capabilities.d.ts +0 -6
  84. package/dist/table-query-capabilities.d.ts.map +0 -1
  85. package/dist/table-query-capabilities.js +0 -26
  86. package/dist/table-query-capabilities.js.map +0 -1
  87. package/dist/table-query.cjs +0 -286
  88. package/dist/table-query.cjs.map +0 -6
  89. package/dist/table-query.d.ts +0 -29
  90. package/dist/table-query.d.ts.map +0 -1
  91. package/dist/table-query.js +0 -30
  92. package/dist/table-query.js.map +0 -1
  93. package/src/arrow-query.ts +0 -17
  94. package/src/bind-sql-predicate.ts +0 -21
  95. package/src/parse-sql-predicate.ts +0 -381
  96. package/src/query-arrow-table.ts +0 -846
  97. package/src/sql-predicate-schema.ts +0 -251
  98. package/src/sql-predicate-types.ts +0 -87
  99. package/src/sql-predicate-zod.ts +0 -52
  100. package/src/sql-predicate.ts +0 -28
  101. package/src/table-query-capabilities.ts +0 -29
  102. package/src/table-query.ts +0 -78
package/dist/index.cjs CHANGED
@@ -55,8 +55,8 @@ __export(index_exports, {
55
55
  });
56
56
  module.exports = __toCommonJS(index_exports);
57
57
 
58
- // ../loader-utils/src/lib/log-utils/log.ts
59
- var import_log = require("@probe.gl/log");
58
+ // ../core/src/loader-utils/lib/log-utils/log.ts
59
+ var import_log = require("probe.gl/log");
60
60
  var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
61
61
  var version = VERSION[0] >= "0" && VERSION[0] <= "9" ? `v${VERSION}` : "";
62
62
  function createLog() {
@@ -70,11 +70,11 @@ function createLog() {
70
70
  }
71
71
  var log = createLog();
72
72
 
73
- // ../loader-utils/src/lib/javascript-utils/is-type.ts
73
+ // ../core/src/loader-utils/lib/javascript-utils/is-type.ts
74
74
  var isObject = (value) => value !== null && typeof value === "object";
75
75
  var isPureObject = (value) => isObject(value) && value.constructor === {}.constructor;
76
76
 
77
- // ../loader-utils/src/lib/option-utils/merge-options.ts
77
+ // ../core/src/loader-utils/lib/option-utils/merge-options.ts
78
78
  function mergeOptions(baseOptions, newOptions) {
79
79
  return mergeOptionsRecursively(baseOptions || {}, newOptions);
80
80
  }
@@ -97,7 +97,7 @@ function mergeOptionsRecursively(baseOptions, newOptions, level = 0) {
97
97
  return options;
98
98
  }
99
99
 
100
- // ../loader-utils/src/lib/request-utils/authentication.ts
100
+ // ../core/src/loader-utils/lib/request-utils/authentication.ts
101
101
  function resolveCredentials(credentials, authentications = []) {
102
102
  if (credentials.every(isAuthentication)) return credentials;
103
103
  return credentials.map((credential, index) => {
@@ -134,7 +134,7 @@ function isAuthentication(credential) {
134
134
  return (credential.type === "header" || credential.type === "query-parameter") && typeof credential.name === "string" && (typeof credential.token === "string" || typeof credential.token === "function") && Array.isArray(credential.refreshStatusCodes);
135
135
  }
136
136
 
137
- // ../loader-utils/src/lib/request-utils/request-credentials.ts
137
+ // ../core/src/loader-utils/lib/request-utils/request-credentials.ts
138
138
  var AUTHENTICATED_FETCH = /* @__PURE__ */ Symbol("loaders.gl.authenticated-fetch");
139
139
  var refreshPromises = /* @__PURE__ */ new WeakMap();
140
140
  function createAuthenticatedFetch(options) {
@@ -166,26 +166,28 @@ function createAuthenticatedFetch(options) {
166
166
  );
167
167
  for (const credential of requestCredentials) normalizeRequestOrigins(credential.origins);
168
168
  const authenticatedFetch = async (url, requestOptions = {}) => {
169
- var _a, _b, _c, _d;
169
+ var _a, _b, _c, _d, _e, _f, _g;
170
170
  requestOptions = mergeFetchOptions(fetchOptions, requestOptions);
171
- if ((_a = requestOptions.signal) == null ? void 0 : _a.aborted) throw createAbortError();
171
+ (_a = requestOptions.signal) == null ? void 0 : _a.throwIfAborted();
172
172
  if (!credentials.length) return baseFetch(url, requestOptions);
173
173
  const resolvedURL = parseHTTPURL(url);
174
174
  const authorization = resolvedURL ? await authorizeRequest(resolvedURL, requestOptions, tokenCredentials) : { url, options: requestOptions, credentials: [] };
175
175
  const signedRequest = await authenticateRequest(authorization, requestCredentials, "request");
176
176
  const response = await baseFetch(signedRequest.url, signedRequest.options);
177
- const refreshableCredentials = authorization.credentials.filter(
178
- ({ credential }) => typeof credential.token === "function" && credential.refreshStatusCodes.includes(response.status)
179
- );
180
- const shouldRetrySignature = signedRequest.credentials.some(
177
+ const refreshableCredentials = [];
178
+ for (const resolvedCredential of authorization.credentials) {
179
+ const { credential } = resolvedCredential;
180
+ if (typeof credential.token === "function" && (isReplayableRequest(requestOptions) || ((_b = credential.canReplayRequest) == null ? void 0 : _b.call(credential, url, requestOptions))) && (isReplayableRequest(signedRequest.options) || ((_c = credential.canReplayRequest) == null ? void 0 : _c.call(credential, signedRequest.url, signedRequest.options))) && (credential.refreshStatusCodes.includes(response.status) || await ((_d = credential.shouldRefresh) == null ? void 0 : _d.call(credential, response))))
181
+ refreshableCredentials.push(resolvedCredential);
182
+ }
183
+ const shouldRetrySignature = isReplayableRequest(requestOptions) && isReplayableRequest(signedRequest.options) && signedRequest.credentials.some(
181
184
  (credential) => {
182
185
  var _a2;
183
186
  return (_a2 = credential.refreshStatusCodes) == null ? void 0 : _a2.includes(response.status);
184
187
  }
185
188
  );
186
- if (!refreshableCredentials.length && !shouldRetrySignature || !isReplayableRequest(requestOptions) || !isReplayableRequest(signedRequest.options))
187
- return response;
188
- if ((_b = requestOptions.signal) == null ? void 0 : _b.aborted) throw createAbortError();
189
+ if (!refreshableCredentials.length && !shouldRetrySignature) return response;
190
+ (_e = requestOptions.signal) == null ? void 0 : _e.throwIfAborted();
189
191
  const refreshedTokens = /* @__PURE__ */ new Map();
190
192
  await Promise.all(
191
193
  refreshableCredentials.map(async ({ credential }) => {
@@ -194,9 +196,9 @@ function createAuthenticatedFetch(options) {
194
196
  })
195
197
  );
196
198
  if (!refreshedTokens.size && !shouldRetrySignature) return response;
197
- await ((_c = response.body) == null ? void 0 : _c.cancel().catch(() => {
199
+ await ((_f = response.body) == null ? void 0 : _f.cancel().catch(() => {
198
200
  }));
199
- if ((_d = requestOptions.signal) == null ? void 0 : _d.aborted) throw createAbortError();
201
+ (_g = requestOptions.signal) == null ? void 0 : _g.throwIfAborted();
200
202
  const replayAuthorization = resolvedURL ? await authorizeRequest(
201
203
  resolvedURL,
202
204
  requestOptions,
@@ -231,9 +233,10 @@ function getAuthenticatedFetch(options = {}) {
231
233
  } else {
232
234
  fetchFunction = (url, requestOptions) => fetch(url, requestOptions);
233
235
  }
236
+ const fetchOptions = typeof fetchOption === "object" && fetchOption ? fetchOption : void 0;
234
237
  return createAuthenticatedFetch({
235
238
  fetch: fetchFunction,
236
- fetchOptions: typeof fetchOption === "object" && fetchOption ? fetchOption : void 0,
239
+ fetchOptions: options.signal ? { ...fetchOptions, signal: options.signal } : fetchOptions,
237
240
  credentials: ((_b = options.core) == null ? void 0 : _b.credentials) || [],
238
241
  authentications: (_c = options.core) == null ? void 0 : _c.authentications
239
242
  });
@@ -253,7 +256,7 @@ async function authenticateRequest(request, credentials, reason, response) {
253
256
  for (const credential of credentials) {
254
257
  const origin = getRequestOrigin(request.url);
255
258
  if (!origin || !normalizeRequestOrigins(credential.origins).includes(origin)) continue;
256
- if (signal == null ? void 0 : signal.aborted) throw createAbortError();
259
+ signal == null ? void 0 : signal.throwIfAborted();
257
260
  const authenticatedRequest = await credential.authenticate({
258
261
  url: request.url,
259
262
  options: { ...request.options, headers: new Headers(request.options.headers) },
@@ -269,7 +272,7 @@ async function authenticateRequest(request, credentials, reason, response) {
269
272
  };
270
273
  appliedCredentials.push(credential);
271
274
  }
272
- if (signal == null ? void 0 : signal.aborted) throw createAbortError();
275
+ signal == null ? void 0 : signal.throwIfAborted();
273
276
  return { ...request, credentials: appliedCredentials };
274
277
  }
275
278
  function getRequestOrigin(url) {
@@ -359,11 +362,8 @@ function isReplayableRequest(options) {
359
362
  if (!["GET", "HEAD", "OPTIONS", "PUT", "DELETE"].includes(method)) return false;
360
363
  return !(options.body && typeof ReadableStream !== "undefined" && options.body instanceof ReadableStream);
361
364
  }
362
- function createAbortError() {
363
- return new DOMException("The operation was aborted.", "AbortError");
364
- }
365
365
 
366
- // ../loader-utils/src/lib/path-utils/file-aliases.ts
366
+ // ../core/src/loader-utils/lib/path-utils/file-aliases.ts
367
367
  var pathPrefix = "";
368
368
  var fileAliases = {};
369
369
  function resolvePath(filename) {
@@ -379,7 +379,7 @@ function resolvePath(filename) {
379
379
  return filename;
380
380
  }
381
381
 
382
- // ../loader-utils/src/lib/sources/data-source.ts
382
+ // ../core/src/loader-utils/lib/sources/data-source.ts
383
383
  var UNAVAILABLE_CORE_API = {
384
384
  fetchFile: unavailableCoreApiMethod("fetchFile"),
385
385
  parse: unavailableCoreApiMethod("parse"),
@@ -511,7 +511,7 @@ function unavailableCoreApiMethod(methodName) {
511
511
  };
512
512
  }
513
513
 
514
- // ../loader-utils/src/lib/scan-utils/columnar-predicate.ts
514
+ // ../core/src/loader-utils/lib/scan-utils/columnar-predicate.ts
515
515
  function getColumnarPredicateColumns(predicate) {
516
516
  return [...new Set(getColumnarPredicatePaths(predicate).map((path) => path[0]))];
517
517
  }
@@ -622,8 +622,8 @@ function copyColumnarPredicateValue(value) {
622
622
  return value;
623
623
  }
624
624
 
625
- // ../loader-utils/src/lib/scan-utils/scan-query-metadata.ts
626
- var import_crs = require("@math.gl/crs");
625
+ // ../core/src/loader-utils/lib/scan-utils/scan-query-metadata.ts
626
+ var import_crs = require("@math.gl/geospatial/crs");
627
627
  function createScanQueryMetadata(options) {
628
628
  validateScanExecutionSupport(options.queryType, options.execution);
629
629
  const schema = Object.freeze({
@@ -700,7 +700,7 @@ function getNonEmptyMetadataValue(metadata, key) {
700
700
  return value || void 0;
701
701
  }
702
702
 
703
- // ../loader-utils/src/lib/scan-utils/table-query.ts
703
+ // ../core/src/loader-utils/lib/scan-utils/table-query.ts
704
704
  function planTableQuery(sourceColumnNames, options = {}) {
705
705
  validateTableQueryOptions(sourceColumnNames, options);
706
706
  const outputColumnNames = options.columns ? [...options.columns] : [...sourceColumnNames];
@@ -745,12 +745,12 @@ function validateTableQueryLimit(limit) {
745
745
  }
746
746
  }
747
747
 
748
- // ../loader-utils/src/lib/scan-utils/table-scan-batch.ts
748
+ // ../core/src/loader-utils/lib/scan-utils/table-scan-batch.ts
749
749
  function makeTableScanBatch(table) {
750
750
  return { ...table, batchType: "data", length: table.data.numRows };
751
751
  }
752
752
 
753
- // ../loader-utils/src/lib/scan-utils/relational-query.ts
753
+ // ../core/src/loader-utils/lib/scan-utils/relational-query.ts
754
754
  function planRelationalQuery(sourceColumnNames, options = {}) {
755
755
  var _a, _b, _c, _d, _e, _f;
756
756
  const available = new Set(sourceColumnNames);
@@ -840,7 +840,7 @@ function validateRelationalColumnReference(columnName, availableColumns) {
840
840
  }
841
841
  }
842
842
 
843
- // ../loader-utils/src/lib/scan-utils/table-query-explain.ts
843
+ // ../core/src/loader-utils/lib/scan-utils/table-query-explain.ts
844
844
  function explainTableQuery(sourceColumnNames, options, capabilities) {
845
845
  const plan = planTableQuery(sourceColumnNames, options);
846
846
  const outputColumns = options.columns ? [...options.columns] : [...sourceColumnNames];
@@ -864,12 +864,12 @@ function createOperatorExplanation(enabled, support) {
864
864
  return Object.freeze({ enabled, support });
865
865
  }
866
866
 
867
- // dist/sql-predicate-types.js
867
+ // ../core/src/scan/sql-predicate-types.ts
868
868
  function isSQLPredicateParameter(value) {
869
869
  return isColumnarPredicateParameter(value);
870
870
  }
871
871
 
872
- // dist/sql-predicate-schema.js
872
+ // ../core/src/scan/sql-predicate-schema.ts
873
873
  var MAXIMUM_PREDICATE_DEPTH = 64;
874
874
  var MAXIMUM_PREDICATE_NODES = 4096;
875
875
  var SQL_PREDICATE_JSON_SCHEMA = {
@@ -1022,7 +1022,9 @@ function validatePredicateNode(value, path, depth, state) {
1022
1022
  throw new Error(`SQL predicate ${path}.in requires a property and non-empty value list`);
1023
1023
  }
1024
1024
  validatePredicateProperty(value.args[0], `${path}.args[0]`);
1025
- value.args[1].forEach((item, index) => validatePredicateValue(item, `${path}.args[1][${index}]`));
1025
+ value.args[1].forEach(
1026
+ (item, index) => validatePredicateValue(item, `${path}.args[1][${index}]`)
1027
+ );
1026
1028
  return;
1027
1029
  case "=":
1028
1030
  case "<>":
@@ -1284,11 +1286,11 @@ function validateSQLIdentifier(identifier) {
1284
1286
  }
1285
1287
  }
1286
1288
 
1287
- // dist/sql-utils.js
1289
+ // ../core/src/scan/rows-to-arrow.ts
1288
1290
  var arrow5 = __toESM(require("apache-arrow"), 1);
1289
1291
 
1290
- // ../schema-utils/src/lib/schema/data-type.ts
1291
- var import_types = require("@math.gl/types");
1292
+ // ../core/src/schema-utils/lib/schema/data-type.ts
1293
+ var import_core = require("@math.gl/core");
1292
1294
  function getDataTypeFromValue(value, defaultNumberType = "float32") {
1293
1295
  if (value instanceof Date) {
1294
1296
  return "date-millisecond";
@@ -1368,7 +1370,7 @@ function getArrayTypeFromDataType(type, nullable) {
1368
1370
  case "float64":
1369
1371
  return Float64Array;
1370
1372
  case "float16":
1371
- return (0, import_types.getFloat16ArrayConstructor)();
1373
+ return (0, import_core.getFloat16ArrayConstructor)();
1372
1374
  default:
1373
1375
  break;
1374
1376
  }
@@ -1376,7 +1378,7 @@ function getArrayTypeFromDataType(type, nullable) {
1376
1378
  return Array;
1377
1379
  }
1378
1380
 
1379
- // ../schema-utils/src/lib/schema/convert-arrow-schema.ts
1381
+ // ../core/src/schema-utils/lib/schema/convert-arrow-schema.ts
1380
1382
  var arrow = __toESM(require("apache-arrow"), 1);
1381
1383
  function convertArrowToSchema(arrowSchema) {
1382
1384
  return serializeArrowSchema(arrowSchema);
@@ -1812,7 +1814,7 @@ function deserializeArrowDictionaryKeyType(keyType) {
1812
1814
  }
1813
1815
  }
1814
1816
 
1815
- // ../schema-utils/src/lib/schema/deduce-table-schema.ts
1817
+ // ../core/src/schema-utils/lib/schema/deduce-table-schema.ts
1816
1818
  function deduceTableSchema(table) {
1817
1819
  switch (table.shape) {
1818
1820
  case "array-row-table":
@@ -1889,7 +1891,7 @@ function deduceFieldFromValue(value, name) {
1889
1891
  };
1890
1892
  }
1891
1893
 
1892
- // ../schema-utils/src/lib/table/tables/make-table.ts
1894
+ // ../core/src/schema-utils/lib/table/tables/make-table.ts
1893
1895
  var arrow2 = __toESM(require("apache-arrow"), 1);
1894
1896
  function makeTableFromData(data) {
1895
1897
  let table;
@@ -1934,7 +1936,7 @@ function getTableShapeFromData(data) {
1934
1936
  throw new Error("invalid table");
1935
1937
  }
1936
1938
 
1937
- // ../schema-utils/src/lib/table/tables/table-accessors.ts
1939
+ // ../core/src/schema-utils/lib/table/tables/table-accessors.ts
1938
1940
  function getTableLength(table) {
1939
1941
  switch (table.shape) {
1940
1942
  case "array-row-table":
@@ -2139,16 +2141,16 @@ function getTableRowAsArray(table, rowIndex, target, copy) {
2139
2141
  }
2140
2142
  }
2141
2143
 
2142
- // ../schema-utils/src/lib/table/tables/table-column.ts
2144
+ // ../core/src/schema-utils/lib/table/tables/table-column.ts
2143
2145
  function makeColumnFromField(field, length) {
2144
2146
  const ArrayType = getArrayTypeFromDataType(field.type, field.nullable);
2145
2147
  return new ArrayType(length);
2146
2148
  }
2147
2149
 
2148
- // ../schema-utils/src/lib/table/tables/convert-arrow-table.ts
2150
+ // ../core/src/schema-utils/lib/table/tables/convert-arrow-table.ts
2149
2151
  var arrow4 = __toESM(require("apache-arrow"), 1);
2150
2152
 
2151
- // ../schema-utils/src/lib/table/batches/make-arrow-batch-iterator.ts
2153
+ // ../core/src/schema-utils/lib/table/batches/make-arrow-batch-iterator.ts
2152
2154
  var arrow3 = __toESM(require("apache-arrow"), 1);
2153
2155
  function* makeArrowRecordBatchIterator(table, options) {
2154
2156
  const arrowSchema = convertSchemaToArrow(table.schema);
@@ -2186,7 +2188,7 @@ function* makeArrowRecordBatchIterator(table, options) {
2186
2188
  builders.map((builder) => builder.finish());
2187
2189
  }
2188
2190
 
2189
- // ../schema-utils/src/lib/table/tables/convert-arrow-table.ts
2191
+ // ../core/src/schema-utils/lib/table/tables/convert-arrow-table.ts
2190
2192
  function convertTableToArrow(table, options) {
2191
2193
  switch (table.shape) {
2192
2194
  case "arrow-table":
@@ -2261,7 +2263,7 @@ function convertArrowToGeoJSONTable(arrowTable) {
2261
2263
  };
2262
2264
  }
2263
2265
 
2264
- // ../schema-utils/src/lib/table/tables/convert-table.ts
2266
+ // ../core/src/schema-utils/lib/table/tables/convert-table.ts
2265
2267
  function convertTable(table, shape) {
2266
2268
  switch (shape) {
2267
2269
  case "object-row-table":
@@ -2337,22 +2339,12 @@ function convertToArrowTable(table) {
2337
2339
  };
2338
2340
  }
2339
2341
 
2340
- // ../schema-utils/src/deprecated.ts
2342
+ // ../core/src/schema-utils/deprecated.ts
2341
2343
  var convertArrowToTable2 = ((...args) => convertArrowToTable(
2342
2344
  ...args
2343
2345
  ));
2344
2346
 
2345
- // dist/sql-utils.js
2346
- function isNodeRuntime() {
2347
- var _a;
2348
- return typeof process !== "undefined" && Boolean((_a = process.versions) == null ? void 0 : _a.node);
2349
- }
2350
- function escapeSqlString(value) {
2351
- return value.replace(/'/g, "''");
2352
- }
2353
- function quoteSqlIdentifier(identifier) {
2354
- return `"${identifier.replace(/"/g, '""')}"`;
2355
- }
2347
+ // ../core/src/scan/rows-to-arrow.ts
2356
2348
  function convertRowsToArrowTable(rows) {
2357
2349
  const table = rows.length > 0 ? makeTableFromData(rows) : { shape: "object-row-table", schema: { fields: [], metadata: {} }, data: rows };
2358
2350
  const schema = deducePrimitiveAwareSchema(table);
@@ -2369,6 +2361,31 @@ function convertRowsToArrowTable(rows) {
2369
2361
  data: arrow5.tableFromJSON(table.data)
2370
2362
  };
2371
2363
  }
2364
+ function deducePrimitiveAwareSchema(table) {
2365
+ return {
2366
+ ...table.schema,
2367
+ fields: table.schema.fields.map((field) => {
2368
+ if (field.type !== "null") {
2369
+ return field;
2370
+ }
2371
+ const columnValues = table.data.map((row) => row[field.name]);
2372
+ const inferredType = getDataTypeFromArray(columnValues);
2373
+ return { ...field, type: inferredType.type, nullable: inferredType.nullable };
2374
+ })
2375
+ };
2376
+ }
2377
+
2378
+ // dist/sql-utils.js
2379
+ function isNodeRuntime() {
2380
+ var _a;
2381
+ return typeof process !== "undefined" && Boolean((_a = process.versions) == null ? void 0 : _a.node);
2382
+ }
2383
+ function escapeSqlString(value) {
2384
+ return value.replace(/'/g, "''");
2385
+ }
2386
+ function quoteSqlIdentifier(identifier) {
2387
+ return `"${identifier.replace(/"/g, '""')}"`;
2388
+ }
2372
2389
  function convertSQLColumnsToSchema(columns) {
2373
2390
  return {
2374
2391
  metadata: {},
@@ -2410,25 +2427,12 @@ function mapSQLTypeToDataType(sqlType) {
2410
2427
  }
2411
2428
  return "utf8";
2412
2429
  }
2413
- function deducePrimitiveAwareSchema(table) {
2414
- return {
2415
- ...table.schema,
2416
- fields: table.schema.fields.map((field) => {
2417
- if (field.type !== "null") {
2418
- return field;
2419
- }
2420
- const columnValues = table.data.map((row) => row[field.name]);
2421
- const inferredType = getDataTypeFromArray(columnValues);
2422
- return { ...field, type: inferredType.type, nullable: inferredType.nullable };
2423
- })
2424
- };
2425
- }
2426
2430
  function getQualifiedTableName(options) {
2427
2431
  const identifiers = [options.catalogName, options.schemaName, options.tableName].filter((value) => Boolean(value));
2428
2432
  return identifiers.map((identifier) => quoteSqlIdentifier(identifier)).join(".");
2429
2433
  }
2430
2434
 
2431
- // dist/table-query-capabilities.js
2435
+ // ../core/src/scan/table-query-capabilities.ts
2432
2436
  var ARROW_TABLE_QUERY_CAPABILITIES = Object.freeze({
2433
2437
  projection: "residual",
2434
2438
  predicate: "residual",
@@ -2612,10 +2616,10 @@ function getSQLTableQueryDialect(sourceType) {
2612
2616
  throw new Error(`Portable table queries are not supported for SQL source type "${sourceType}".`);
2613
2617
  }
2614
2618
 
2615
- // dist/query-arrow-table.js
2619
+ // ../core/src/scan/query-arrow-table.ts
2616
2620
  var arrow6 = __toESM(require("apache-arrow"), 1);
2617
2621
 
2618
- // dist/table-query.js
2622
+ // ../core/src/scan/table-query.ts
2619
2623
  function planTableQuery2(sourceColumnNames, options = {}) {
2620
2624
  if (options.predicate) {
2621
2625
  validateSQLPredicate(options.predicate);
@@ -2626,18 +2630,26 @@ function explainTableQuery2(sourceColumnNames, options = {}) {
2626
2630
  if (options.predicate) {
2627
2631
  validateSQLPredicate(options.predicate);
2628
2632
  }
2629
- return explainTableQuery(sourceColumnNames, options, SQL_DATA_SOURCE_TABLE_QUERY_CAPABILITIES);
2633
+ return explainTableQuery(
2634
+ sourceColumnNames,
2635
+ options,
2636
+ SQL_DATA_SOURCE_TABLE_QUERY_CAPABILITIES
2637
+ );
2630
2638
  }
2631
2639
  function getSQLPredicateColumnNames(predicate) {
2632
2640
  return getColumnarPredicateColumns(predicate);
2633
2641
  }
2634
2642
 
2635
- // dist/query-arrow-table.js
2643
+ // ../core/src/scan/query-arrow-table.ts
2636
2644
  function explainArrowTableQuery(sourceTable, options = {}) {
2637
2645
  if (options.predicate) {
2638
2646
  validateSQLPredicate(options.predicate);
2639
2647
  }
2640
- return explainTableQuery(sourceTable.data.schema.fields.map((field) => field.name), options, ARROW_TABLE_QUERY_CAPABILITIES);
2648
+ return explainTableQuery(
2649
+ sourceTable.data.schema.fields.map((field) => field.name),
2650
+ options,
2651
+ ARROW_TABLE_QUERY_CAPABILITIES
2652
+ );
2641
2653
  }
2642
2654
  function queryArrowTable(sourceTable, options = {}) {
2643
2655
  var _a, _b;
@@ -2655,7 +2667,10 @@ function queryArrowTable(sourceTable, options = {}) {
2655
2667
  return queryArrowTableRelational(sourceTable, options);
2656
2668
  }
2657
2669
  const sourceData = sourceTable.data;
2658
- const plan = planTableQuery2(sourceData.schema.fields.map((field) => field.name), options);
2670
+ const plan = planTableQuery2(
2671
+ sourceData.schema.fields.map((field) => field.name),
2672
+ options
2673
+ );
2659
2674
  const scannedData = sourceData.select([...getScanStep(plan).columns]);
2660
2675
  const projectedData = scannedData.select([...getProjectStep(plan).columns]);
2661
2676
  const predicate = (_a = getFilterStep(plan)) == null ? void 0 : _a.predicate;
@@ -2703,8 +2718,7 @@ function queryArrowTableRelational(sourceTable, options) {
2703
2718
  let rows = arrowTableToRows(filteredTable.data);
2704
2719
  for (const child of options.union || []) {
2705
2720
  const childTable = (_a = options.tables) == null ? void 0 : _a[child.source];
2706
- if (!childTable)
2707
- throw new Error(`Arrow union source not found: ${child.source}`);
2721
+ if (!childTable) throw new Error(`Arrow union source not found: ${child.source}`);
2708
2722
  const childResult = queryArrowTable(childTable, {
2709
2723
  ...child.query || {},
2710
2724
  columns: getUnionChildColumns(sourceColumnNames, options),
@@ -2744,11 +2758,12 @@ function getUnionChildColumns(sourceColumnNames, options) {
2744
2758
  const expressionNames = new Set((options.expressions || []).map((expression) => expression.name));
2745
2759
  const aggregateNames = new Set((options.aggregates || []).map((aggregate) => aggregate.name));
2746
2760
  const outputColumns = options.columns || (((_a = options.groupBy) == null ? void 0 : _a.length) || ((_b = options.aggregates) == null ? void 0 : _b.length) ? [...options.groupBy || [], ...(options.aggregates || []).map((aggregate) => aggregate.name)] : sourceColumnNames);
2747
- const requiredColumns = new Set(outputColumns.filter((column) => !expressionNames.has(column) && !aggregateNames.has(column)));
2761
+ const requiredColumns = new Set(
2762
+ outputColumns.filter((column) => !expressionNames.has(column) && !aggregateNames.has(column))
2763
+ );
2748
2764
  for (const expression of options.expressions || []) {
2749
2765
  const definition = expression.expression;
2750
- if (definition.op === "column")
2751
- requiredColumns.add(definition.column);
2766
+ if (definition.op === "column") requiredColumns.add(definition.column);
2752
2767
  if ("left" in definition) {
2753
2768
  requiredColumns.add(definition.left);
2754
2769
  requiredColumns.add(definition.right);
@@ -2759,30 +2774,30 @@ function getUnionChildColumns(sourceColumnNames, options) {
2759
2774
  requiredColumns.add(key.column);
2760
2775
  }
2761
2776
  }
2762
- for (const column of options.groupBy || [])
2763
- requiredColumns.add(column);
2777
+ for (const column of options.groupBy || []) requiredColumns.add(column);
2764
2778
  for (const aggregate of options.aggregates || []) {
2765
- if (aggregate.column)
2766
- requiredColumns.add(aggregate.column);
2779
+ if (aggregate.column) requiredColumns.add(aggregate.column);
2767
2780
  }
2768
2781
  return sourceColumnNames.filter((column) => requiredColumns.has(column));
2769
2782
  }
2770
2783
  function hasRelationalOperators(options) {
2771
2784
  var _a, _b, _c, _d, _e;
2772
- 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) || options.join);
2785
+ return Boolean(
2786
+ ((_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) || options.join
2787
+ );
2773
2788
  }
2774
2789
  function hasRelationalOperatorsExceptJoin(options) {
2775
2790
  var _a, _b, _c, _d, _e;
2776
- 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));
2791
+ return Boolean(
2792
+ ((_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)
2793
+ );
2777
2794
  }
2778
2795
  function queryArrowJoin(sourceTable, options) {
2779
2796
  var _a;
2780
2797
  const join = options.join;
2781
- if (!join)
2782
- throw new Error("Arrow join query is missing a join definition.");
2798
+ if (!join) throw new Error("Arrow join query is missing a join definition.");
2783
2799
  const childTable = (_a = options.tables) == null ? void 0 : _a[join.child.source];
2784
- if (!childTable)
2785
- throw new Error(`Arrow join source not found: ${join.child.source}`);
2800
+ if (!childTable) throw new Error(`Arrow join source not found: ${join.child.source}`);
2786
2801
  const leftResult = queryArrowTable(sourceTable, {
2787
2802
  predicate: options.predicate,
2788
2803
  columns: void 0,
@@ -2805,28 +2820,42 @@ function queryArrowJoin(sourceTable, options) {
2805
2820
  if (leftRow[join.left] !== null && leftRow[join.left] !== void 0 && rightRow[join.right] !== null && rightRow[join.right] !== void 0 && compareSortValues(leftRow[join.left], rightRow[join.right]) === 0) {
2806
2821
  rows.push({
2807
2822
  ...leftRow,
2808
- ...Object.fromEntries(Object.entries(rightRow).map(([key, value]) => [`${rightPrefix}${key}`, value]))
2823
+ ...Object.fromEntries(
2824
+ Object.entries(rightRow).map(([key, value]) => [`${rightPrefix}${key}`, value])
2825
+ )
2809
2826
  });
2810
2827
  }
2811
2828
  }
2812
2829
  }
2813
2830
  const outputColumns = options.columns || defaultOutputColumns;
2814
- const outputRows = rows.map((row) => Object.fromEntries(outputColumns.map((column) => [column, row[column]])));
2831
+ const outputRows = rows.map(
2832
+ (row) => Object.fromEntries(outputColumns.map((column) => [column, row[column]]))
2833
+ );
2815
2834
  const limitedRows = outputRows.slice(0, options.limit);
2816
- return limitedRows.length ? convertRowsToArrowTable(limitedRows) : createEmptyRelationalResult(sourceTable.data, outputColumns, options, new Map(rightResult.data.schema.fields.map((field) => [
2817
- `${rightPrefix}${field.name}`,
2818
- new arrow6.Field(`${rightPrefix}${field.name}`, field.type, field.nullable, field.metadata)
2819
- ])));
2835
+ return limitedRows.length ? convertRowsToArrowTable(limitedRows) : createEmptyRelationalResult(
2836
+ sourceTable.data,
2837
+ outputColumns,
2838
+ options,
2839
+ new Map(
2840
+ rightResult.data.schema.fields.map((field) => [
2841
+ `${rightPrefix}${field.name}`,
2842
+ new arrow6.Field(
2843
+ `${rightPrefix}${field.name}`,
2844
+ field.type,
2845
+ field.nullable,
2846
+ field.metadata
2847
+ )
2848
+ ])
2849
+ )
2850
+ );
2820
2851
  }
2821
2852
  function validateArrowJoinQuery(sourceTable, options) {
2822
2853
  var _a, _b, _c;
2823
2854
  const join = options.join;
2824
- if (!join)
2825
- return;
2855
+ if (!join) return;
2826
2856
  const sourceColumnNames = sourceTable.data.schema.fields.map((field) => field.name);
2827
2857
  const childTable = (_a = options.tables) == null ? void 0 : _a[join.child.source];
2828
- if (!childTable)
2829
- throw new Error(`Arrow join source not found: ${join.child.source}`);
2858
+ if (!childTable) throw new Error(`Arrow join source not found: ${join.child.source}`);
2830
2859
  const childColumnNames = childTable.data.schema.fields.map((field) => field.name);
2831
2860
  if (!sourceColumnNames.includes(join.left)) {
2832
2861
  throw new Error(`Arrow join column not found: ${join.left}`);
@@ -2872,8 +2901,7 @@ function arrowTableToRows(data) {
2872
2901
  return Array.from({ length: data.numRows }, (_, rowIndex) => {
2873
2902
  const row = {};
2874
2903
  for (const column of columns) {
2875
- if (!column.vector)
2876
- throw new Error(`Arrow relational query could not read ${column.name}`);
2904
+ if (!column.vector) throw new Error(`Arrow relational query could not read ${column.name}`);
2877
2905
  row[column.name] = column.vector.get(rowIndex);
2878
2906
  }
2879
2907
  return row;
@@ -2881,14 +2909,11 @@ function arrowTableToRows(data) {
2881
2909
  }
2882
2910
  function evaluateRelationalExpression(expression, row) {
2883
2911
  const definition = expression.expression;
2884
- if (definition.op === "literal")
2885
- return definition.value;
2886
- if (definition.op === "column")
2887
- return row[definition.column];
2912
+ if (definition.op === "literal") return definition.value;
2913
+ if (definition.op === "column") return row[definition.column];
2888
2914
  const left = row[definition.left];
2889
2915
  const right = row[definition.right];
2890
- if (left === null || left === void 0 || right === null || right === void 0)
2891
- return null;
2916
+ if (left === null || left === void 0 || right === null || right === void 0) return null;
2892
2917
  if (typeof left !== "number" || typeof right !== "number") {
2893
2918
  throw new Error(`Arrow relational expression ${expression.name} requires numeric operands.`);
2894
2919
  }
@@ -2909,14 +2934,12 @@ function compareRows(left, right, orderBy) {
2909
2934
  const rightValue = right[key.column];
2910
2935
  const nulls = key.nulls || "last";
2911
2936
  if (leftValue === null || leftValue === void 0 || rightValue === null || rightValue === void 0) {
2912
- if (leftValue === rightValue)
2913
- continue;
2937
+ if (leftValue === rightValue) continue;
2914
2938
  const nullResult = leftValue === null || leftValue === void 0 ? -1 : 1;
2915
2939
  return nulls === "first" ? nullResult : -nullResult;
2916
2940
  }
2917
2941
  const result = compareSortValues(leftValue, rightValue);
2918
- if (result)
2919
- return (key.direction === "desc" ? -1 : 1) * result;
2942
+ if (result) return (key.direction === "desc" ? -1 : 1) * result;
2920
2943
  }
2921
2944
  return 0;
2922
2945
  }
@@ -2925,13 +2948,13 @@ function compareSortValues(left, right) {
2925
2948
  return compareNumbers(left.getTime(), right.getTime());
2926
2949
  if (typeof left === "bigint" && typeof right === "bigint")
2927
2950
  return left === right ? 0 : left < right ? -1 : 1;
2928
- if (typeof left === "number" && typeof right === "number")
2929
- return compareNumbers(left, right);
2951
+ if (typeof left === "number" && typeof right === "number") return compareNumbers(left, right);
2930
2952
  if (typeof left === "string" && typeof right === "string")
2931
2953
  return left === right ? 0 : left < right ? -1 : 1;
2932
- if (typeof left === "boolean" && typeof right === "boolean")
2933
- return Number(left) - Number(right);
2934
- throw new Error(`Arrow relational order cannot compare ${getValueType(left)} with ${getValueType(right)}.`);
2954
+ if (typeof left === "boolean" && typeof right === "boolean") return Number(left) - Number(right);
2955
+ throw new Error(
2956
+ `Arrow relational order cannot compare ${getValueType(left)} with ${getValueType(right)}.`
2957
+ );
2935
2958
  }
2936
2959
  function aggregateRows(rows, groupBy, aggregates) {
2937
2960
  const groups = /* @__PURE__ */ new Map();
@@ -2941,13 +2964,11 @@ function aggregateRows(rows, groupBy, aggregates) {
2941
2964
  group.push(row);
2942
2965
  groups.set(key, group);
2943
2966
  }
2944
- if (!groupBy.length && !rows.length)
2945
- groups.set("[]", []);
2967
+ if (!groupBy.length && !rows.length) groups.set("[]", []);
2946
2968
  return [...groups.values()].map((group) => {
2947
2969
  var _a;
2948
2970
  const output = {};
2949
- for (const column of groupBy)
2950
- output[column] = ((_a = group[0]) == null ? void 0 : _a[column]) ?? null;
2971
+ for (const column of groupBy) output[column] = ((_a = group[0]) == null ? void 0 : _a[column]) ?? null;
2951
2972
  for (const aggregate of aggregates)
2952
2973
  output[aggregate.name] = evaluateAggregate(aggregate, group);
2953
2974
  return output;
@@ -2955,26 +2976,25 @@ function aggregateRows(rows, groupBy, aggregates) {
2955
2976
  }
2956
2977
  function serializeGroupKey(values) {
2957
2978
  return values.map((value) => {
2958
- if (value === null || value === void 0)
2959
- return "null:";
2960
- if (value instanceof Date)
2961
- return `date:${value.getTime()}`;
2962
- if (value instanceof Uint8Array)
2963
- return `bytes:${Array.from(value).join(".")}`;
2979
+ if (value === null || value === void 0) return "null:";
2980
+ if (value instanceof Date) return `date:${value.getTime()}`;
2981
+ if (value instanceof Uint8Array) return `bytes:${Array.from(value).join(".")}`;
2964
2982
  return `${typeof value}:${String(value)}`;
2965
2983
  }).join("");
2966
2984
  }
2967
2985
  function createEmptyRelationalResult(sourceData, outputColumns, options, additionalFields) {
2968
2986
  const sourceFields = new Map(sourceData.schema.fields.map((field) => [field.name, field]));
2969
- const expressions = new Map((options.expressions || []).map((expression) => [expression.name, expression]));
2970
- const aggregates = new Map((options.aggregates || []).map((aggregate) => [aggregate.name, aggregate]));
2987
+ const expressions = new Map(
2988
+ (options.expressions || []).map((expression) => [expression.name, expression])
2989
+ );
2990
+ const aggregates = new Map(
2991
+ (options.aggregates || []).map((aggregate) => [aggregate.name, aggregate])
2992
+ );
2971
2993
  const fields = outputColumns.map((columnName) => {
2972
2994
  const sourceField = sourceFields.get(columnName);
2973
- if (sourceField)
2974
- return sourceField;
2995
+ if (sourceField) return sourceField;
2975
2996
  const additionalField = additionalFields == null ? void 0 : additionalFields.get(columnName);
2976
- if (additionalField)
2977
- return additionalField;
2997
+ if (additionalField) return additionalField;
2978
2998
  const expression = expressions.get(columnName);
2979
2999
  if (expression)
2980
3000
  return new arrow6.Field(columnName, getExpressionType(expression, sourceFields), true);
@@ -2984,18 +3004,15 @@ function createEmptyRelationalResult(sourceData, outputColumns, options, additio
2984
3004
  return new arrow6.Field(columnName, new arrow6.Utf8(), true);
2985
3005
  });
2986
3006
  const columns = {};
2987
- for (const field of fields)
2988
- columns[field.name] = arrow6.vectorFromArray([], field.type);
3007
+ for (const field of fields) columns[field.name] = arrow6.vectorFromArray([], field.type);
2989
3008
  return wrapArrowTable(new arrow6.Table(new arrow6.Schema(fields), columns));
2990
3009
  }
2991
3010
  function getExpressionType(expression, sourceFields) {
2992
3011
  var _a;
2993
3012
  if (expression.expression.op === "literal") {
2994
3013
  const value = expression.expression.value;
2995
- if (typeof value === "boolean")
2996
- return new arrow6.Bool();
2997
- if (typeof value === "number")
2998
- return new arrow6.Float64();
3014
+ if (typeof value === "boolean") return new arrow6.Bool();
3015
+ if (typeof value === "number") return new arrow6.Float64();
2999
3016
  return new arrow6.Utf8();
3000
3017
  }
3001
3018
  if (expression.expression.op === "column") {
@@ -3005,16 +3022,14 @@ function getExpressionType(expression, sourceFields) {
3005
3022
  }
3006
3023
  function getAggregateType(aggregate, sourceFields) {
3007
3024
  var _a;
3008
- if (aggregate.function === "count")
3009
- return new arrow6.Int32();
3025
+ if (aggregate.function === "count") return new arrow6.Int32();
3010
3026
  return aggregate.column ? ((_a = sourceFields.get(aggregate.column)) == null ? void 0 : _a.type) || new arrow6.Float64() : new arrow6.Float64();
3011
3027
  }
3012
3028
  function evaluateAggregate(aggregate, rows) {
3013
3029
  if (aggregate.function === "count")
3014
3030
  return aggregate.column ? rows.filter((row) => row[aggregate.column] != null).length : rows.length;
3015
3031
  const values = rows.map((row) => row[aggregate.column]).filter((value) => value != null);
3016
- if (!values.length)
3017
- return null;
3032
+ if (!values.length) return null;
3018
3033
  if (!values.every((value) => typeof value === "number"))
3019
3034
  throw new Error(`Arrow aggregate ${aggregate.function} requires numeric values.`);
3020
3035
  const numericValues = values;
@@ -3110,7 +3125,9 @@ function evaluateComparison(value, predicate) {
3110
3125
  }
3111
3126
  function compareValues(left, right) {
3112
3127
  if (isSQLPredicateParameter(right)) {
3113
- throw new Error(`Arrow query parameter ":${right.parameter}" must be bound before query execution.`);
3128
+ throw new Error(
3129
+ `Arrow query parameter ":${right.parameter}" must be bound before query execution.`
3130
+ );
3114
3131
  }
3115
3132
  if (left instanceof Date && right instanceof Date) {
3116
3133
  return compareNumbers(left.getTime(), right.getTime());
@@ -3139,7 +3156,9 @@ function compareValues(left, right) {
3139
3156
  if (typeof left === "boolean" && typeof right === "boolean") {
3140
3157
  return Number(left) - Number(right);
3141
3158
  }
3142
- throw new Error(`Arrow query cannot compare ${getValueType(left)} with ${getValueType(right)} values.`);
3159
+ throw new Error(
3160
+ `Arrow query cannot compare ${getValueType(left)} with ${getValueType(right)} values.`
3161
+ );
3143
3162
  }
3144
3163
  function compareNumbers(left, right) {
3145
3164
  if (!Number.isFinite(left) || !Number.isFinite(right)) {
@@ -3188,7 +3207,9 @@ function getFilterStep(plan) {
3188
3207
  return plan.find((candidate) => candidate.kind === "filter");
3189
3208
  }
3190
3209
  function getProjectStep(plan) {
3191
- const step = plan.find((candidate) => candidate.kind === "project");
3210
+ const step = plan.find(
3211
+ (candidate) => candidate.kind === "project"
3212
+ );
3192
3213
  if (!step) {
3193
3214
  throw new Error("Arrow query plan is missing a project step.");
3194
3215
  }
@@ -3269,7 +3290,8 @@ function throwIfAborted2(signal) {
3269
3290
  }
3270
3291
 
3271
3292
  // dist/duckdb-sql-source.js
3272
- var VERSION2 = true ? "5.0.0-alpha.8" : "latest";
3293
+ var import_apache_arrow = require("apache-arrow");
3294
+ var VERSION2 = true ? "5.0.0-beta.1" : "latest";
3273
3295
  var DuckDBSQLSource = {
3274
3296
  dataType: null,
3275
3297
  batchType: null,
@@ -3311,6 +3333,18 @@ var DuckDBSQLSource = {
3311
3333
  createDataSource: (data, options, coreApi) => new DuckDBSQLDataSource(data, options, coreApi)
3312
3334
  };
3313
3335
  var DuckDBSQLDataSource = class extends SQLDataSource {
3336
+ /** Uploads an Arrow table through IPC. Supported by the browser DuckDB-Wasm adapter. */
3337
+ async insertArrowTable(table, options) {
3338
+ await this.insertArrowIPC((0, import_apache_arrow.tableToIPC)(table.data, "stream"), options);
3339
+ }
3340
+ /** Uploads a complete Arrow IPC stream to a browser DuckDB-Wasm table. */
3341
+ async insertArrowIPC(bytes, options) {
3342
+ const adapter = await this.getAdapter();
3343
+ if (!adapter.insertArrowIPC) {
3344
+ throw new Error("This DuckDB adapter does not support Arrow IPC uploads.");
3345
+ }
3346
+ await adapter.insertArrowIPC(bytes, options);
3347
+ }
3314
3348
  constructor(data, options, coreApi) {
3315
3349
  super(data, options, DuckDBSQLSource.type, SQL_SOURCE_DEFAULT_OPTIONS, createDuckDBAdapter, coreApi);
3316
3350
  }
@@ -3450,7 +3484,7 @@ async function createDuckDBBrowserAdapter(context) {
3450
3484
  const connection = await database.connect();
3451
3485
  const executeRows = async (sqlText, options = {}) => {
3452
3486
  const result = await executeDuckDBBrowserQuery(connection, sqlText, options.parameters);
3453
- return convertArrowToTable2(result, "object-row-table").data;
3487
+ return convertArrowToTable2((0, import_apache_arrow.tableFromIPC)(result), "object-row-table").data;
3454
3488
  };
3455
3489
  return {
3456
3490
  capabilities: {
@@ -3459,6 +3493,13 @@ async function createDuckDBBrowserAdapter(context) {
3459
3493
  runtime: "browser",
3460
3494
  isDynamic: true
3461
3495
  },
3496
+ async insertArrowIPC(bytes, options) {
3497
+ await connection.insertArrowFromIPCStream(new Uint8Array(bytes), {
3498
+ name: options.tableName,
3499
+ schema: options.schemaName,
3500
+ create: options.create ?? true
3501
+ });
3502
+ },
3462
3503
  async connect() {
3463
3504
  },
3464
3505
  async close() {
@@ -3535,21 +3576,23 @@ async function createDuckDBBrowserAdapter(context) {
3535
3576
  },
3536
3577
  async executeArrow(sqlText, options = {}) {
3537
3578
  const result = await executeDuckDBBrowserQuery(connection, sqlText, options.parameters);
3538
- return convertArrowToTable2(result, "arrow-table");
3579
+ return convertArrowToTable2((0, import_apache_arrow.tableFromIPC)(result), "arrow-table");
3539
3580
  }
3540
3581
  };
3541
3582
  }
3542
3583
  async function executeDuckDBBrowserQuery(connection, sqlText, parameters) {
3543
- if (!parameters) {
3544
- return await connection.query(sqlText);
3545
- }
3546
- const values = Array.isArray(parameters) ? parameters : Object.values(parameters);
3547
- const statement = await connection.prepare(sqlText);
3548
- try {
3549
- return await statement.query(...values);
3550
- } finally {
3551
- await statement.close();
3552
- }
3584
+ return await connection.useUnsafe(async (bindings, connectionId) => {
3585
+ if (!parameters) {
3586
+ return await bindings.runQuery(connectionId, sqlText);
3587
+ }
3588
+ const values = Array.isArray(parameters) ? parameters : Object.values(parameters);
3589
+ const statementId = await bindings.createPrepared(connectionId, sqlText);
3590
+ try {
3591
+ return await bindings.runPrepared(connectionId, statementId, values);
3592
+ } finally {
3593
+ await bindings.closePrepared(connectionId, statementId);
3594
+ }
3595
+ });
3553
3596
  }
3554
3597
  function getDuckDBDatabasePath(url, options) {
3555
3598
  var _a;
@@ -3565,7 +3608,7 @@ function getDuckDBDatabasePath(url, options) {
3565
3608
  }
3566
3609
 
3567
3610
  // dist/snowflake-sql-source.js
3568
- var VERSION3 = true ? "5.0.0-alpha.8" : "latest";
3611
+ var VERSION3 = true ? "5.0.0-beta.1" : "latest";
3569
3612
  var SnowflakeSQLSource = {
3570
3613
  dataType: null,
3571
3614
  batchType: null,
@@ -3770,12 +3813,16 @@ function getSnowflakeBaseUrl(url, options) {
3770
3813
  return `https://${account}.snowflakecomputing.com`;
3771
3814
  }
3772
3815
 
3773
- // dist/parse-sql-predicate.js
3816
+ // ../core/src/scan/parse-sql-predicate.ts
3774
3817
  var MAXIMUM_SQL_LENGTH = 65536;
3775
3818
  var MAXIMUM_SQL_TOKENS = 4096;
3776
3819
  var MAXIMUM_EXPRESSION_DEPTH = 64;
3777
3820
  function parseSQLPredicate(source, options = {}) {
3778
- const parser = new SQLPredicateParser(source, options.parameters ?? {}, options.preserveParameters === true);
3821
+ const parser = new SQLPredicateParser(
3822
+ source,
3823
+ options.parameters ?? {},
3824
+ options.preserveParameters === true
3825
+ );
3779
3826
  const predicate = parser.parse();
3780
3827
  validateSQLPredicate(predicate);
3781
3828
  return predicate;
@@ -4020,7 +4067,9 @@ function tokenizeSQLPredicate(source) {
4020
4067
  position += match[0].length + 1;
4021
4068
  } else {
4022
4069
  const numberMatch = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(source.slice(position));
4023
- const identifierMatch = /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*/.exec(source.slice(position));
4070
+ const identifierMatch = /^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*/.exec(
4071
+ source.slice(position)
4072
+ );
4024
4073
  if (numberMatch) {
4025
4074
  tokens.push({ kind: "number", value: numberMatch[0] });
4026
4075
  position += numberMatch[0].length;
@@ -4064,7 +4113,7 @@ function readQuotedToken(source, start, quote, escapedQuote) {
4064
4113
  throw new Error(`SQL predicate contains an unterminated quoted value at character ${start}`);
4065
4114
  }
4066
4115
 
4067
- // dist/bind-sql-predicate.js
4116
+ // ../core/src/scan/bind-sql-predicate.ts
4068
4117
  function bindSQLPredicate(predicate, parameters) {
4069
4118
  validateSQLPredicate(predicate);
4070
4119
  return bindColumnarPredicateParameters(predicate, parameters);