@query-farm/vgi 0.44.0 → 0.46.0

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 (73) hide show
  1. package/README.md +8 -1
  2. package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
  3. package/dist/arrow/impl-arrowjs/ipc.d.ts +6 -0
  4. package/dist/arrow/impl-flechette/build.d.ts +2 -2
  5. package/dist/arrow/impl-flechette/canonical.d.ts +2 -2
  6. package/dist/arrow/impl-flechette/index.d.ts +1 -1
  7. package/dist/arrow/impl-flechette/ipc.d.ts +6 -0
  8. package/dist/arrow/impl-flechette/schema.d.ts +19 -5
  9. package/dist/arrow/index.d.ts +1 -1
  10. package/dist/catalog/contents-codec.d.ts +7 -0
  11. package/dist/catalog/contents-digest.d.ts +2 -1
  12. package/dist/catalog/interface.d.ts +3 -0
  13. package/dist/catalog/publication-envelope.d.ts +1 -0
  14. package/dist/catalog/publication.d.ts +142 -0
  15. package/dist/catalog/s3-publication.d.ts +38 -0
  16. package/dist/client/client.d.ts +20 -1
  17. package/dist/client-entry.js +189 -37
  18. package/dist/client-entry.js.map +15 -12
  19. package/dist/codec/asd.d.ts +4 -0
  20. package/dist/functions/continuation.d.ts +69 -0
  21. package/dist/functions/table-in-out.d.ts +51 -7
  22. package/dist/functions/types.d.ts +20 -0
  23. package/dist/generated/vgi-client.d.ts +7 -14
  24. package/dist/generated/vgi-protocol-schemas.d.ts +2 -0
  25. package/dist/generated/vgi-protocol-types.d.ts +26 -3
  26. package/dist/generated/vgi-service.d.ts +3 -3
  27. package/dist/index.core.d.ts +1 -0
  28. package/dist/index.d.ts +4 -0
  29. package/dist/index.js +981 -138
  30. package/dist/index.js.map +31 -25
  31. package/dist/protocol/dispatch.d.ts +1 -1
  32. package/dist/protocol/handlers/catalog/contents.d.ts +4 -4
  33. package/dist/serve-entry.js +643 -81
  34. package/dist/serve-entry.js.map +22 -18
  35. package/dist/util/parent-rows.d.ts +8 -0
  36. package/dist/worker-cf-entry.d.ts +1 -1
  37. package/dist/worker-cf-entry.js +821 -131
  38. package/dist/worker-cf-entry.js.map +29 -24
  39. package/package.json +4 -4
  40. package/src/arrow/impl-arrowjs/index.ts +1 -0
  41. package/src/arrow/impl-arrowjs/ipc.ts +23 -0
  42. package/src/arrow/impl-flechette/build.ts +4 -2
  43. package/src/arrow/impl-flechette/canonical.ts +14 -7
  44. package/src/arrow/impl-flechette/index.ts +1 -0
  45. package/src/arrow/impl-flechette/ipc.ts +19 -0
  46. package/src/arrow/index.ts +1 -1
  47. package/src/catalog/contents-codec.ts +77 -0
  48. package/src/catalog/contents-digest.ts +20 -17
  49. package/src/catalog/interface.ts +3 -0
  50. package/src/catalog/publication-envelope.ts +62 -0
  51. package/src/catalog/publication.ts +290 -0
  52. package/src/catalog/read-only.ts +6 -2
  53. package/src/catalog/s3-publication.ts +81 -0
  54. package/src/client/client.ts +82 -30
  55. package/src/codec/asd.ts +40 -1
  56. package/src/codec/conform.ts +2 -1
  57. package/src/filter-pushdown/collector.ts +17 -1
  58. package/src/functions/continuation.ts +202 -0
  59. package/src/functions/table-in-out.ts +131 -56
  60. package/src/functions/types.ts +20 -0
  61. package/src/generated/vgi-client.ts +8 -16
  62. package/src/generated/vgi-protocol-schemas.ts +14 -6
  63. package/src/generated/vgi-protocol-types.ts +39 -5
  64. package/src/generated/vgi-service.ts +4 -3
  65. package/src/index.core.ts +6 -0
  66. package/src/index.ts +5 -0
  67. package/src/protocol/dispatch.ts +1 -1
  68. package/src/protocol/handlers/catalog/admin.ts +7 -4
  69. package/src/protocol/handlers/catalog/contents.ts +50 -35
  70. package/src/protocol/handlers/function.ts +12 -0
  71. package/src/protocol/state-serializer.ts +7 -1
  72. package/src/util/parent-rows.ts +41 -0
  73. package/src/worker-cf-entry.ts +3 -0
@@ -39,6 +39,7 @@ __export(exports_impl_arrowjs, {
39
39
  decodeDictValue: () => decodeDictValue,
40
40
  denseUnion: () => denseUnion,
41
41
  deserializeBatch: () => deserializeBatch,
42
+ deserializeBatches: () => deserializeBatches,
42
43
  deserializeSchema: () => deserializeSchema,
43
44
  dictionary: () => dictionary,
44
45
  duration: () => duration,
@@ -68,6 +69,8 @@ __export(exports_impl_arrowjs, {
68
69
  safeNumber: () => safeNumber,
69
70
  schema: () => schema,
70
71
  serializeBatch: () => serializeBatch,
72
+ serializeBatches: () => serializeBatches,
73
+ serializeCollectionRows: () => serializeCollectionRows,
71
74
  serializeSchema: () => serializeSchema,
72
75
  sparseUnion: () => sparseUnion,
73
76
  struct: () => struct,
@@ -1732,6 +1735,24 @@ function deserializeBatch(bytes) {
1732
1735
  }
1733
1736
  return batches[0];
1734
1737
  }
1738
+ function deserializeBatches(bytes) {
1739
+ return [...RecordBatchReader.from(bytes)];
1740
+ }
1741
+ function serializeBatches(batches, schema) {
1742
+ const writer = new RecordBatchStreamWriter;
1743
+ writer.reset(undefined, schema);
1744
+ for (const batch of batches)
1745
+ writer._writeRecordBatch(batch);
1746
+ writer.close();
1747
+ return writer.toUint8Array(true);
1748
+ }
1749
+ function serializeCollectionRows(schema, rows, maxBatchRows) {
1750
+ const batch = batchFromRows(rows, schema);
1751
+ const batches = [];
1752
+ for (let offset = 0;offset < batch.numRows; offset += maxBatchRows)
1753
+ batches.push(batch.slice(offset, offset + maxBatchRows));
1754
+ return serializeBatches(batches, schema);
1755
+ }
1735
1756
  // src/arrow/impl-arrowjs/statistics.ts
1736
1757
  import {
1737
1758
  Field as Field3,
@@ -1893,6 +1914,14 @@ function map2(keyField, valueField, keysSorted) {
1893
1914
  function dictionary2(valueType, indexType, ordered, id) {
1894
1915
  return dictionary(valueType, indexType, ordered, id);
1895
1916
  }
1917
+ // src/cache-control.ts
1918
+ var CACHE_NOT_MODIFIED_KEY = "vgi.cache.not_modified";
1919
+
1920
+ // src/functions/continuation.ts
1921
+ var STATUS_KEY = "vgi.status";
1922
+ var HAVE_MORE_OUTPUT = "HAVE_MORE_OUTPUT";
1923
+ var CONTINUE = "CONTINUE";
1924
+
1896
1925
  // src/arguments/arguments.ts
1897
1926
  class Arguments {
1898
1927
  positional;
@@ -2098,7 +2127,9 @@ function mapPairs(raw) {
2098
2127
  return Object.entries(raw);
2099
2128
  }
2100
2129
  function zeroValue(type) {
2101
- if (isUtf8(type) || isDictionary(type))
2130
+ if (isDictionary(type))
2131
+ return zeroValue(type.dictionary);
2132
+ if (isUtf8(type))
2102
2133
  return "";
2103
2134
  if (isBinary(type))
2104
2135
  return new Uint8Array(0);
@@ -2537,7 +2568,7 @@ function normalizeValue(raw, type) {
2537
2568
  return out;
2538
2569
  }
2539
2570
  if (isDictionary(type)) {
2540
- return raw == null ? null : String(raw);
2571
+ return normalizeValue(raw, type.dictionary);
2541
2572
  }
2542
2573
  if (isBinary(type)) {
2543
2574
  return toUint8Array3(raw);
@@ -2566,6 +2597,35 @@ function toUint8Array3(val) {
2566
2597
  }
2567
2598
  return new Uint8Array(0);
2568
2599
  }
2600
+ function decodeASDCollection(schema, bytes) {
2601
+ if (bytes == null)
2602
+ return [];
2603
+ const output = [];
2604
+ const batches = deserializeBatches(bytes);
2605
+ const validateSchema = (actualSchema) => {
2606
+ if (actualSchema.fields.length !== schema.fields.length || schema.fields.some((field, i) => {
2607
+ const actual = actualSchema.fields[i];
2608
+ return actual.name !== field.name || actual.nullable !== field.nullable || typeSignature(actual.type) !== typeSignature(field.type);
2609
+ }))
2610
+ throw new Error("catalog collection has an incompatible metadata schema");
2611
+ };
2612
+ if (batches.length === 0)
2613
+ validateSchema(deserializeSchema(bytes));
2614
+ for (const batch of batches) {
2615
+ validateSchema(batch.schema);
2616
+ for (let row = 0;row < batch.numRows; row++) {
2617
+ const item = {};
2618
+ for (const field of schema.fields) {
2619
+ const value = batch.getChild(field.name)?.get(row);
2620
+ if (value == null && !field.nullable)
2621
+ throw new Error(`catalog collection has null ${field.name}`);
2622
+ item[field.name] = normalizeValue(value, field.type);
2623
+ }
2624
+ output.push(item);
2625
+ }
2626
+ }
2627
+ return output;
2628
+ }
2569
2629
 
2570
2630
  // src/generated/vgi-protocol-schemas.ts
2571
2631
  var CatalogInfoSchema = schema2([
@@ -2579,7 +2639,6 @@ var CatalogInfoSchema = schema2([
2579
2639
  var SchemaInfoSchema = schema2([
2580
2640
  field2("comment", utf82(), true),
2581
2641
  field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
2582
- field2("attach_opaque_data", binary2(), false),
2583
2642
  field2("path", list2(field2("item", utf82(), true)), false),
2584
2643
  field2("estimated_object_count", map2(field2("key", utf82(), false), field2("value", int642(), true), false), true)
2585
2644
  ]);
@@ -2620,9 +2679,9 @@ var FunctionInfoSchema = schema2([
2620
2679
  field2("name", utf82(), false),
2621
2680
  field2("schema_path", list2(field2("item", utf82(), true)), false),
2622
2681
  field2("function_type", dictionary2(utf82(), int162()), false),
2623
- field2("arguments", binary2(), false),
2624
- field2("output_schema", binary2(), false),
2625
- field2("parameter_default_values", binary2(), true),
2682
+ field2("arguments", dictionary2(binary2(), int322()), false),
2683
+ field2("output_schema", dictionary2(binary2(), int322()), false),
2684
+ field2("parameter_default_values", dictionary2(binary2(), int322()), true),
2626
2685
  field2("stability", dictionary2(utf82(), int162()), true),
2627
2686
  field2("null_handling", dictionary2(utf82(), int162()), true),
2628
2687
  field2("argument_monotonicity", list2(field2("item", utf82(), true)), true),
@@ -2654,6 +2713,7 @@ var FunctionInfoSchema = schema2([
2654
2713
  field2("sink_order_dependent", bool2(), false),
2655
2714
  field2("requires_input_batch_index", bool2(), false),
2656
2715
  field2("input_from_args", bool2(), false),
2716
+ field2("input_rows_per_call", int642(), true),
2657
2717
  field2("required_settings", list2(field2("item", utf82(), true)), false),
2658
2718
  field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false)
2659
2719
  ]);
@@ -3083,7 +3143,12 @@ var CatalogContentsResultSchema = schema2([
3083
3143
  field2("catalog_version", int642(), false),
3084
3144
  field2("etag", utf82(), true),
3085
3145
  field2("not_modified", bool2(), false),
3086
- field2("schemas", list2(field2("item", struct2([field2("path", list2(field2("item", utf82(), true)), false), field2("schema", binary2(), false), field2("tables", list2(field2("item", binary2(), true)), false), field2("views", list2(field2("item", binary2(), true)), false), field2("scalar_functions", list2(field2("item", binary2(), true)), false), field2("aggregate_functions", list2(field2("item", binary2(), true)), false), field2("table_functions", list2(field2("item", binary2(), true)), false), field2("scalar_macros", list2(field2("item", binary2(), true)), false), field2("table_macros", list2(field2("item", binary2(), true)), false), field2("indexes", list2(field2("item", binary2(), true)), false)]), true)), false)
3146
+ field2("schemas", binary2(), true),
3147
+ field2("tables", binary2(), true),
3148
+ field2("views", binary2(), true),
3149
+ field2("functions", binary2(), true),
3150
+ field2("macros", binary2(), true),
3151
+ field2("indexes", binary2(), true)
3087
3152
  ]);
3088
3153
  var CatalogCopyFromFormatsResultSchema = schema2([
3089
3154
  field2("items", list2(field2("item", binary2(), true)), false)
@@ -3702,6 +3767,77 @@ function wrapRpcWithErrorEnrichment(rpc) {
3702
3767
  };
3703
3768
  }
3704
3769
 
3770
+ // src/catalog/contents-codec.ts
3771
+ var schemaPathKey = (path) => JSON.stringify(path.map((part) => part.toLowerCase()));
3772
+ var CATALOG_STREAM_KINDS = ["schemas", "tables", "views", "functions", "macros", "indexes"];
3773
+ function decodeCatalogStreams(response, ifNoneMatch) {
3774
+ if (response.not_modified) {
3775
+ if (response.etag == null || ifNoneMatch !== undefined && response.etag !== ifNoneMatch || CATALOG_STREAM_KINDS.some((kind) => response[kind] != null)) {
3776
+ throw new Error("invalid catalog_contents not_modified response");
3777
+ }
3778
+ return [];
3779
+ }
3780
+ const infos = decodeASDCollection(SchemaInfoSchema, response.schemas);
3781
+ const schemas = [];
3782
+ const index = new Map;
3783
+ for (const schema of infos) {
3784
+ if (!Array.isArray(schema.path) || schema.path.length === 0)
3785
+ throw new Error("catalog schema has an empty path");
3786
+ const key = schemaPathKey(schema.path);
3787
+ if (index.has(key))
3788
+ throw new Error("catalog contains duplicate schema paths");
3789
+ if (schema.path.length > 1 && !index.has(schemaPathKey(schema.path.slice(0, -1)))) {
3790
+ throw new Error("catalog schema is missing its preceding parent");
3791
+ }
3792
+ const entry = { schema, tables: [], views: [], scalar_functions: [], aggregate_functions: [], table_functions: [], scalar_macros: [], table_macros: [], indexes: [] };
3793
+ index.set(key, entry);
3794
+ schemas.push(entry);
3795
+ }
3796
+ const owner = (item) => {
3797
+ const entry = index.get(schemaPathKey(item.schema_path));
3798
+ if (!entry)
3799
+ throw new Error("catalog object references an absent schema");
3800
+ return entry;
3801
+ };
3802
+ for (const item of decodeASDCollection(TableInfoSchema, response.tables))
3803
+ owner(item).tables.push(item);
3804
+ for (const item of decodeASDCollection(ViewInfoSchema, response.views))
3805
+ owner(item).views.push(item);
3806
+ for (const item of decodeASDCollection(FunctionInfoSchema, response.functions)) {
3807
+ const entry = owner(item);
3808
+ switch (String(item.function_type).toUpperCase()) {
3809
+ case "SCALAR":
3810
+ entry.scalar_functions.push(item);
3811
+ break;
3812
+ case "AGGREGATE":
3813
+ entry.aggregate_functions.push(item);
3814
+ break;
3815
+ case "TABLE":
3816
+ case "TABLE_BUFFERING":
3817
+ entry.table_functions.push(item);
3818
+ break;
3819
+ default:
3820
+ throw new Error(`unknown catalog function type ${item.function_type}`);
3821
+ }
3822
+ }
3823
+ for (const item of decodeASDCollection(MacroInfoSchema, response.macros)) {
3824
+ const entry = owner(item);
3825
+ switch (String(item.macro_type).toUpperCase()) {
3826
+ case "SCALAR":
3827
+ entry.scalar_macros.push(item);
3828
+ break;
3829
+ case "TABLE":
3830
+ entry.table_macros.push(item);
3831
+ break;
3832
+ default:
3833
+ throw new Error(`unknown catalog macro type ${item.macro_type}`);
3834
+ }
3835
+ }
3836
+ for (const item of decodeASDCollection(IndexInfoSchema, response.indexes))
3837
+ owner(item).indexes.push(item);
3838
+ return schemas;
3839
+ }
3840
+
3705
3841
  // src/client/helpers.ts
3706
3842
  function deserializeInfoList(items, deserializeFn) {
3707
3843
  if (!items)
@@ -3742,6 +3878,42 @@ function toAsyncIterator(input) {
3742
3878
  function onConflictName(onConflict) {
3743
3879
  return String(onConflict).toUpperCase();
3744
3880
  }
3881
+ function isNotModified(md) {
3882
+ const v = md.get(CACHE_NOT_MODIFIED_KEY);
3883
+ return v != null && v !== "0" && v.toLowerCase() !== "false";
3884
+ }
3885
+ async function* exchangeContinued(session, functionName, input) {
3886
+ const raw = session;
3887
+ if (typeof raw.exchangeRaw !== "function") {
3888
+ throw new VgiClientError(`tableInOutFunction(${functionName}): the transport's stream session has no exchangeRaw(), ` + `which continued output needs to read each reply's vgi.status`);
3889
+ }
3890
+ const exchangeRaw = raw.exchangeRaw.bind(session);
3891
+ let tick = false;
3892
+ let reply = await exchangeRaw({ batch: input, metadata: new Map });
3893
+ for (;; ) {
3894
+ if (reply === null) {
3895
+ if (tick) {
3896
+ throw new VgiClientError(`tableInOutFunction(${functionName}): the worker ended the stream while output was pending`);
3897
+ }
3898
+ return;
3899
+ }
3900
+ const md = new Map([...reply.batch.metadata ?? [], ...reply.metadata]);
3901
+ const more = md.get(STATUS_KEY) === HAVE_MORE_OUTPUT;
3902
+ if (isNotModified(md) && (more || tick)) {
3903
+ throw new VgiClientError(`tableInOutFunction(${functionName}): the worker answered not_modified on a continued reply ` + `(${tick ? "answering a continuation tick" : "one saying HAVE_MORE_OUTPUT"}); ` + `not_modified must be an input's only reply`);
3904
+ }
3905
+ const rows = [...iterRows(reply.batch)];
3906
+ if (rows.length > 0)
3907
+ yield rows;
3908
+ if (!more)
3909
+ return;
3910
+ tick = true;
3911
+ reply = await exchangeRaw({
3912
+ batch: emptyBatch(input.schema),
3913
+ metadata: new Map([[STATUS_KEY, CONTINUE]])
3914
+ });
3915
+ }
3916
+ }
3745
3917
 
3746
3918
  class VgiClient {
3747
3919
  rpc;
@@ -3906,13 +4078,9 @@ class VgiClient {
3906
4078
  joinKeys: opts.joinKeys
3907
4079
  });
3908
4080
  try {
3909
- const outRows = await inputSession.exchange([...iterRows(firstBatch)]);
3910
- if (outRows.length > 0)
3911
- yield outRows;
4081
+ yield* exchangeContinued(inputSession, opts.functionName, firstBatch);
3912
4082
  for await (const batch of { [Symbol.asyncIterator]: () => inputIter }) {
3913
- const result = await inputSession.exchange([...iterRows(batch)]);
3914
- if (result.length > 0)
3915
- yield result;
4083
+ yield* exchangeContinued(inputSession, opts.functionName, batch);
3916
4084
  }
3917
4085
  } finally {
3918
4086
  inputSession.close();
@@ -3957,13 +4125,13 @@ class VgiClient {
3957
4125
  });
3958
4126
  const outputSchema = bindResp.output_schema;
3959
4127
  try {
3960
- const outRows = await inputSession.exchange([...iterRows(firstBatch)]);
3961
- if (outRows.length > 0)
3962
- yield batchFromRows(outRows, outputSchema);
4128
+ for await (const rows of exchangeContinued(inputSession, opts.functionName, firstBatch)) {
4129
+ yield batchFromRows(rows, outputSchema);
4130
+ }
3963
4131
  for await (const batch of { [Symbol.asyncIterator]: () => inputIter }) {
3964
- const result = await inputSession.exchange([...iterRows(batch)]);
3965
- if (result.length > 0)
3966
- yield batchFromRows(result, outputSchema);
4132
+ for await (const rows of exchangeContinued(inputSession, opts.functionName, batch)) {
4133
+ yield batchFromRows(rows, outputSchema);
4134
+ }
3967
4135
  }
3968
4136
  } finally {
3969
4137
  inputSession.close();
@@ -4075,23 +4243,7 @@ class VgiClient {
4075
4243
  if (!result)
4076
4244
  throw new VgiClientError("catalog_contents returned null");
4077
4245
  const response = decodeCatalogContentsResponse(toUint8Array(result.result));
4078
- const schemas = response.schemas.map((c) => {
4079
- const schema = decodeSchemaInfo(c.schema);
4080
- if (JSON.stringify(c.path) !== JSON.stringify(schema.path)) {
4081
- throw new VgiClientError(`catalog_contents: SchemaContents.path ${JSON.stringify(c.path)} != SchemaInfo.path ${JSON.stringify(schema.path)}`);
4082
- }
4083
- return {
4084
- schema,
4085
- tables: c.tables.map(decodeTableInfo),
4086
- views: c.views.map(decodeViewInfo),
4087
- scalar_functions: c.scalar_functions.map(decodeFunctionInfo),
4088
- aggregate_functions: c.aggregate_functions.map(decodeFunctionInfo),
4089
- table_functions: c.table_functions.map(decodeFunctionInfo),
4090
- scalar_macros: c.scalar_macros.map(decodeMacroInfo),
4091
- table_macros: c.table_macros.map(decodeMacroInfo),
4092
- indexes: c.indexes.map(decodeIndexInfo)
4093
- };
4094
- });
4246
+ const schemas = decodeCatalogStreams(response, ifNoneMatch);
4095
4247
  return {
4096
4248
  catalog_version: Number(response.catalog_version ?? 0),
4097
4249
  etag: response.etag ?? null,
@@ -4764,4 +4916,4 @@ export {
4764
4916
  typeSignature
4765
4917
  };
4766
4918
 
4767
- //# debugId=586BBE791F5462D664756E2164756E21
4919
+ //# debugId=8E373AB802AEADEE64756E2164756E21