@quereus/quereus 4.9.0 → 4.11.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 (190) hide show
  1. package/dist/src/core/database.d.ts.map +1 -1
  2. package/dist/src/core/database.js +19 -4
  3. package/dist/src/core/database.js.map +1 -1
  4. package/dist/src/core/statement.d.ts.map +1 -1
  5. package/dist/src/core/statement.js +74 -15
  6. package/dist/src/core/statement.js.map +1 -1
  7. package/dist/src/func/builtins/aggregate.d.ts.map +1 -1
  8. package/dist/src/func/builtins/aggregate.js +85 -33
  9. package/dist/src/func/builtins/aggregate.js.map +1 -1
  10. package/dist/src/func/builtins/explain.d.ts.map +1 -1
  11. package/dist/src/func/builtins/explain.js +9 -2
  12. package/dist/src/func/builtins/explain.js.map +1 -1
  13. package/dist/src/func/builtins/scalar.d.ts.map +1 -1
  14. package/dist/src/func/builtins/scalar.js +4 -2
  15. package/dist/src/func/builtins/scalar.js.map +1 -1
  16. package/dist/src/func/registration.d.ts +6 -0
  17. package/dist/src/func/registration.d.ts.map +1 -1
  18. package/dist/src/func/registration.js +1 -0
  19. package/dist/src/func/registration.js.map +1 -1
  20. package/dist/src/index.d.ts +1 -0
  21. package/dist/src/index.d.ts.map +1 -1
  22. package/dist/src/index.js +6 -0
  23. package/dist/src/index.js.map +1 -1
  24. package/dist/src/planner/building/constraint-builder.d.ts +3 -2
  25. package/dist/src/planner/building/constraint-builder.d.ts.map +1 -1
  26. package/dist/src/planner/building/constraint-builder.js +15 -24
  27. package/dist/src/planner/building/constraint-builder.js.map +1 -1
  28. package/dist/src/planner/building/delete.d.ts.map +1 -1
  29. package/dist/src/planner/building/delete.js +7 -24
  30. package/dist/src/planner/building/delete.js.map +1 -1
  31. package/dist/src/planner/building/foreign-key-builder.d.ts +3 -2
  32. package/dist/src/planner/building/foreign-key-builder.d.ts.map +1 -1
  33. package/dist/src/planner/building/foreign-key-builder.js +13 -17
  34. package/dist/src/planner/building/foreign-key-builder.js.map +1 -1
  35. package/dist/src/planner/building/insert.d.ts.map +1 -1
  36. package/dist/src/planner/building/insert.js +16 -32
  37. package/dist/src/planner/building/insert.js.map +1 -1
  38. package/dist/src/planner/building/mutation-context.d.ts +63 -0
  39. package/dist/src/planner/building/mutation-context.d.ts.map +1 -0
  40. package/dist/src/planner/building/mutation-context.js +126 -0
  41. package/dist/src/planner/building/mutation-context.js.map +1 -0
  42. package/dist/src/planner/building/update.d.ts.map +1 -1
  43. package/dist/src/planner/building/update.js +7 -24
  44. package/dist/src/planner/building/update.js.map +1 -1
  45. package/dist/src/planner/nodes/scalar.d.ts.map +1 -1
  46. package/dist/src/planner/nodes/scalar.js +13 -1
  47. package/dist/src/planner/nodes/scalar.js.map +1 -1
  48. package/dist/src/runtime/emission-context.d.ts +14 -1
  49. package/dist/src/runtime/emission-context.d.ts.map +1 -1
  50. package/dist/src/runtime/emission-context.js +17 -5
  51. package/dist/src/runtime/emission-context.js.map +1 -1
  52. package/dist/src/runtime/emit/aggregate-setup.d.ts +44 -8
  53. package/dist/src/runtime/emit/aggregate-setup.d.ts.map +1 -1
  54. package/dist/src/runtime/emit/aggregate-setup.js +79 -15
  55. package/dist/src/runtime/emit/aggregate-setup.js.map +1 -1
  56. package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
  57. package/dist/src/runtime/emit/aggregate.js +21 -106
  58. package/dist/src/runtime/emit/aggregate.js.map +1 -1
  59. package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
  60. package/dist/src/runtime/emit/alter-table.js +11 -2
  61. package/dist/src/runtime/emit/alter-table.js.map +1 -1
  62. package/dist/src/runtime/emit/asof-scan.js +1 -1
  63. package/dist/src/runtime/emit/asof-scan.js.map +1 -1
  64. package/dist/src/runtime/emit/between.d.ts +2 -0
  65. package/dist/src/runtime/emit/between.d.ts.map +1 -1
  66. package/dist/src/runtime/emit/between.js +7 -8
  67. package/dist/src/runtime/emit/between.js.map +1 -1
  68. package/dist/src/runtime/emit/binary.d.ts +27 -5
  69. package/dist/src/runtime/emit/binary.d.ts.map +1 -1
  70. package/dist/src/runtime/emit/binary.js +266 -177
  71. package/dist/src/runtime/emit/binary.js.map +1 -1
  72. package/dist/src/runtime/emit/case.d.ts +34 -0
  73. package/dist/src/runtime/emit/case.d.ts.map +1 -1
  74. package/dist/src/runtime/emit/case.js +18 -11
  75. package/dist/src/runtime/emit/case.js.map +1 -1
  76. package/dist/src/runtime/emit/cast.d.ts +2 -0
  77. package/dist/src/runtime/emit/cast.d.ts.map +1 -1
  78. package/dist/src/runtime/emit/cast.js +7 -5
  79. package/dist/src/runtime/emit/cast.js.map +1 -1
  80. package/dist/src/runtime/emit/column-reference.d.ts +3 -1
  81. package/dist/src/runtime/emit/column-reference.d.ts.map +1 -1
  82. package/dist/src/runtime/emit/column-reference.js +6 -2
  83. package/dist/src/runtime/emit/column-reference.js.map +1 -1
  84. package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
  85. package/dist/src/runtime/emit/constraint-check.js +17 -7
  86. package/dist/src/runtime/emit/constraint-check.js.map +1 -1
  87. package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
  88. package/dist/src/runtime/emit/dml-executor.js +26 -1
  89. package/dist/src/runtime/emit/dml-executor.js.map +1 -1
  90. package/dist/src/runtime/emit/filter.d.ts +1 -1
  91. package/dist/src/runtime/emit/filter.js +1 -1
  92. package/dist/src/runtime/emit/hash-aggregate.d.ts.map +1 -1
  93. package/dist/src/runtime/emit/hash-aggregate.js +18 -88
  94. package/dist/src/runtime/emit/hash-aggregate.js.map +1 -1
  95. package/dist/src/runtime/emit/literal.d.ts +14 -1
  96. package/dist/src/runtime/emit/literal.d.ts.map +1 -1
  97. package/dist/src/runtime/emit/literal.js +33 -7
  98. package/dist/src/runtime/emit/literal.js.map +1 -1
  99. package/dist/src/runtime/emit/materialized-view-helpers.d.ts +7 -1
  100. package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
  101. package/dist/src/runtime/emit/materialized-view-helpers.js +121 -32
  102. package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
  103. package/dist/src/runtime/emit/parameter.d.ts +3 -1
  104. package/dist/src/runtime/emit/parameter.d.ts.map +1 -1
  105. package/dist/src/runtime/emit/parameter.js +7 -2
  106. package/dist/src/runtime/emit/parameter.js.map +1 -1
  107. package/dist/src/runtime/emit/scalar-function.d.ts +29 -1
  108. package/dist/src/runtime/emit/scalar-function.d.ts.map +1 -1
  109. package/dist/src/runtime/emit/scalar-function.js +66 -16
  110. package/dist/src/runtime/emit/scalar-function.js.map +1 -1
  111. package/dist/src/runtime/emit/scalar-op.d.ts +63 -0
  112. package/dist/src/runtime/emit/scalar-op.d.ts.map +1 -0
  113. package/dist/src/runtime/emit/scalar-op.js +37 -0
  114. package/dist/src/runtime/emit/scalar-op.js.map +1 -0
  115. package/dist/src/runtime/emit/scan.d.ts.map +1 -1
  116. package/dist/src/runtime/emit/scan.js +19 -1
  117. package/dist/src/runtime/emit/scan.js.map +1 -1
  118. package/dist/src/runtime/emit/temporal-arithmetic.d.ts +18 -8
  119. package/dist/src/runtime/emit/temporal-arithmetic.d.ts.map +1 -1
  120. package/dist/src/runtime/emit/temporal-arithmetic.js +29 -311
  121. package/dist/src/runtime/emit/temporal-arithmetic.js.map +1 -1
  122. package/dist/src/runtime/emit/unary.d.ts +2 -0
  123. package/dist/src/runtime/emit/unary.d.ts.map +1 -1
  124. package/dist/src/runtime/emit/unary.js +125 -53
  125. package/dist/src/runtime/emit/unary.js.map +1 -1
  126. package/dist/src/runtime/emitters.d.ts +22 -0
  127. package/dist/src/runtime/emitters.d.ts.map +1 -1
  128. package/dist/src/runtime/emitters.js +29 -0
  129. package/dist/src/runtime/emitters.js.map +1 -1
  130. package/dist/src/runtime/scalar-fusion.d.ts +47 -0
  131. package/dist/src/runtime/scalar-fusion.d.ts.map +1 -0
  132. package/dist/src/runtime/scalar-fusion.js +275 -0
  133. package/dist/src/runtime/scalar-fusion.js.map +1 -0
  134. package/dist/src/runtime/strict-flags.d.ts +9 -0
  135. package/dist/src/runtime/strict-flags.d.ts.map +1 -1
  136. package/dist/src/runtime/strict-flags.js +9 -0
  137. package/dist/src/runtime/strict-flags.js.map +1 -1
  138. package/dist/src/runtime/strict-fork.js +2 -2
  139. package/dist/src/runtime/strict-fork.js.map +1 -1
  140. package/dist/src/runtime/strict-representation.d.ts +78 -0
  141. package/dist/src/runtime/strict-representation.d.ts.map +1 -0
  142. package/dist/src/runtime/strict-representation.js +159 -0
  143. package/dist/src/runtime/strict-representation.js.map +1 -0
  144. package/dist/src/schema/catalog.d.ts +25 -2
  145. package/dist/src/schema/catalog.d.ts.map +1 -1
  146. package/dist/src/schema/catalog.js +35 -2
  147. package/dist/src/schema/catalog.js.map +1 -1
  148. package/dist/src/schema/constraint-builder.d.ts +15 -2
  149. package/dist/src/schema/constraint-builder.d.ts.map +1 -1
  150. package/dist/src/schema/constraint-builder.js +21 -5
  151. package/dist/src/schema/constraint-builder.js.map +1 -1
  152. package/dist/src/schema/function.d.ts +15 -0
  153. package/dist/src/schema/function.d.ts.map +1 -1
  154. package/dist/src/schema/function.js.map +1 -1
  155. package/dist/src/schema/manager.d.ts +13 -0
  156. package/dist/src/schema/manager.d.ts.map +1 -1
  157. package/dist/src/schema/manager.js +44 -11
  158. package/dist/src/schema/manager.js.map +1 -1
  159. package/dist/src/schema/table.d.ts +43 -0
  160. package/dist/src/schema/table.d.ts.map +1 -1
  161. package/dist/src/schema/table.js +80 -0
  162. package/dist/src/schema/table.js.map +1 -1
  163. package/dist/src/types/builtin-types.d.ts.map +1 -1
  164. package/dist/src/types/builtin-types.js +17 -8
  165. package/dist/src/types/builtin-types.js.map +1 -1
  166. package/dist/src/types/temporal-ops.d.ts +119 -0
  167. package/dist/src/types/temporal-ops.d.ts.map +1 -0
  168. package/dist/src/types/temporal-ops.js +348 -0
  169. package/dist/src/types/temporal-ops.js.map +1 -0
  170. package/dist/src/types/temporal-types.d.ts.map +1 -1
  171. package/dist/src/types/temporal-types.js +8 -3
  172. package/dist/src/types/temporal-types.js.map +1 -1
  173. package/dist/src/util/coercion.d.ts +22 -7
  174. package/dist/src/util/coercion.d.ts.map +1 -1
  175. package/dist/src/util/coercion.js +28 -15
  176. package/dist/src/util/coercion.js.map +1 -1
  177. package/dist/src/util/comparison.d.ts +25 -0
  178. package/dist/src/util/comparison.d.ts.map +1 -1
  179. package/dist/src/util/comparison.js +25 -0
  180. package/dist/src/util/comparison.js.map +1 -1
  181. package/dist/src/util/key-tuple-codec.d.ts +12 -3
  182. package/dist/src/util/key-tuple-codec.d.ts.map +1 -1
  183. package/dist/src/util/key-tuple-codec.js.map +1 -1
  184. package/dist/src/util/numeric-canonical.d.ts +26 -0
  185. package/dist/src/util/numeric-canonical.d.ts.map +1 -0
  186. package/dist/src/util/numeric-canonical.js +66 -0
  187. package/dist/src/util/numeric-canonical.js.map +1 -0
  188. package/dist/src/vtab/module.d.ts +25 -0
  189. package/dist/src/vtab/module.d.ts.map +1 -1
  190. package/package.json +4 -3
@@ -1,9 +1,37 @@
1
1
  import type { ScalarFunctionCallNode } from '../../planner/nodes/function.js';
2
- import type { Instruction } from '../types.js';
2
+ import type { Instruction, RuntimeContext } from '../types.js';
3
+ import { type MaybePromise, type SqlValue } from '../../common/types.js';
3
4
  import type { EmissionContext } from '../emission-context.js';
5
+ /**
6
+ * The per-call body of a scalar function call: its emit-time arity assert, its
7
+ * implementation-error wrapping (carrying the call's source location) and its
8
+ * `REPR_STRICT` return-type check, all resolved once here rather than per row.
9
+ *
10
+ * Two consumers read this, exactly as {@link import('./scalar-op.js').ScalarOpSpec} has
11
+ * two: {@link emitScalarFunctionCallDefault} hands it to the scheduler as an
12
+ * `Instruction.run`, and the scalar-fusion compiler (`runtime/scalar-fusion.ts`)
13
+ * composes it directly into a fused closure. Keeping one copy is what stops a fused
14
+ * call and an instruction call from disagreeing on error text or evaluation counts.
15
+ *
16
+ * The return type is `MaybePromise<SqlValue>` because a registered implementation may
17
+ * be async — the scheduler resolves that, while fusion admits only bodies it has
18
+ * *proven* synchronous and guards the remainder. The body is variadic (a `ScalarFunc`
19
+ * is `(...args: SqlValue[])`), which is why it stays off `ScalarOpSpec`, whose
20
+ * `assertSpecArity` requires one declared parameter per operand.
21
+ *
22
+ * Assumes `plan.functionSchema` has already been validated as a scalar function schema
23
+ * by the caller (the entry point {@link emitScalarFunctionCall} checks it before
24
+ * dispatching here directly or via a `customEmitter`'s `defaultEmit`; the fusion arm
25
+ * declines when the check fails and lets the unfused path report it) — this function
26
+ * does not repeat the check.
27
+ */
28
+ export declare function buildScalarFunctionRun(plan: ScalarFunctionCallNode): (rctx: RuntimeContext, ...args: SqlValue[]) => MaybePromise<SqlValue>;
4
29
  /**
5
30
  * Default emission logic for scalar function calls.
6
31
  * This is exported so custom emitters can call it if needed.
32
+ *
33
+ * A thin wrapper over {@link buildScalarFunctionRun}: it emits one instruction param
34
+ * per operand and hands the shared body to the scheduler.
7
35
  */
8
36
  export declare function emitScalarFunctionCallDefault(plan: ScalarFunctionCallNode, ctx: EmissionContext): Instruction;
9
37
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"scalar-function.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/scalar-function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAK/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,sBAAsB,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAkC7G;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,sBAAsB,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAgBtG"}
1
+ {"version":3,"file":"scalar-function.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/scalar-function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI/D,OAAO,EAAc,KAAK,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGrF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,sBAAsB,GAC1B,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,KAAK,YAAY,CAAC,QAAQ,CAAC,CA2CvE;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,sBAAsB,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAU7G;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,sBAAsB,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAgBtG"}
@@ -2,33 +2,83 @@ import { asRun } from '../types.js';
2
2
  import { emitPlanNode, createValidatedInstruction } from '../emitters.js';
3
3
  import { QuereusError } from '../../common/errors.js';
4
4
  import { StatusCode } from '../../common/types.js';
5
+ import { REPR_STRICT } from '../strict-flags.js';
6
+ import { assertConformsToType } from '../strict-representation.js';
5
7
  import { isScalarFunctionSchema } from '../../schema/function.js';
6
8
  /**
7
- * Default emission logic for scalar function calls.
8
- * This is exported so custom emitters can call it if needed.
9
+ * The per-call body of a scalar function call: its emit-time arity assert, its
10
+ * implementation-error wrapping (carrying the call's source location) and its
11
+ * `REPR_STRICT` return-type check, all resolved once here rather than per row.
12
+ *
13
+ * Two consumers read this, exactly as {@link import('./scalar-op.js').ScalarOpSpec} has
14
+ * two: {@link emitScalarFunctionCallDefault} hands it to the scheduler as an
15
+ * `Instruction.run`, and the scalar-fusion compiler (`runtime/scalar-fusion.ts`)
16
+ * composes it directly into a fused closure. Keeping one copy is what stops a fused
17
+ * call and an instruction call from disagreeing on error text or evaluation counts.
18
+ *
19
+ * The return type is `MaybePromise<SqlValue>` because a registered implementation may
20
+ * be async — the scheduler resolves that, while fusion admits only bodies it has
21
+ * *proven* synchronous and guards the remainder. The body is variadic (a `ScalarFunc`
22
+ * is `(...args: SqlValue[])`), which is why it stays off `ScalarOpSpec`, whose
23
+ * `assertSpecArity` requires one declared parameter per operand.
24
+ *
25
+ * Assumes `plan.functionSchema` has already been validated as a scalar function schema
26
+ * by the caller (the entry point {@link emitScalarFunctionCall} checks it before
27
+ * dispatching here directly or via a `customEmitter`'s `defaultEmit`; the fusion arm
28
+ * declines when the check fails and lets the unfused path report it) — this function
29
+ * does not repeat the check.
9
30
  */
10
- export function emitScalarFunctionCallDefault(plan, ctx) {
31
+ export function buildScalarFunctionRun(plan) {
11
32
  const functionName = plan.expression.name.toLowerCase();
12
- const functionSchema = plan.functionSchema;
13
- // Validate that it's a scalar function
14
- if (!isScalarFunctionSchema(functionSchema)) {
15
- throw new QuereusError(`Function ${functionName} is not a scalar function`, StatusCode.ERROR);
33
+ const scalarFunction = plan.functionSchema;
34
+ // Arity is a plan-time fact: the planner resolved this schema by arity, and both
35
+ // consumers evaluate exactly `plan.operands` — so a mismatch here can only be an
36
+ // emitter bug, not a per-call condition. Assert once at emit time instead of
37
+ // re-checking every row.
38
+ if (scalarFunction.numArgs >= 0 && plan.operands.length !== scalarFunction.numArgs) {
39
+ throw new QuereusError(`Internal error: function ${functionName} plan has ${plan.operands.length} operands, expected ${scalarFunction.numArgs}`, StatusCode.INTERNAL);
16
40
  }
17
- function run(_rctx, ...args) {
18
- // Use the pre-resolved function schema from the plan node
19
- const scalarFunction = functionSchema;
20
- // Validate argument count
21
- if (scalarFunction.numArgs >= 0 && args.length !== scalarFunction.numArgs) {
22
- throw new QuereusError(`Function ${functionName} called with ${args.length} arguments, expected ${scalarFunction.numArgs}`, StatusCode.ERROR);
23
- }
41
+ // QUEREUS_REPR_STRICT seam: the value a function RETURNS, checked against its
42
+ // schema's declared return type. A UDF's output is one of the two boundaries the
43
+ // engine deliberately does not coerce (docs/types.md § Physical representation), so
44
+ // this is where a drifting implementation is caught. Resolved only when the flag is
45
+ // on — a normal emit does no type lookup for it.
46
+ const reprReturnType = REPR_STRICT ? scalarFunction.returnType.logicalType : undefined;
47
+ const reprWhere = REPR_STRICT
48
+ ? `the return value of function ${functionName}(${plan.operands.length})`
49
+ : '';
50
+ return function run(_rctx, ...args) {
51
+ let result;
24
52
  try {
25
- return scalarFunction.implementation(...args);
53
+ result = scalarFunction.implementation(...args);
26
54
  }
27
55
  catch (error) {
28
56
  const message = error instanceof Error ? error.message : String(error);
29
57
  throw new QuereusError(`Function ${functionName} failed: ${message}`, StatusCode.ERROR, error instanceof Error ? error : undefined, plan.expression.loc?.start.line, plan.expression.loc?.start.column);
30
58
  }
31
- }
59
+ // Checked OUTSIDE the try on purpose: inside, a representation violation would be
60
+ // re-reported as "Function <name> failed", hiding the seam its message names.
61
+ if (REPR_STRICT) {
62
+ if (result instanceof Promise) {
63
+ return result.then(value => {
64
+ assertConformsToType(value, reprReturnType, reprWhere);
65
+ return value;
66
+ });
67
+ }
68
+ assertConformsToType(result, reprReturnType, reprWhere);
69
+ }
70
+ return result;
71
+ };
72
+ }
73
+ /**
74
+ * Default emission logic for scalar function calls.
75
+ * This is exported so custom emitters can call it if needed.
76
+ *
77
+ * A thin wrapper over {@link buildScalarFunctionRun}: it emits one instruction param
78
+ * per operand and hands the shared body to the scheduler.
79
+ */
80
+ export function emitScalarFunctionCallDefault(plan, ctx) {
81
+ const run = buildScalarFunctionRun(plan);
32
82
  const operandExprs = plan.operands.map(operand => emitPlanNode(operand, ctx));
33
83
  return createValidatedInstruction(operandExprs, asRun(run), ctx, `${plan.expression.name}(${plan.operands.length})`);
34
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scalar-function.js","sourceRoot":"","sources":["../../../../src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C,IAA4B,EAAE,GAAoB;IAC/F,MAAM,GAAG,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAE9E,OAAO,0BAA0B,CAChC,YAAY,EACZ,KAAK,CAAC,GAAG,CAAC,EACV,GAAG,EACH,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAClD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAA4B,EAAE,GAAoB;IACxF,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;IAE3C,uCAAuC;IACvC,IAAI,CAAC,sBAAsB,CAAC,cAAc,CAAC,EAAE,CAAC;QAC7C,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACxD,MAAM,IAAI,YAAY,CAAC,YAAY,YAAY,2BAA2B,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAC/F,CAAC;IAED,yCAAyC;IACzC,IAAI,cAAc,CAAC,aAAa,EAAE,CAAC;QAClC,OAAO,cAAc,CAAC,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,6BAA6B,CAAC,CAAC;IAC/E,CAAC;IAED,6BAA6B;IAC7B,OAAO,6BAA6B,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { type SqlValue } from '../../common/types.js';
2
+ import type { Instruction, RuntimeContext } from '../types.js';
3
+ import type { ScalarPlanNode } from '../../planner/nodes/plan-node.js';
4
+ import type { EmissionContext } from '../emission-context.js';
5
+ /**
6
+ * The synchronous body of one scalar operation: it receives the runtime context plus
7
+ * one already-evaluated value per declared operand, and returns a plain value.
8
+ *
9
+ * A fixed-arity body (`(ctx, v1: SqlValue, v2: SqlValue) => SqlValue`) assigns to this
10
+ * rest signature directly — no `asRun`-style cast is needed, and every declared param
11
+ * and the return stay checked against `SqlValue`.
12
+ *
13
+ * What a rest signature cannot check is that the body's arity matches `operands.length`
14
+ * — a spec declaring two operands with a body taking one compiles, and the extra value
15
+ * is silently dropped at runtime. `buildLikeOpSpec` varies both together between its two
16
+ * paths, so the pairing is not statically detectable in general; {@link assertSpecArity}
17
+ * checks it at emit time instead.
18
+ *
19
+ * Deliberately NOT widened to `OutputValue`. A spec body that could return a Promise
20
+ * would be unusable by the fusion consumer described on {@link ScalarOpSpec}, so an
21
+ * emitter whose body is genuinely async keeps building its own `Instruction` instead
22
+ * of being forced through here.
23
+ */
24
+ export type ScalarOpRun = (ctx: RuntimeContext, ...args: SqlValue[]) => SqlValue;
25
+ /**
26
+ * Emit-time description of one scalar node's evaluation: the operand plan nodes whose
27
+ * values it consumes, and the synchronous body that combines them.
28
+ *
29
+ * Two consumers read this. {@link emitScalarOp} emits each operand as an `Instruction`
30
+ * param and hands the body to the scheduler as the instruction's `run` — today's
31
+ * behavior. The scalar-fusion compiler instead composes each operand's own fused
32
+ * closure into a direct call, with no scheduler and no per-row allocation. Both must
33
+ * agree exactly, which is why the body lives here and not inside either one.
34
+ *
35
+ * `operands` is the list that becomes `Instruction.params` — NOT the plan node's
36
+ * children. `buildLikeOpSpec`'s constant-pattern fast path bakes its right operand into the
37
+ * closure and declares one operand; the spec describes what is actually evaluated.
38
+ */
39
+ export interface ScalarOpSpec {
40
+ readonly operands: readonly ScalarPlanNode[];
41
+ readonly run: ScalarOpRun;
42
+ readonly note: string;
43
+ }
44
+ /**
45
+ * Emit-time guard that a spec's body takes exactly one parameter per declared operand,
46
+ * plus the leading context. A mismatch is an emitter bug, not a per-row condition, and
47
+ * it is otherwise silent: the scheduler spreads `params.length` args into a body that
48
+ * ignores the tail, and a fused call would drop the same values.
49
+ *
50
+ * NOTE: a body with a rest signature (`(ctx, ...args)`) or a defaulted parameter reports
51
+ * a `Function.length` that stops short, so it trips this. No spec is variadic today —
52
+ * `buildScalarFunctionRun` (emit/scalar-function.ts), the one variadic scalar body,
53
+ * deliberately stays off `ScalarOpSpec` and is composed by the fusion compiler without
54
+ * this guard. A future variadic spec needs an explicit opt-out here, not a weakened
55
+ * check for everyone.
56
+ *
57
+ * Exported for the scalar-fusion compiler (runtime/scalar-fusion.ts), which composes
58
+ * spec bodies without going through {@link emitScalarOp} and needs the same guard.
59
+ */
60
+ export declare function assertSpecArity(spec: ScalarOpSpec): void;
61
+ /** Emit a spec as the `Instruction` its emitter returned before this factoring. */
62
+ export declare function emitScalarOp(spec: ScalarOpSpec, ctx: EmissionContext): Instruction;
63
+ //# sourceMappingURL=scalar-op.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar-op.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/scalar-op.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,KAAK,QAAQ,CAAC;AAEjF;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IAC7C,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAQxD;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAOlF"}
@@ -0,0 +1,37 @@
1
+ import { StatusCode } from '../../common/types.js';
2
+ import { QuereusError } from '../../common/errors.js';
3
+ import { asRun } from '../types.js';
4
+ import { emitPlanNode } from '../emitters.js';
5
+ /**
6
+ * Emit-time guard that a spec's body takes exactly one parameter per declared operand,
7
+ * plus the leading context. A mismatch is an emitter bug, not a per-row condition, and
8
+ * it is otherwise silent: the scheduler spreads `params.length` args into a body that
9
+ * ignores the tail, and a fused call would drop the same values.
10
+ *
11
+ * NOTE: a body with a rest signature (`(ctx, ...args)`) or a defaulted parameter reports
12
+ * a `Function.length` that stops short, so it trips this. No spec is variadic today —
13
+ * `buildScalarFunctionRun` (emit/scalar-function.ts), the one variadic scalar body,
14
+ * deliberately stays off `ScalarOpSpec` and is composed by the fusion compiler without
15
+ * this guard. A future variadic spec needs an explicit opt-out here, not a weakened
16
+ * check for everyone.
17
+ *
18
+ * Exported for the scalar-fusion compiler (runtime/scalar-fusion.ts), which composes
19
+ * spec bodies without going through {@link emitScalarOp} and needs the same guard.
20
+ */
21
+ export function assertSpecArity(spec) {
22
+ const expected = spec.operands.length + 1;
23
+ if (spec.run.length !== expected) {
24
+ throw new QuereusError(`Internal error: scalar op '${spec.note}' declares ${spec.operands.length} operand(s) `
25
+ + `but its body takes ${spec.run.length - 1}`, StatusCode.INTERNAL);
26
+ }
27
+ }
28
+ /** Emit a spec as the `Instruction` its emitter returned before this factoring. */
29
+ export function emitScalarOp(spec, ctx) {
30
+ assertSpecArity(spec);
31
+ return {
32
+ params: spec.operands.map(operand => emitPlanNode(operand, ctx)),
33
+ run: asRun(spec.run),
34
+ note: spec.note,
35
+ };
36
+ }
37
+ //# sourceMappingURL=scalar-op.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar-op.js","sourceRoot":"","sources":["../../../../src/runtime/emit/scalar-op.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAiB,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA4C9C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe,CAAC,IAAkB;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1C,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,IAAI,YAAY,CACrB,8BAA8B,IAAI,CAAC,IAAI,cAAc,IAAI,CAAC,QAAQ,CAAC,MAAM,cAAc;cACrF,sBAAsB,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,EAC7C,UAAU,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC;AACF,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,YAAY,CAAC,IAAkB,EAAE,GAAoB;IACpE,eAAe,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO;QACN,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAChE,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,EAAE,IAAI,CAAC,IAAI;KACf,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,aAAa,E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aAAa,EACjD,GAAG,EAAE,eAAe,EACpB,kBAAkB,CAAC,EAAE,kBAAkB,GACrC,WAAW,CAuKb"}
@@ -6,6 +6,8 @@ import { createValidatedInstruction, emitPlanNode } from "../emitters.js";
6
6
  import { disconnectVTable } from "../utils.js";
7
7
  import { buildRowDescriptor } from "../../util/row-descriptor.js";
8
8
  import { createRowSlot } from "../context-helpers.js";
9
+ import { REPR_STRICT } from "../strict-flags.js";
10
+ import { assertRowConforms, RepresentationError } from "../strict-representation.js";
9
11
  /**
10
12
  * Emits instructions for physical table access nodes (SeqScan, IndexScan, IndexSeek).
11
13
  *
@@ -33,6 +35,16 @@ export function emitSeqScan(plan, ctx, filterInfoOverride) {
33
35
  // scan site — a self-join's two scans over the same table get different keys and
34
36
  // therefore isolated instances. Mirrors the executionMemo symbol pattern.
35
37
  const scanConnectionKey = Symbol(`scan:${plan.nodeType}(${schema.name})`);
38
+ // QUEREUS_REPR_STRICT seam: rows leaving a module's `query()`, checked against the
39
+ // table's declared column types. Catches a non-conforming module (in-tree or
40
+ // third-party) at its OWN boundary rather than three layers downstream. Everything
41
+ // the check needs is built here only when the flag is on, so a normal emit allocates
42
+ // nothing on its behalf.
43
+ const reprColumnTypes = REPR_STRICT ? schema.columns.map(col => col.logicalType) : undefined;
44
+ const reprColumnNames = REPR_STRICT ? schema.columns.map(col => col.name) : undefined;
45
+ const reprWhere = REPR_STRICT
46
+ ? `module '${schema.vtabModuleName}' query() row for ${schema.schemaName}.${schema.name}`
47
+ : '';
36
48
  async function* run(runtimeCtx, ...dynamicArgs) {
37
49
  // Use the captured module info instead of doing a fresh lookup
38
50
  const capturedModuleInfo = ctx.getCapturedSchemaObject(moduleKey);
@@ -113,13 +125,19 @@ export function emitSeqScan(plan, ctx, filterInfoOverride) {
113
125
  // checkpoint — the inner scan layers (safeIterate/scanLayer) went sync,
114
126
  // so do not remove it expecting an inner checkpoint to cover the scan.
115
127
  throwIfAborted(runtimeCtx.signal);
128
+ // Synchronous and inside this loop on purpose: enabling the flag must not
129
+ // introduce a microtask hop into the scan's fast path (docs/runtime.md).
130
+ if (REPR_STRICT)
131
+ assertRowConforms(row, reprColumnTypes, reprWhere, reprColumnNames);
116
132
  rowSlot.set(row);
117
133
  yield row;
118
134
  }
119
135
  }
120
136
  catch (e) {
121
137
  // Preserve cancellation identity — don't re-wrap it as a generic query error.
122
- if (e instanceof AbortError)
138
+ // A representation violation is likewise rethrown verbatim: re-wrapping it
139
+ // would bury the seam/column/type detail its message exists to carry.
140
+ if (e instanceof AbortError || e instanceof RepresentationError)
123
141
  throw e;
124
142
  const message = e instanceof Error ? e.message : String(e);
125
143
  throw new QuereusError(`Error during query on table '${schema.name}': ${message}`, e instanceof QuereusError ? e.code : StatusCode.ERROR, e instanceof Error ? e : undefined);
@@ -1 +1 @@
1
- {"version":3,"file":"scan.js","sourceRoot":"","sources":["../../../../src/runtime/emit/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA2B,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAA8B,aAAa,EAAE,MAAM,2CAA2C,CAAC;AACtG,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAKlF,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAiBtD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAC1B,IAAiD,EACjD,GAAoB,EACpB,kBAAuC;IAEvC,+BAA+B;IAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC;IAElC,gEA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,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC/K,CAAC;gBAAS,CAAC;YACV,+DAA+D;YAC/D,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,2EAA2E;YAC3E,4EAA4E;YAC5E,wDAAwD;YACxD,IAAI,YAAY,EAAE,CAAC;gBAClB,MAAM,gBAAgB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;IACF,CAAC;IAED,qEAAqE;IACrE,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,IAAI,IAAI,YAAY,aAAa,EAAE,CAAC;QACnC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YACtC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC;IACF,CAAC;IAED,OAAO,0BAA0B,CAChC,MAAM,EACN,KAAK,CAAC,GAAG,CAAC,EACV,GAAG,EACH,GAAG,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,GAAG,CAClC,CAAC;AACH,CAAC"}
@@ -1,18 +1,16 @@
1
1
  import type { SqlValue } from "../../common/types.js";
2
- import type { Instruction } from "../types.js";
3
- import type { BinaryOpNode } from "../../planner/nodes/scalar.js";
4
- import type { EmissionContext } from "../emission-context.js";
5
2
  /**
6
3
  * Try to perform temporal arithmetic on two values.
7
4
  * Returns the result if successful, or undefined if the values are not temporal types.
8
5
  * Throws QuereusError if the operation is invalid.
6
+ *
7
+ * Which combinations exist, what each produces, and what each announces as its result
8
+ * type all live in one table (`types/temporal-ops.ts`) that the planner reads too. This
9
+ * function is the *value-sniffed* entry into that table: it derives both operand kinds
10
+ * from the runtime values, which is the defined behavior whenever the declared types
11
+ * cannot settle the case (a TEXT column holding a duration string, for instance).
9
12
  */
10
13
  export declare function tryTemporalArithmetic(operator: string, v1: SqlValue, v2: SqlValue): SqlValue | undefined;
11
- /**
12
- * Emit temporal arithmetic operations
13
- * Handles operations between temporal types (DATE, TIME, DATETIME, TIMESPAN)
14
- */
15
- export declare function emitTemporalArithmetic(plan: BinaryOpNode, ctx: EmissionContext): Instruction;
16
14
  /**
17
15
  * Attempts to perform temporal comparison. Returns undefined if not a temporal comparison.
18
16
  * This allows the caller to fall back to standard comparison logic.
@@ -24,6 +22,18 @@ export declare function emitTemporalArithmetic(plan: BinaryOpNode, ctx: Emission
24
22
  * Note: DATE, TIME, and DATETIME use ISO 8601 format which compares correctly lexicographically,
25
23
  * so they don't need special handling here.
26
24
  *
25
+ * NOTE: deliberately NOT given the emit-time specialization `buildNumericOpSpec`'s temporal
26
+ * arm got. The shapes look alike, but the economics do not:
27
+ * - the per-row cost here is one `startsWith` per operand, not four regexes — TIMESPAN is
28
+ * the only temporal type whose text order differs from its semantic order, so it is the
29
+ * only one {@link tryTemporalCompare} probes for;
30
+ * - `buildComparisonOpSpec` already bypasses this function for the hot case: two operands
31
+ * of the same semantic-ordering type take the `sharedSemanticType` path
32
+ * (`=(compare-typed)`) and never reach the generic comparison run;
33
+ * - what is left is the mixed TIMESPAN-vs-TEXT/ANY shape, where runtime sniffing is the
34
+ * defined semantics and cannot be resolved from the declared types anyway.
35
+ * Revisit only if a profile shows the generic comparison run hot on temporal operands.
36
+ *
27
37
  * @param operator The comparison operator (=, !=, <, <=, >, >=)
28
38
  * @param v1 First value
29
39
  * @param v2 Second value
@@ -1 +1 @@
1
- {"version":3,"file":"temporal-arithmetic.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/temporal-arithmetic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,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