@query-farm/vgi 0.48.5 → 0.48.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@query-farm/vgi",
3
- "version": "0.48.5",
3
+ "version": "0.48.7",
4
4
  "description": "TypeScript framework for extending DuckDB with user-defined functions via the Vector Gateway Interface (VGI) over Arrow IPC.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Query Farm LLC (https://query.farm)",
@@ -93,12 +93,12 @@
93
93
  },
94
94
  "peerDependencies": {
95
95
  "@query-farm/apache-arrow": "^21.1.1",
96
- "@query-farm/vgi-rpc": "^0.29.6"
96
+ "@query-farm/vgi-rpc": "^0.29.7"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@duckdb/node-api": "^1.5.5-r.4",
100
100
  "@query-farm/apache-arrow": "^21.1.1",
101
- "@query-farm/vgi-rpc": "^0.29.6",
101
+ "@query-farm/vgi-rpc": "^0.29.7",
102
102
  "@types/bun": "latest",
103
103
  "typescript": "^7.0.2"
104
104
  },
@@ -26,6 +26,11 @@ import { schemaDescriptorPath, type CatalogDescriptor, type SchemaDescriptor, ty
26
26
  import { serializeColumnStatistics } from "../util/statistics.js";
27
27
  import type { VgiFunction } from "../functions/types.js";
28
28
  import type { FunctionRegistry } from "../functions/registry.js";
29
+
30
+ // Schema and view lookups may be overridden with async implementations, for a
31
+ // catalog that discovers them from a remote service; the dispatcher awaits
32
+ // them. (schemaContentsTables/tableGet are async already.)
33
+ type Awaitable<T> = T | Promise<T>;
29
34
  import { argumentSpecsToSchema } from "../arguments/argument-spec.js";
30
35
  import { serializeSchema, serializeBatch, emptyBatch, batchFromColumns } from "../util/arrow/index.js";
31
36
  import { resolveMetadata } from "../metadata/resolve.js";
@@ -329,7 +334,7 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
329
334
  return super.catalogContentsCacheable() && !this.perAttachItemIds;
330
335
  }
331
336
 
332
- schemas(attachOpaqueData: AttachOpaqueData, transactionOpaqueData?: TransactionOpaqueData): SchemaInfo[] {
337
+ schemas(attachOpaqueData: AttachOpaqueData, transactionOpaqueData?: TransactionOpaqueData): Awaitable<SchemaInfo[]> {
333
338
  return this._descriptor.schemas.map((s) => ({
334
339
  path: schemaDescriptorPath(s),
335
340
  comment: s.comment ?? null,
@@ -364,7 +369,7 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
364
369
  attachOpaqueData: AttachOpaqueData,
365
370
  path: string[],
366
371
  transactionOpaqueData?: TransactionOpaqueData
367
- ): SchemaInfo | null {
372
+ ): Awaitable<SchemaInfo | null> {
368
373
  const desc = this._descriptor.schemas.find((s) => schemaPathsEqual(schemaDescriptorPath(s), path));
369
374
  if (!desc) return null;
370
375
  return {
@@ -546,7 +551,7 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
546
551
  attachOpaqueData: AttachOpaqueData,
547
552
  path: string[],
548
553
  transactionOpaqueData?: TransactionOpaqueData
549
- ): ViewInfo[] {
554
+ ): Awaitable<ViewInfo[]> {
550
555
  const schema = this._descriptor.schemas.find((s) => schemaPathsEqual(schemaDescriptorPath(s), path));
551
556
  if (!schema || !schema.views) return [];
552
557
 
@@ -1009,13 +1014,13 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
1009
1014
  return tables.find((t) => t.name === name) ?? null;
1010
1015
  }
1011
1016
 
1012
- override viewGet(
1017
+ override async viewGet(
1013
1018
  attachOpaqueData: AttachOpaqueData,
1014
1019
  schemaPath: string[],
1015
1020
  name: string,
1016
1021
  transactionOpaqueData?: TransactionOpaqueData
1017
- ): ViewInfo | null {
1018
- const views = this.schemaContentsViews(attachOpaqueData, schemaPath, transactionOpaqueData);
1022
+ ): Promise<ViewInfo | null> {
1023
+ const views = await this.schemaContentsViews(attachOpaqueData, schemaPath, transactionOpaqueData);
1019
1024
  return views.find((v) => v.name === name) ?? null;
1020
1025
  }
1021
1026
 
@@ -229,13 +229,24 @@ class WkbBoundsReader {
229
229
  return value;
230
230
  }
231
231
 
232
- private point(littleEndian: boolean, dimensions: number): Bounds | null {
232
+ /**
233
+ * One vertex, as DuckDB core `&&` sees it: NaN on an axis leaves that axis
234
+ * unbounded and ±inf are ordinary values. Only a POINT geometry whose
235
+ * coordinates are ALL NaN, Z and M included (how WKB spells POINT EMPTY),
236
+ * has no vertex at all: `POINT Z (nan nan 5)` is a vertex unbounded on both
237
+ * axes, as are all-NaN coordinates in a LINESTRING or POLYGON.
238
+ */
239
+ private point(littleEndian: boolean, dimensions: number, isPointGeometry = false): Bounds | null {
233
240
  const x = this.float64(littleEndian);
234
241
  const y = this.float64(littleEndian);
235
- for (let dimension = 2; dimension < dimensions; dimension++) this.float64(littleEndian);
236
- if (Number.isNaN(x) && Number.isNaN(y)) return null;
237
- if (!Number.isFinite(x) || !Number.isFinite(y)) throw new FilterV2Error("WKB coordinate must be finite");
238
- return { minX: x, minY: y, maxX: x, maxY: y };
242
+ let allNaN = Number.isNaN(x) && Number.isNaN(y);
243
+ for (let dimension = 2; dimension < dimensions; dimension++) {
244
+ allNaN = Number.isNaN(this.float64(littleEndian)) && allNaN;
245
+ }
246
+ if (isPointGeometry && allNaN) return null;
247
+ const [minX, maxX] = Number.isNaN(x) ? [-Infinity, Infinity] : [x, x];
248
+ const [minY, maxY] = Number.isNaN(y) ? [-Infinity, Infinity] : [y, y];
249
+ return { minX, minY, maxX, maxY };
239
250
  }
240
251
 
241
252
  private count(littleEndian: boolean): number {
@@ -286,7 +297,7 @@ class WkbBoundsReader {
286
297
  }
287
298
  if (hasSrid) this.uint32(littleEndian);
288
299
 
289
- if (type === 1) return this.point(littleEndian, dimensions);
300
+ if (type === 1) return this.point(littleEndian, dimensions, true);
290
301
  if (type === 2) return this.points(littleEndian, dimensions);
291
302
  if (type === 3) {
292
303
  let bounds: Bounds | null = null;
@@ -503,14 +514,19 @@ export class PushdownFilters {
503
514
  mask.fill(1);
504
515
  for (const predicate of this.predicates) {
505
516
  if (predicate.expression.node === "runtime_filter" && !predicate.expression.supported) continue;
506
- let values: unknown[];
507
- try {
508
- values = Array.from({ length: batch.numRows }, (_, row) => evaluateExpression(
509
- predicate.expression, batch, row, this.evaluationContext));
510
- } catch (error) {
511
- if (predicate.mode === "advisory") continue;
512
- throw error;
513
- }
517
+ // A required predicate that cannot be evaluated fails the scan: DuckDB
518
+ // has dropped it from its own plan. An advisory one only prunes, so a
519
+ // row it cannot evaluate (malformed WKB, a non-binary value, ...) is
520
+ // kept, and the other rows are still filtered.
521
+ const advisory = predicate.mode === "advisory";
522
+ const values = Array.from({ length: batch.numRows }, (_, row) => {
523
+ try {
524
+ return evaluateExpression(predicate.expression, batch, row, this.evaluationContext);
525
+ } catch (error) {
526
+ if (advisory) return true;
527
+ throw error;
528
+ }
529
+ });
514
530
  for (let row = 0; row < batch.numRows; row++) mask[row]! &= values[row] === true ? 1 : 0;
515
531
  }
516
532
  return mask;