@quereus/quereus 4.5.0 → 4.6.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 (468) hide show
  1. package/README.md +4 -3
  2. package/dist/src/core/database-events.d.ts +99 -1
  3. package/dist/src/core/database-events.d.ts.map +1 -1
  4. package/dist/src/core/database-events.js +219 -3
  5. package/dist/src/core/database-events.js.map +1 -1
  6. package/dist/src/core/database-materialized-views-plan-builders.d.ts.map +1 -1
  7. package/dist/src/core/database-materialized-views-plan-builders.js +29 -2
  8. package/dist/src/core/database-materialized-views-plan-builders.js.map +1 -1
  9. package/dist/src/core/database-transaction.d.ts +9 -0
  10. package/dist/src/core/database-transaction.d.ts.map +1 -1
  11. package/dist/src/core/database-transaction.js +9 -0
  12. package/dist/src/core/database-transaction.js.map +1 -1
  13. package/dist/src/core/database.d.ts +7 -1
  14. package/dist/src/core/database.d.ts.map +1 -1
  15. package/dist/src/core/database.js +20 -5
  16. package/dist/src/core/database.js.map +1 -1
  17. package/dist/src/func/builtins/aggregate.js +11 -11
  18. package/dist/src/func/builtins/aggregate.js.map +1 -1
  19. package/dist/src/func/builtins/builtin-window-functions.d.ts.map +1 -1
  20. package/dist/src/func/builtins/builtin-window-functions.js +15 -85
  21. package/dist/src/func/builtins/builtin-window-functions.js.map +1 -1
  22. package/dist/src/func/builtins/conversion.d.ts.map +1 -1
  23. package/dist/src/func/builtins/conversion.js +10 -9
  24. package/dist/src/func/builtins/conversion.js.map +1 -1
  25. package/dist/src/func/builtins/datetime.d.ts.map +1 -1
  26. package/dist/src/func/builtins/datetime.js +28 -10
  27. package/dist/src/func/builtins/datetime.js.map +1 -1
  28. package/dist/src/func/builtins/json.d.ts.map +1 -1
  29. package/dist/src/func/builtins/json.js +23 -17
  30. package/dist/src/func/builtins/json.js.map +1 -1
  31. package/dist/src/func/builtins/mutation.js +2 -2
  32. package/dist/src/func/builtins/mutation.js.map +1 -1
  33. package/dist/src/func/builtins/return-types.d.ts +327 -0
  34. package/dist/src/func/builtins/return-types.d.ts.map +1 -0
  35. package/dist/src/func/builtins/return-types.js +43 -0
  36. package/dist/src/func/builtins/return-types.js.map +1 -0
  37. package/dist/src/func/builtins/scalar.d.ts.map +1 -1
  38. package/dist/src/func/builtins/scalar.js +138 -71
  39. package/dist/src/func/builtins/scalar.js.map +1 -1
  40. package/dist/src/func/builtins/schema.d.ts.map +1 -1
  41. package/dist/src/func/builtins/schema.js +11 -3
  42. package/dist/src/func/builtins/schema.js.map +1 -1
  43. package/dist/src/func/builtins/string.d.ts.map +1 -1
  44. package/dist/src/func/builtins/string.js +4 -2
  45. package/dist/src/func/builtins/string.js.map +1 -1
  46. package/dist/src/func/builtins/timespan.d.ts +3 -0
  47. package/dist/src/func/builtins/timespan.d.ts.map +1 -1
  48. package/dist/src/func/builtins/timespan.js +15 -11
  49. package/dist/src/func/builtins/timespan.js.map +1 -1
  50. package/dist/src/func/registration.d.ts +35 -1
  51. package/dist/src/func/registration.d.ts.map +1 -1
  52. package/dist/src/func/registration.js +235 -41
  53. package/dist/src/func/registration.js.map +1 -1
  54. package/dist/src/index.d.ts +11 -4
  55. package/dist/src/index.d.ts.map +1 -1
  56. package/dist/src/index.js +12 -3
  57. package/dist/src/index.js.map +1 -1
  58. package/dist/src/parser/parser.d.ts +46 -0
  59. package/dist/src/parser/parser.d.ts.map +1 -1
  60. package/dist/src/parser/parser.js +160 -44
  61. package/dist/src/parser/parser.js.map +1 -1
  62. package/dist/src/planner/analysis/check-extraction.d.ts.map +1 -1
  63. package/dist/src/planner/analysis/check-extraction.js +37 -4
  64. package/dist/src/planner/analysis/check-extraction.js.map +1 -1
  65. package/dist/src/planner/analysis/comparison-collation.d.ts +20 -22
  66. package/dist/src/planner/analysis/comparison-collation.d.ts.map +1 -1
  67. package/dist/src/planner/analysis/comparison-collation.js +29 -26
  68. package/dist/src/planner/analysis/comparison-collation.js.map +1 -1
  69. package/dist/src/planner/analysis/constraint-extractor.d.ts +0 -7
  70. package/dist/src/planner/analysis/constraint-extractor.d.ts.map +1 -1
  71. package/dist/src/planner/analysis/constraint-extractor.js +59 -59
  72. package/dist/src/planner/analysis/constraint-extractor.js.map +1 -1
  73. package/dist/src/planner/building/alter-table.d.ts.map +1 -1
  74. package/dist/src/planner/building/alter-table.js +65 -27
  75. package/dist/src/planner/building/alter-table.js.map +1 -1
  76. package/dist/src/planner/building/coercion.d.ts +21 -45
  77. package/dist/src/planner/building/coercion.d.ts.map +1 -1
  78. package/dist/src/planner/building/coercion.js +42 -91
  79. package/dist/src/planner/building/coercion.js.map +1 -1
  80. package/dist/src/planner/building/expression.d.ts +17 -0
  81. package/dist/src/planner/building/expression.d.ts.map +1 -1
  82. package/dist/src/planner/building/expression.js +28 -17
  83. package/dist/src/planner/building/expression.js.map +1 -1
  84. package/dist/src/planner/building/function-call.d.ts.map +1 -1
  85. package/dist/src/planner/building/function-call.js +7 -2
  86. package/dist/src/planner/building/function-call.js.map +1 -1
  87. package/dist/src/planner/building/select-aggregates.d.ts +1 -1
  88. package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
  89. package/dist/src/planner/building/select-aggregates.js +53 -2
  90. package/dist/src/planner/building/select-aggregates.js.map +1 -1
  91. package/dist/src/planner/building/select-context.d.ts +7 -0
  92. package/dist/src/planner/building/select-context.d.ts.map +1 -1
  93. package/dist/src/planner/building/select-context.js +10 -40
  94. package/dist/src/planner/building/select-context.js.map +1 -1
  95. package/dist/src/planner/building/select.d.ts +37 -1
  96. package/dist/src/planner/building/select.d.ts.map +1 -1
  97. package/dist/src/planner/building/select.js +112 -51
  98. package/dist/src/planner/building/select.js.map +1 -1
  99. package/dist/src/planner/cost/conjunct-cost.d.ts +40 -0
  100. package/dist/src/planner/cost/conjunct-cost.d.ts.map +1 -1
  101. package/dist/src/planner/cost/conjunct-cost.js +45 -0
  102. package/dist/src/planner/cost/conjunct-cost.js.map +1 -1
  103. package/dist/src/planner/cost/index.d.ts +10 -0
  104. package/dist/src/planner/cost/index.d.ts.map +1 -1
  105. package/dist/src/planner/cost/index.js +15 -0
  106. package/dist/src/planner/cost/index.js.map +1 -1
  107. package/dist/src/planner/nodes/aggregate-node.d.ts +6 -0
  108. package/dist/src/planner/nodes/aggregate-node.d.ts.map +1 -1
  109. package/dist/src/planner/nodes/aggregate-node.js +10 -2
  110. package/dist/src/planner/nodes/aggregate-node.js.map +1 -1
  111. package/dist/src/planner/nodes/alias-node.d.ts.map +1 -1
  112. package/dist/src/planner/nodes/alias-node.js +2 -1
  113. package/dist/src/planner/nodes/alias-node.js.map +1 -1
  114. package/dist/src/planner/nodes/alter-table-node.d.ts +24 -8
  115. package/dist/src/planner/nodes/alter-table-node.d.ts.map +1 -1
  116. package/dist/src/planner/nodes/alter-table-node.js.map +1 -1
  117. package/dist/src/planner/nodes/asof-scan-node.d.ts.map +1 -1
  118. package/dist/src/planner/nodes/asof-scan-node.js +4 -1
  119. package/dist/src/planner/nodes/asof-scan-node.js.map +1 -1
  120. package/dist/src/planner/nodes/asserted-keys-node.d.ts.map +1 -1
  121. package/dist/src/planner/nodes/asserted-keys-node.js +2 -1
  122. package/dist/src/planner/nodes/asserted-keys-node.js.map +1 -1
  123. package/dist/src/planner/nodes/bloom-join-node.d.ts.map +1 -1
  124. package/dist/src/planner/nodes/bloom-join-node.js +8 -3
  125. package/dist/src/planner/nodes/bloom-join-node.js.map +1 -1
  126. package/dist/src/planner/nodes/cache-node.d.ts.map +1 -1
  127. package/dist/src/planner/nodes/cache-node.js +2 -1
  128. package/dist/src/planner/nodes/cache-node.js.map +1 -1
  129. package/dist/src/planner/nodes/distinct-node.d.ts +6 -0
  130. package/dist/src/planner/nodes/distinct-node.d.ts.map +1 -1
  131. package/dist/src/planner/nodes/distinct-node.js +10 -2
  132. package/dist/src/planner/nodes/distinct-node.js.map +1 -1
  133. package/dist/src/planner/nodes/eager-prefetch-node.d.ts.map +1 -1
  134. package/dist/src/planner/nodes/eager-prefetch-node.js +2 -1
  135. package/dist/src/planner/nodes/eager-prefetch-node.js.map +1 -1
  136. package/dist/src/planner/nodes/fanout-lookup-join-node.d.ts +5 -0
  137. package/dist/src/planner/nodes/fanout-lookup-join-node.d.ts.map +1 -1
  138. package/dist/src/planner/nodes/fanout-lookup-join-node.js +13 -6
  139. package/dist/src/planner/nodes/fanout-lookup-join-node.js.map +1 -1
  140. package/dist/src/planner/nodes/filter.d.ts.map +1 -1
  141. package/dist/src/planner/nodes/filter.js +12 -5
  142. package/dist/src/planner/nodes/filter.js.map +1 -1
  143. package/dist/src/planner/nodes/hash-aggregate.d.ts +6 -0
  144. package/dist/src/planner/nodes/hash-aggregate.d.ts.map +1 -1
  145. package/dist/src/planner/nodes/hash-aggregate.js +10 -2
  146. package/dist/src/planner/nodes/hash-aggregate.js.map +1 -1
  147. package/dist/src/planner/nodes/join-node.d.ts +20 -1
  148. package/dist/src/planner/nodes/join-node.d.ts.map +1 -1
  149. package/dist/src/planner/nodes/join-node.js +30 -9
  150. package/dist/src/planner/nodes/join-node.js.map +1 -1
  151. package/dist/src/planner/nodes/join-utils.d.ts +21 -0
  152. package/dist/src/planner/nodes/join-utils.d.ts.map +1 -1
  153. package/dist/src/planner/nodes/join-utils.js +26 -0
  154. package/dist/src/planner/nodes/join-utils.js.map +1 -1
  155. package/dist/src/planner/nodes/key-set-semi-join-node.d.ts.map +1 -1
  156. package/dist/src/planner/nodes/key-set-semi-join-node.js +5 -1
  157. package/dist/src/planner/nodes/key-set-semi-join-node.js.map +1 -1
  158. package/dist/src/planner/nodes/lens-auxiliary-access-node.d.ts.map +1 -1
  159. package/dist/src/planner/nodes/lens-auxiliary-access-node.js +2 -1
  160. package/dist/src/planner/nodes/lens-auxiliary-access-node.js.map +1 -1
  161. package/dist/src/planner/nodes/limit-offset.d.ts +6 -0
  162. package/dist/src/planner/nodes/limit-offset.d.ts.map +1 -1
  163. package/dist/src/planner/nodes/limit-offset.js +10 -2
  164. package/dist/src/planner/nodes/limit-offset.js.map +1 -1
  165. package/dist/src/planner/nodes/merge-join-node.d.ts.map +1 -1
  166. package/dist/src/planner/nodes/merge-join-node.js +8 -3
  167. package/dist/src/planner/nodes/merge-join-node.js.map +1 -1
  168. package/dist/src/planner/nodes/ordinal-slice-node.d.ts +5 -0
  169. package/dist/src/planner/nodes/ordinal-slice-node.d.ts.map +1 -1
  170. package/dist/src/planner/nodes/ordinal-slice-node.js +9 -2
  171. package/dist/src/planner/nodes/ordinal-slice-node.js.map +1 -1
  172. package/dist/src/planner/nodes/plan-node.d.ts +24 -0
  173. package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
  174. package/dist/src/planner/nodes/plan-node.js.map +1 -1
  175. package/dist/src/planner/nodes/project-node.d.ts.map +1 -1
  176. package/dist/src/planner/nodes/project-node.js +2 -1
  177. package/dist/src/planner/nodes/project-node.js.map +1 -1
  178. package/dist/src/planner/nodes/reference.d.ts.map +1 -1
  179. package/dist/src/planner/nodes/reference.js +3 -2
  180. package/dist/src/planner/nodes/reference.js.map +1 -1
  181. package/dist/src/planner/nodes/retrieve-node.d.ts.map +1 -1
  182. package/dist/src/planner/nodes/retrieve-node.js +2 -1
  183. package/dist/src/planner/nodes/retrieve-node.js.map +1 -1
  184. package/dist/src/planner/nodes/scalar.d.ts.map +1 -1
  185. package/dist/src/planner/nodes/scalar.js +5 -18
  186. package/dist/src/planner/nodes/scalar.js.map +1 -1
  187. package/dist/src/planner/nodes/sort.d.ts.map +1 -1
  188. package/dist/src/planner/nodes/sort.js +3 -1
  189. package/dist/src/planner/nodes/sort.js.map +1 -1
  190. package/dist/src/planner/nodes/stream-aggregate.d.ts +6 -0
  191. package/dist/src/planner/nodes/stream-aggregate.d.ts.map +1 -1
  192. package/dist/src/planner/nodes/stream-aggregate.js +10 -2
  193. package/dist/src/planner/nodes/stream-aggregate.js.map +1 -1
  194. package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -1
  195. package/dist/src/planner/nodes/table-access-nodes.js +5 -0
  196. package/dist/src/planner/nodes/table-access-nodes.js.map +1 -1
  197. package/dist/src/planner/nodes/window-function.d.ts.map +1 -1
  198. package/dist/src/planner/nodes/window-function.js +8 -0
  199. package/dist/src/planner/nodes/window-function.js.map +1 -1
  200. package/dist/src/planner/nodes/window-node.d.ts +1 -1
  201. package/dist/src/planner/nodes/window-node.d.ts.map +1 -1
  202. package/dist/src/planner/nodes/window-node.js +3 -1
  203. package/dist/src/planner/nodes/window-node.js.map +1 -1
  204. package/dist/src/planner/optimizer.d.ts +9 -1
  205. package/dist/src/planner/optimizer.d.ts.map +1 -1
  206. package/dist/src/planner/optimizer.js +77 -6
  207. package/dist/src/planner/optimizer.js.map +1 -1
  208. package/dist/src/planner/rules/access/rule-key-set-seek.d.ts.map +1 -1
  209. package/dist/src/planner/rules/access/rule-key-set-seek.js +3 -68
  210. package/dist/src/planner/rules/access/rule-key-set-seek.js.map +1 -1
  211. package/dist/src/planner/rules/access/rule-select-access-path.d.ts +19 -0
  212. package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
  213. package/dist/src/planner/rules/access/rule-select-access-path.js +24 -3
  214. package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
  215. package/dist/src/planner/rules/cache/rule-cte-optimization.d.ts.map +1 -1
  216. package/dist/src/planner/rules/cache/rule-cte-optimization.js +9 -0
  217. package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +1 -1
  218. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.d.ts.map +1 -1
  219. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js +6 -4
  220. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js.map +1 -1
  221. package/dist/src/planner/rules/join/equi-pair-extractor.d.ts +5 -31
  222. package/dist/src/planner/rules/join/equi-pair-extractor.d.ts.map +1 -1
  223. package/dist/src/planner/rules/join/equi-pair-extractor.js +4 -44
  224. package/dist/src/planner/rules/join/equi-pair-extractor.js.map +1 -1
  225. package/dist/src/planner/rules/join/index-nested-loop.d.ts +49 -0
  226. package/dist/src/planner/rules/join/index-nested-loop.d.ts.map +1 -0
  227. package/dist/src/planner/rules/join/index-nested-loop.js +285 -0
  228. package/dist/src/planner/rules/join/index-nested-loop.js.map +1 -0
  229. package/dist/src/planner/rules/join/rule-fanout-batched-outer.js +8 -8
  230. package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts +10 -4
  231. package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts.map +1 -1
  232. package/dist/src/planner/rules/join/rule-join-physical-selection.js +83 -27
  233. package/dist/src/planner/rules/join/rule-join-physical-selection.js.map +1 -1
  234. package/dist/src/planner/rules/join/rule-monotonic-merge-join.js +4 -4
  235. package/dist/src/planner/rules/join/rule-monotonic-merge-join.js.map +1 -1
  236. package/dist/src/planner/rules/predicate/rule-filter-conjunct-ordering.d.ts +21 -8
  237. package/dist/src/planner/rules/predicate/rule-filter-conjunct-ordering.d.ts.map +1 -1
  238. package/dist/src/planner/rules/predicate/rule-filter-conjunct-ordering.js +70 -14
  239. package/dist/src/planner/rules/predicate/rule-filter-conjunct-ordering.js.map +1 -1
  240. package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts +42 -17
  241. package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts.map +1 -1
  242. package/dist/src/planner/rules/predicate/rule-filter-selectivity.js +84 -154
  243. package/dist/src/planner/rules/predicate/rule-filter-selectivity.js.map +1 -1
  244. package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.d.ts +73 -0
  245. package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.d.ts.map +1 -0
  246. package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.js +205 -0
  247. package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.js.map +1 -0
  248. package/dist/src/planner/rules/predicate/rule-predicate-inference-equivalence.d.ts +14 -11
  249. package/dist/src/planner/rules/predicate/rule-predicate-inference-equivalence.d.ts.map +1 -1
  250. package/dist/src/planner/rules/predicate/rule-predicate-inference-equivalence.js +21 -85
  251. package/dist/src/planner/rules/predicate/rule-predicate-inference-equivalence.js.map +1 -1
  252. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts +7 -1
  253. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts.map +1 -1
  254. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js +7 -1
  255. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js.map +1 -1
  256. package/dist/src/planner/rules/shared/access-leaf.d.ts +39 -0
  257. package/dist/src/planner/rules/shared/access-leaf.d.ts.map +1 -0
  258. package/dist/src/planner/rules/shared/access-leaf.js +79 -0
  259. package/dist/src/planner/rules/shared/access-leaf.js.map +1 -0
  260. package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.d.ts.map +1 -1
  261. package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.js +18 -8
  262. package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.js.map +1 -1
  263. package/dist/src/planner/rules/subquery/rule-semi-join-fk-trivial.d.ts +3 -1
  264. package/dist/src/planner/rules/subquery/rule-semi-join-fk-trivial.d.ts.map +1 -1
  265. package/dist/src/planner/rules/subquery/rule-semi-join-fk-trivial.js +27 -10
  266. package/dist/src/planner/rules/subquery/rule-semi-join-fk-trivial.js.map +1 -1
  267. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.d.ts.map +1 -1
  268. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.js +69 -11
  269. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.js.map +1 -1
  270. package/dist/src/planner/rules/window/rule-monotonic-window.d.ts +17 -7
  271. package/dist/src/planner/rules/window/rule-monotonic-window.d.ts.map +1 -1
  272. package/dist/src/planner/rules/window/rule-monotonic-window.js +124 -87
  273. package/dist/src/planner/rules/window/rule-monotonic-window.js.map +1 -1
  274. package/dist/src/planner/scopes/aliased.d.ts.map +1 -1
  275. package/dist/src/planner/scopes/aliased.js +6 -0
  276. package/dist/src/planner/scopes/aliased.js.map +1 -1
  277. package/dist/src/planner/stats/catalog-stats.d.ts +44 -13
  278. package/dist/src/planner/stats/catalog-stats.d.ts.map +1 -1
  279. package/dist/src/planner/stats/catalog-stats.js +137 -61
  280. package/dist/src/planner/stats/catalog-stats.js.map +1 -1
  281. package/dist/src/planner/stats/conjunct-selectivity.d.ts +48 -0
  282. package/dist/src/planner/stats/conjunct-selectivity.d.ts.map +1 -0
  283. package/dist/src/planner/stats/conjunct-selectivity.js +168 -0
  284. package/dist/src/planner/stats/conjunct-selectivity.js.map +1 -0
  285. package/dist/src/planner/stats/index.d.ts +22 -3
  286. package/dist/src/planner/stats/index.d.ts.map +1 -1
  287. package/dist/src/planner/stats/index.js.map +1 -1
  288. package/dist/src/planner/stats/table-cardinality.d.ts +28 -0
  289. package/dist/src/planner/stats/table-cardinality.d.ts.map +1 -0
  290. package/dist/src/planner/stats/table-cardinality.js +29 -0
  291. package/dist/src/planner/stats/table-cardinality.js.map +1 -0
  292. package/dist/src/planner/util/column-origins.d.ts +29 -8
  293. package/dist/src/planner/util/column-origins.d.ts.map +1 -1
  294. package/dist/src/planner/util/column-origins.js +74 -14
  295. package/dist/src/planner/util/column-origins.js.map +1 -1
  296. package/dist/src/planner/util/fd-utils.d.ts +32 -8
  297. package/dist/src/planner/util/fd-utils.d.ts.map +1 -1
  298. package/dist/src/planner/util/fd-utils.js +46 -9
  299. package/dist/src/planner/util/fd-utils.js.map +1 -1
  300. package/dist/src/planner/util/ind-utils.d.ts +56 -17
  301. package/dist/src/planner/util/ind-utils.d.ts.map +1 -1
  302. package/dist/src/planner/util/ind-utils.js +82 -21
  303. package/dist/src/planner/util/ind-utils.js.map +1 -1
  304. package/dist/src/planner/util/key-utils.d.ts +20 -2
  305. package/dist/src/planner/util/key-utils.d.ts.map +1 -1
  306. package/dist/src/planner/util/key-utils.js +37 -3
  307. package/dist/src/planner/util/key-utils.js.map +1 -1
  308. package/dist/src/planner/util/row-estimates.d.ts +28 -0
  309. package/dist/src/planner/util/row-estimates.d.ts.map +1 -0
  310. package/dist/src/planner/util/row-estimates.js +40 -0
  311. package/dist/src/planner/util/row-estimates.js.map +1 -0
  312. package/dist/src/planner/util/row-population.d.ts +42 -0
  313. package/dist/src/planner/util/row-population.d.ts.map +1 -0
  314. package/dist/src/planner/util/row-population.js +71 -0
  315. package/dist/src/planner/util/row-population.js.map +1 -0
  316. package/dist/src/runtime/emit/add-constraint.d.ts.map +1 -1
  317. package/dist/src/runtime/emit/add-constraint.js +39 -1
  318. package/dist/src/runtime/emit/add-constraint.js.map +1 -1
  319. package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
  320. package/dist/src/runtime/emit/aggregate.js +4 -4
  321. package/dist/src/runtime/emit/aggregate.js.map +1 -1
  322. package/dist/src/runtime/emit/alter-schema-event.d.ts +42 -0
  323. package/dist/src/runtime/emit/alter-schema-event.d.ts.map +1 -0
  324. package/dist/src/runtime/emit/alter-schema-event.js +28 -0
  325. package/dist/src/runtime/emit/alter-schema-event.js.map +1 -0
  326. package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
  327. package/dist/src/runtime/emit/alter-table.js +380 -154
  328. package/dist/src/runtime/emit/alter-table.js.map +1 -1
  329. package/dist/src/runtime/emit/analyze.d.ts.map +1 -1
  330. package/dist/src/runtime/emit/analyze.js +35 -3
  331. package/dist/src/runtime/emit/analyze.js.map +1 -1
  332. package/dist/src/runtime/emit/cast.d.ts.map +1 -1
  333. package/dist/src/runtime/emit/cast.js +4 -19
  334. package/dist/src/runtime/emit/cast.js.map +1 -1
  335. package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
  336. package/dist/src/runtime/emit/dml-executor.js +64 -27
  337. package/dist/src/runtime/emit/dml-executor.js.map +1 -1
  338. package/dist/src/runtime/emit/drop-index.d.ts.map +1 -1
  339. package/dist/src/runtime/emit/drop-index.js +4 -3
  340. package/dist/src/runtime/emit/drop-index.js.map +1 -1
  341. package/dist/src/runtime/emit/hash-aggregate.d.ts.map +1 -1
  342. package/dist/src/runtime/emit/hash-aggregate.js +2 -2
  343. package/dist/src/runtime/emit/hash-aggregate.js.map +1 -1
  344. package/dist/src/runtime/emit/join.d.ts.map +1 -1
  345. package/dist/src/runtime/emit/join.js +8 -67
  346. package/dist/src/runtime/emit/join.js.map +1 -1
  347. package/dist/src/runtime/emit/key-set-semi-join.d.ts.map +1 -1
  348. package/dist/src/runtime/emit/key-set-semi-join.js +6 -0
  349. package/dist/src/runtime/emit/key-set-semi-join.js.map +1 -1
  350. package/dist/src/runtime/emit/operand-comparator.d.ts +30 -0
  351. package/dist/src/runtime/emit/operand-comparator.d.ts.map +1 -1
  352. package/dist/src/runtime/emit/operand-comparator.js +34 -0
  353. package/dist/src/runtime/emit/operand-comparator.js.map +1 -1
  354. package/dist/src/runtime/emit/schema-declarative.d.ts.map +1 -1
  355. package/dist/src/runtime/emit/schema-declarative.js +30 -0
  356. package/dist/src/runtime/emit/schema-declarative.js.map +1 -1
  357. package/dist/src/runtime/emit/subquery.d.ts.map +1 -1
  358. package/dist/src/runtime/emit/subquery.js +153 -52
  359. package/dist/src/runtime/emit/subquery.js.map +1 -1
  360. package/dist/src/runtime/emit/window.js +36 -23
  361. package/dist/src/runtime/emit/window.js.map +1 -1
  362. package/dist/src/schema/catalog-persistability.d.ts +19 -16
  363. package/dist/src/schema/catalog-persistability.d.ts.map +1 -1
  364. package/dist/src/schema/catalog-persistability.js +76 -20
  365. package/dist/src/schema/catalog-persistability.js.map +1 -1
  366. package/dist/src/schema/catalog.d.ts +67 -2
  367. package/dist/src/schema/catalog.d.ts.map +1 -1
  368. package/dist/src/schema/catalog.js +194 -3
  369. package/dist/src/schema/catalog.js.map +1 -1
  370. package/dist/src/schema/column.d.ts +26 -3
  371. package/dist/src/schema/column.d.ts.map +1 -1
  372. package/dist/src/schema/column.js.map +1 -1
  373. package/dist/src/schema/ddl-generator.d.ts.map +1 -1
  374. package/dist/src/schema/ddl-generator.js +19 -6
  375. package/dist/src/schema/ddl-generator.js.map +1 -1
  376. package/dist/src/schema/function.d.ts +32 -1
  377. package/dist/src/schema/function.d.ts.map +1 -1
  378. package/dist/src/schema/function.js +10 -2
  379. package/dist/src/schema/function.js.map +1 -1
  380. package/dist/src/schema/manager.d.ts +84 -7
  381. package/dist/src/schema/manager.d.ts.map +1 -1
  382. package/dist/src/schema/manager.js +153 -53
  383. package/dist/src/schema/manager.js.map +1 -1
  384. package/dist/src/schema/schema-differ.d.ts.map +1 -1
  385. package/dist/src/schema/schema-differ.js +104 -28
  386. package/dist/src/schema/schema-differ.js.map +1 -1
  387. package/dist/src/schema/table.d.ts +149 -1
  388. package/dist/src/schema/table.d.ts.map +1 -1
  389. package/dist/src/schema/table.js +248 -1
  390. package/dist/src/schema/table.js.map +1 -1
  391. package/dist/src/schema/unique-enforcement.d.ts +5 -3
  392. package/dist/src/schema/unique-enforcement.d.ts.map +1 -1
  393. package/dist/src/schema/unique-enforcement.js +5 -3
  394. package/dist/src/schema/unique-enforcement.js.map +1 -1
  395. package/dist/src/types/builtin-types.d.ts +16 -0
  396. package/dist/src/types/builtin-types.d.ts.map +1 -1
  397. package/dist/src/types/builtin-types.js +46 -8
  398. package/dist/src/types/builtin-types.js.map +1 -1
  399. package/dist/src/types/cast-semantics.d.ts +42 -0
  400. package/dist/src/types/cast-semantics.d.ts.map +1 -1
  401. package/dist/src/types/cast-semantics.js +64 -0
  402. package/dist/src/types/cast-semantics.js.map +1 -1
  403. package/dist/src/types/comparison-coercion.d.ts +101 -0
  404. package/dist/src/types/comparison-coercion.d.ts.map +1 -0
  405. package/dist/src/types/comparison-coercion.js +162 -0
  406. package/dist/src/types/comparison-coercion.js.map +1 -0
  407. package/dist/src/types/index.d.ts +2 -2
  408. package/dist/src/types/index.d.ts.map +1 -1
  409. package/dist/src/types/index.js +2 -2
  410. package/dist/src/types/index.js.map +1 -1
  411. package/dist/src/types/logical-type.d.ts +7 -0
  412. package/dist/src/types/logical-type.d.ts.map +1 -1
  413. package/dist/src/types/logical-type.js.map +1 -1
  414. package/dist/src/types/validation.d.ts +56 -0
  415. package/dist/src/types/validation.d.ts.map +1 -1
  416. package/dist/src/types/validation.js +68 -0
  417. package/dist/src/types/validation.js.map +1 -1
  418. package/dist/src/util/coercion.d.ts +8 -0
  419. package/dist/src/util/coercion.d.ts.map +1 -1
  420. package/dist/src/util/coercion.js +8 -0
  421. package/dist/src/util/coercion.js.map +1 -1
  422. package/dist/src/util/comparison.d.ts +16 -3
  423. package/dist/src/util/comparison.d.ts.map +1 -1
  424. package/dist/src/util/comparison.js +21 -5
  425. package/dist/src/util/comparison.js.map +1 -1
  426. package/dist/src/util/key-serializer.d.ts +46 -0
  427. package/dist/src/util/key-serializer.d.ts.map +1 -1
  428. package/dist/src/util/key-serializer.js +47 -0
  429. package/dist/src/util/key-serializer.js.map +1 -1
  430. package/dist/src/util/value-set.d.ts +21 -0
  431. package/dist/src/util/value-set.d.ts.map +1 -0
  432. package/dist/src/util/value-set.js +22 -0
  433. package/dist/src/util/value-set.js.map +1 -0
  434. package/dist/src/vtab/capabilities.d.ts +1 -1
  435. package/dist/src/vtab/events.d.ts +5 -1
  436. package/dist/src/vtab/events.d.ts.map +1 -1
  437. package/dist/src/vtab/events.js.map +1 -1
  438. package/dist/src/vtab/memory/layer/alter-column.d.ts +147 -0
  439. package/dist/src/vtab/memory/layer/alter-column.d.ts.map +1 -0
  440. package/dist/src/vtab/memory/layer/alter-column.js +214 -0
  441. package/dist/src/vtab/memory/layer/alter-column.js.map +1 -0
  442. package/dist/src/vtab/memory/layer/base.d.ts.map +1 -1
  443. package/dist/src/vtab/memory/layer/base.js +4 -3
  444. package/dist/src/vtab/memory/layer/base.js.map +1 -1
  445. package/dist/src/vtab/memory/layer/interface.d.ts +2 -2
  446. package/dist/src/vtab/memory/layer/interface.d.ts.map +1 -1
  447. package/dist/src/vtab/memory/layer/manager.d.ts +176 -25
  448. package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
  449. package/dist/src/vtab/memory/layer/manager.js +572 -495
  450. package/dist/src/vtab/memory/layer/manager.js.map +1 -1
  451. package/dist/src/vtab/memory/layer/scan-layer.d.ts.map +1 -1
  452. package/dist/src/vtab/memory/layer/scan-layer.js +32 -5
  453. package/dist/src/vtab/memory/layer/scan-layer.js.map +1 -1
  454. package/dist/src/vtab/memory/layer/transaction.d.ts +101 -15
  455. package/dist/src/vtab/memory/layer/transaction.d.ts.map +1 -1
  456. package/dist/src/vtab/memory/layer/transaction.js +133 -45
  457. package/dist/src/vtab/memory/layer/transaction.js.map +1 -1
  458. package/dist/src/vtab/memory/module.d.ts.map +1 -1
  459. package/dist/src/vtab/memory/module.js +2 -1
  460. package/dist/src/vtab/memory/module.js.map +1 -1
  461. package/dist/src/vtab/memory/table.d.ts.map +1 -1
  462. package/dist/src/vtab/memory/table.js +11 -6
  463. package/dist/src/vtab/memory/table.js.map +1 -1
  464. package/dist/src/vtab/module.d.ts +51 -21
  465. package/dist/src/vtab/module.d.ts.map +1 -1
  466. package/dist/src/vtab/table.d.ts +1 -1
  467. package/dist/src/vtab/table.js +1 -1
  468. package/package.json +3 -3
@@ -1,4 +1,5 @@
1
1
  import type { SqlValue } from '../common/types.js';
2
+ import type { ScalarType } from '../common/datatype.js';
2
3
  import type { LogicalType } from './logical-type.js';
3
4
  /**
4
5
  * What a CAST produces when the target type's `parse` rejects the operand.
@@ -24,6 +25,29 @@ import type { LogicalType } from './logical-type.js';
24
25
  * loosening this to "no validate ⇒ keep".
25
26
  */
26
27
  export declare function castFallback(value: SqlValue, type: LogicalType): SqlValue;
28
+ /**
29
+ * What `cast(<value> as type)` produces: the target type's `parse`, falling back to
30
+ * {@link castFallback} when it rejects the operand. CAST stays lenient and never throws.
31
+ *
32
+ * THE one definition of "convert to this type the way CAST does". `emitCast` is the
33
+ * expression-level caller; `emitIn`'s membership evaluation converts a per-row subquery
34
+ * value where the plan-time coercion (`insertCrossTypeCoercion`) has no fixed operand to
35
+ * wrap; `makeComparisonGroup` (`runtime/emit/operand-comparator.ts`) converts a per-row
36
+ * *copy* of a comparison builtin's argument, where wrapping the operand would corrupt the
37
+ * value that builtin returns.
38
+ *
39
+ * NOTE: a type with no `parse` defines no conversion, so the operand passes through while
40
+ * the caller still advertises the target type — the very shape castFallback exists to
41
+ * prevent. Unreachable today: NULL is the only builtin without `parse`, and the parser
42
+ * rejects it as a CAST target. If a plugin ever registers a parse-less type, validate here.
43
+ *
44
+ * NOTE: the fallback path costs one *thrown* exception per call, and every caller runs
45
+ * per row — so a scan whose operands mostly fail to parse (`json_col in (select
46
+ * free_text from big_table)`, or `least(free_text, 1)` over a text column of prose) pays
47
+ * V8 exception construction on every row. Fine at current scale; if it ever shows up in
48
+ * a profile, give LogicalType an optional non-throwing `tryParse` and prefer it here.
49
+ */
50
+ export declare function lenientCast(value: SqlValue, type: LogicalType): SqlValue;
27
51
  /**
28
52
  * Can `cast(<non-null operand> as type)` produce NULL? Answers the static
29
53
  * nullability of a converting CAST ({@link import('../planner/nodes/scalar.js').CastNode}).
@@ -40,4 +64,22 @@ export declare function castFallback(value: SqlValue, type: LogicalType): SqlVal
40
64
  * declaration, while under-reporting it would let a NULL reach a NOT NULL column.
41
65
  */
42
66
  export declare function castCanYieldNull(type: LogicalType): boolean;
67
+ /**
68
+ * The ScalarType a conversion to `target` advertises for an operand of
69
+ * `operandType` — THE one derivation of "what does the converted value look like
70
+ * statically". {@link import('../planner/nodes/scalar.js').CastNode} is the
71
+ * plan-time caller; `makeComparisonGroup` (`runtime/emit/operand-comparator.ts`)
72
+ * is the emit-time one, so an emit-time comparison key resolves its collation and
73
+ * comparator routing off exactly the types a plan-time cast would have produced.
74
+ *
75
+ * A converting CAST is nullable even from a non-null operand: `cast('' as integer)`
76
+ * is null because INTEGER's parse maps the empty string to null, and a conversion
77
+ * that fails outright yields null rather than the unconverted operand. A cast to
78
+ * the operand's own type converts nothing, and TEXT/BLOB convert every non-null
79
+ * operand ({@link castCanYieldNull}), so both keep the operand's nullability.
80
+ *
81
+ * Collation survives only into a textual target: a number or a JSON document has
82
+ * no collation to compare under.
83
+ */
84
+ export declare function castedScalarType(operandType: ScalarType, target: LogicalType): ScalarType;
43
85
  //# sourceMappingURL=cast-semantics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cast-semantics.d.ts","sourceRoot":"","sources":["../../../src/types/cast-semantics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,GAAG,QAAQ,CAezE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAE3D"}
1
+ {"version":3,"file":"cast-semantics.d.ts","sourceRoot":"","sources":["../../../src/types/cast-semantics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,GAAG,QAAQ,CAezE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,GAAG,QAAQ,CAUxE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAE3D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,GAAG,UAAU,CAUzF"}
@@ -38,6 +38,42 @@ export function castFallback(value, type) {
38
38
  return type.validate?.(value) === true ? value : null;
39
39
  }
40
40
  }
41
+ /**
42
+ * What `cast(<value> as type)` produces: the target type's `parse`, falling back to
43
+ * {@link castFallback} when it rejects the operand. CAST stays lenient and never throws.
44
+ *
45
+ * THE one definition of "convert to this type the way CAST does". `emitCast` is the
46
+ * expression-level caller; `emitIn`'s membership evaluation converts a per-row subquery
47
+ * value where the plan-time coercion (`insertCrossTypeCoercion`) has no fixed operand to
48
+ * wrap; `makeComparisonGroup` (`runtime/emit/operand-comparator.ts`) converts a per-row
49
+ * *copy* of a comparison builtin's argument, where wrapping the operand would corrupt the
50
+ * value that builtin returns.
51
+ *
52
+ * NOTE: a type with no `parse` defines no conversion, so the operand passes through while
53
+ * the caller still advertises the target type — the very shape castFallback exists to
54
+ * prevent. Unreachable today: NULL is the only builtin without `parse`, and the parser
55
+ * rejects it as a CAST target. If a plugin ever registers a parse-less type, validate here.
56
+ *
57
+ * NOTE: the fallback path costs one *thrown* exception per call, and every caller runs
58
+ * per row — so a scan whose operands mostly fail to parse (`json_col in (select
59
+ * free_text from big_table)`, or `least(free_text, 1)` over a text column of prose) pays
60
+ * V8 exception construction on every row. Fine at current scale; if it ever shows up in
61
+ * a profile, give LogicalType an optional non-throwing `tryParse` and prefer it here.
62
+ */
63
+ export function lenientCast(value, type) {
64
+ if (value === null)
65
+ return null;
66
+ if (!type.parse)
67
+ return value;
68
+ try {
69
+ return type.parse(value);
70
+ }
71
+ catch {
72
+ // CAST failures in SQL return 0 for numeric targets, '' for text, etc.
73
+ // This matches SQLite's lenient CAST behavior.
74
+ return castFallback(value, type);
75
+ }
76
+ }
41
77
  /**
42
78
  * Can `cast(<non-null operand> as type)` produce NULL? Answers the static
43
79
  * nullability of a converting CAST ({@link import('../planner/nodes/scalar.js').CastNode}).
@@ -56,4 +92,32 @@ export function castFallback(value, type) {
56
92
  export function castCanYieldNull(type) {
57
93
  return type !== TEXT_TYPE && type !== BLOB_TYPE;
58
94
  }
95
+ /**
96
+ * The ScalarType a conversion to `target` advertises for an operand of
97
+ * `operandType` — THE one derivation of "what does the converted value look like
98
+ * statically". {@link import('../planner/nodes/scalar.js').CastNode} is the
99
+ * plan-time caller; `makeComparisonGroup` (`runtime/emit/operand-comparator.ts`)
100
+ * is the emit-time one, so an emit-time comparison key resolves its collation and
101
+ * comparator routing off exactly the types a plan-time cast would have produced.
102
+ *
103
+ * A converting CAST is nullable even from a non-null operand: `cast('' as integer)`
104
+ * is null because INTEGER's parse maps the empty string to null, and a conversion
105
+ * that fails outright yields null rather than the unconverted operand. A cast to
106
+ * the operand's own type converts nothing, and TEXT/BLOB convert every non-null
107
+ * operand ({@link castCanYieldNull}), so both keep the operand's nullability.
108
+ *
109
+ * Collation survives only into a textual target: a number or a JSON document has
110
+ * no collation to compare under.
111
+ */
112
+ export function castedScalarType(operandType, target) {
113
+ return {
114
+ typeClass: 'scalar',
115
+ logicalType: target,
116
+ nullable: operandType.nullable
117
+ || (target !== operandType.logicalType && castCanYieldNull(target)),
118
+ isReadOnly: operandType.isReadOnly,
119
+ collationName: target.isTextual ? operandType.collationName : undefined,
120
+ collationSource: target.isTextual ? operandType.collationSource : undefined,
121
+ };
122
+ }
59
123
  //# sourceMappingURL=cast-semantics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cast-semantics.js","sourceRoot":"","sources":["../../../src/types/cast-semantics.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,YAAY,CAAC,KAAe,EAAE,IAAiB;IAC9D,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,SAAS;YACb,OAAO,CAAC,CAAC;QACV,KAAK,MAAM;YACV,OAAO,GAAG,CAAC;QACZ,KAAK,SAAS;YACb,OAAO,CAAC,CAAC;QACV,KAAK,MAAM;YACV,OAAO,MAAM,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QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,CAAC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IAC9B,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACR,uEAAuE;QACvE,+CAA+C;QAC/C,OAAO,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAiB;IACjD,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAuB,EAAE,MAAmB;IAC5E,OAAO;QACN,SAAS,EAAE,QAAQ;QACnB,WAAW,EAAE,MAAM;QACnB,QAAQ,EAAE,WAAW,CAAC,QAAQ;eAC1B,CAAC,MAAM,KAAK,WAAW,CAAC,WAAW,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;QACpE,UAAU,EAAE,WAAW,CAAC,UAAU;QAClC,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS;QACvE,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS;KAC3E,CAAC;AACH,CAAC"}
@@ -0,0 +1,101 @@
1
+ import type { LogicalType } from './logical-type.js';
2
+ /**
3
+ * THE type-level decision behind every comparison-site coercion: given the
4
+ * declared types of the operands, which of them must be converted, and to what.
5
+ * Purely about `LogicalType` — no plan nodes, no values — so both consumers read
6
+ * the same rule and cannot drift:
7
+ *
8
+ * - **Plan-time** (`planner/building/coercion.ts`) maps the answer onto synthetic
9
+ * `CastNode` wrappers, for `=` and friends, BETWEEN, IN value lists and simple
10
+ * CASE.
11
+ * - **Emit-time** (`runtime/emit/operand-comparator.ts` `makeComparisonGroup`)
12
+ * maps the same answer onto per-row {@link import('./cast-semantics.js').lenientCast}
13
+ * calls, for the comparison builtins that *return* one of their arguments
14
+ * (`nullif`, `greatest`, `least`) and therefore cannot have that argument
15
+ * replaced by its cast.
16
+ *
17
+ * Both paths convert identically: a plan-time `CastNode` runs `lenientCast` per
18
+ * row too (`runtime/emit/cast.ts`), so "compare the converted copy" and "compare
19
+ * the cast operand" are the same comparison.
20
+ */
21
+ /**
22
+ * The argument positions a function's `comparesArgs` declaration
23
+ * ({@link import('../schema/function.js').BaseFunctionSchema.comparesArgs}) names,
24
+ * clamped to the call's actual arity. Index 0 of the result is the group's probe.
25
+ * Shared by the plan-time rewrite and the emit-time group builder so they cannot
26
+ * disagree about which positions form the group.
27
+ */
28
+ export declare function comparisonGroupIndices(comparesArgs: 'all' | readonly number[], argCount: number): readonly number[];
29
+ /** Which side of a pairwise comparison converts, and to what. */
30
+ export interface CrossTypeCoercion {
31
+ readonly side: 'left' | 'right';
32
+ readonly target: LogicalType;
33
+ }
34
+ /**
35
+ * Reconcile two operand types that cannot be compared meaningfully as-is.
36
+ * Returns `null` when neither side converts.
37
+ *
38
+ * Two pairings are handled, in this order:
39
+ *
40
+ * 1. **Object-physical vs anything else.** JSON is the engine's only logical type
41
+ * whose `physicalType` is `PhysicalType.OBJECT`: its runtime values are native
42
+ * JS objects/arrays, which `compareSqlValuesFast` short-circuits against any
43
+ * other storage class — so `json_col = '{"a":1}'` was unconditionally false,
44
+ * even for byte-identical text. The non-object side converts to the object
45
+ * side's type, never the reverse: converting the JSON side to text would make
46
+ * equality depend on spelling and put `=` out of step with the index, which
47
+ * compares structurally.
48
+ *
49
+ * The gate is deliberately `physicalType === OBJECT`, **not**
50
+ * `semanticOrdering`. DATE/TIME/DATETIME/TIMESPAN also carry semantic ordering
51
+ * but are physically text, and the runtime's `tryTemporalComparison` already
52
+ * reconciles them; routing them through a conversion would change behavior for
53
+ * no gain.
54
+ *
55
+ * A conversion to JSON is lenient (see `types/cast-semantics.ts`): text that
56
+ * does not parse comes back unchanged, so `json_col = 'not json'` is false
57
+ * rather than an error. Note the consequence for JSON *string scalars*, which
58
+ * are stored as plain JS strings: a column holding `"hello"` matches BOTH the
59
+ * SQL literal `'"hello"'` (parses to the JSON string `hello`) and the bare
60
+ * `'hello'` (does not parse, falls back to the raw string `hello`, which
61
+ * `JSON_TYPE.compare` then compares as text). Only the first form generalizes —
62
+ * `'[1,2]'` matches the JSON array while a bare `[1,2]` is not SQL text at all.
63
+ *
64
+ * A NULL-typed operand is left alone: the comparison is UNKNOWN regardless, so
65
+ * the conversion would only add a runtime hop.
66
+ *
67
+ * 2. **Numeric vs textual.** The textual operand converts to the numeric side's
68
+ * type (e.g. INTEGER or REAL) so the runtime can take the fast path.
69
+ */
70
+ export declare function crossTypeCoercion(left: LogicalType, right: LogicalType): CrossTypeCoercion | null;
71
+ /**
72
+ * Per-operand conversion target for a "one probe against many values" comparison
73
+ * group — an IN value list, a simple CASE, or a comparison builtin's argument
74
+ * group. Index 0 is the probe, the rest the value list. The result is aligned with
75
+ * the input array; `null` at a position means "leave that operand alone".
76
+ *
77
+ * This is more than a `map` over {@link crossTypeCoercion} because the probe is a
78
+ * SINGLE operand shared by every value, so it can convert at most once:
79
+ *
80
+ * - **A value-side conversion is per value** and never conflicts: an
81
+ * object-physical or numeric probe leaves the probe alone and converts each
82
+ * value independently, so a mixed list (`case i when '1' when 2 …`) gets a
83
+ * per-clause decision for free.
84
+ * - **A probe-side conversion is hoisted** and therefore has to be unambiguous.
85
+ * For the object arm it always is: a conversion to JSON is lenient, so a textual
86
+ * value that is not JSON source survives as itself and still compares as text.
87
+ * For the numeric arm it is NOT — `cast('abc' as real)` is `0`, so hoisting a
88
+ * probe conversion over a MIXED list would make `t in (1, 'abc')` true for the
89
+ * stored text `'0'`, which `t = 1 or t = 'abc'` is not. So the numeric probe
90
+ * conversion applies only when every non-NULL value is numeric.
91
+ *
92
+ * NOTE: the leftover gap is a textual probe against a list mixing numeric and
93
+ * textual values (`text_col in (1, 'abc')`), which stays unconverted and so still
94
+ * disagrees with the `=` disjunction on the numeric member. Closing it needs a
95
+ * per-value probe, which `IN` cannot express — its members live in ONE key space
96
+ * (a BTree keyed under one collation, `runtime/emit/subquery.ts`). If that shape
97
+ * ever matters, desugar a mixed `IN` list into an `OR` of `=` comparisons at build
98
+ * time rather than widening the hoist here.
99
+ */
100
+ export declare function comparisonGroupCoercions(logicals: readonly LogicalType[]): readonly (LogicalType | null)[];
101
+ //# sourceMappingURL=comparison-coercion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparison-coercion.d.ts","sourceRoot":"","sources":["../../../src/types/comparison-coercion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACrC,YAAY,EAAE,KAAK,GAAG,SAAS,MAAM,EAAE,EACvC,QAAQ,EAAE,MAAM,GACd,SAAS,MAAM,EAAE,CAInB;AAED,iEAAiE;AACjE,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC7B;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,GAAG,iBAAiB,GAAG,IAAI,CAgBjG;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,wBAAwB,CACvC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC9B,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,CAqCjC"}
@@ -0,0 +1,162 @@
1
+ import { PhysicalType } from './logical-type.js';
2
+ import { NULL_TYPE, NUMERIC_TYPE } from './builtin-types.js';
3
+ /**
4
+ * THE type-level decision behind every comparison-site coercion: given the
5
+ * declared types of the operands, which of them must be converted, and to what.
6
+ * Purely about `LogicalType` — no plan nodes, no values — so both consumers read
7
+ * the same rule and cannot drift:
8
+ *
9
+ * - **Plan-time** (`planner/building/coercion.ts`) maps the answer onto synthetic
10
+ * `CastNode` wrappers, for `=` and friends, BETWEEN, IN value lists and simple
11
+ * CASE.
12
+ * - **Emit-time** (`runtime/emit/operand-comparator.ts` `makeComparisonGroup`)
13
+ * maps the same answer onto per-row {@link import('./cast-semantics.js').lenientCast}
14
+ * calls, for the comparison builtins that *return* one of their arguments
15
+ * (`nullif`, `greatest`, `least`) and therefore cannot have that argument
16
+ * replaced by its cast.
17
+ *
18
+ * Both paths convert identically: a plan-time `CastNode` runs `lenientCast` per
19
+ * row too (`runtime/emit/cast.ts`), so "compare the converted copy" and "compare
20
+ * the cast operand" are the same comparison.
21
+ */
22
+ /**
23
+ * The argument positions a function's `comparesArgs` declaration
24
+ * ({@link import('../schema/function.js').BaseFunctionSchema.comparesArgs}) names,
25
+ * clamped to the call's actual arity. Index 0 of the result is the group's probe.
26
+ * Shared by the plan-time rewrite and the emit-time group builder so they cannot
27
+ * disagree about which positions form the group.
28
+ */
29
+ export function comparisonGroupIndices(comparesArgs, argCount) {
30
+ return comparesArgs === 'all'
31
+ ? Array.from({ length: argCount }, (_, i) => i)
32
+ : comparesArgs.filter(i => i >= 0 && i < argCount);
33
+ }
34
+ const isObject = (type) => type.physicalType === PhysicalType.OBJECT;
35
+ /**
36
+ * Reconcile two operand types that cannot be compared meaningfully as-is.
37
+ * Returns `null` when neither side converts.
38
+ *
39
+ * Two pairings are handled, in this order:
40
+ *
41
+ * 1. **Object-physical vs anything else.** JSON is the engine's only logical type
42
+ * whose `physicalType` is `PhysicalType.OBJECT`: its runtime values are native
43
+ * JS objects/arrays, which `compareSqlValuesFast` short-circuits against any
44
+ * other storage class — so `json_col = '{"a":1}'` was unconditionally false,
45
+ * even for byte-identical text. The non-object side converts to the object
46
+ * side's type, never the reverse: converting the JSON side to text would make
47
+ * equality depend on spelling and put `=` out of step with the index, which
48
+ * compares structurally.
49
+ *
50
+ * The gate is deliberately `physicalType === OBJECT`, **not**
51
+ * `semanticOrdering`. DATE/TIME/DATETIME/TIMESPAN also carry semantic ordering
52
+ * but are physically text, and the runtime's `tryTemporalComparison` already
53
+ * reconciles them; routing them through a conversion would change behavior for
54
+ * no gain.
55
+ *
56
+ * A conversion to JSON is lenient (see `types/cast-semantics.ts`): text that
57
+ * does not parse comes back unchanged, so `json_col = 'not json'` is false
58
+ * rather than an error. Note the consequence for JSON *string scalars*, which
59
+ * are stored as plain JS strings: a column holding `"hello"` matches BOTH the
60
+ * SQL literal `'"hello"'` (parses to the JSON string `hello`) and the bare
61
+ * `'hello'` (does not parse, falls back to the raw string `hello`, which
62
+ * `JSON_TYPE.compare` then compares as text). Only the first form generalizes —
63
+ * `'[1,2]'` matches the JSON array while a bare `[1,2]` is not SQL text at all.
64
+ *
65
+ * A NULL-typed operand is left alone: the comparison is UNKNOWN regardless, so
66
+ * the conversion would only add a runtime hop.
67
+ *
68
+ * 2. **Numeric vs textual.** The textual operand converts to the numeric side's
69
+ * type (e.g. INTEGER or REAL) so the runtime can take the fast path.
70
+ */
71
+ export function crossTypeCoercion(left, right) {
72
+ const leftObject = isObject(left);
73
+ const rightObject = isObject(right);
74
+ // NOTE: two object-physical operands of DIFFERENT logical types fall through both
75
+ // arms onto the generic runtime path. Unreachable while JSON is the only
76
+ // PhysicalType.OBJECT type; adding a second one means deciding which side converts.
77
+ if (leftObject !== rightObject) {
78
+ if (leftObject && right !== NULL_TYPE)
79
+ return { side: 'right', target: left };
80
+ if (rightObject && left !== NULL_TYPE)
81
+ return { side: 'left', target: right };
82
+ return null;
83
+ }
84
+ if (left.isNumeric && right.isTextual)
85
+ return { side: 'right', target: left };
86
+ if (right.isNumeric && left.isTextual)
87
+ return { side: 'left', target: right };
88
+ return null;
89
+ }
90
+ /**
91
+ * Per-operand conversion target for a "one probe against many values" comparison
92
+ * group — an IN value list, a simple CASE, or a comparison builtin's argument
93
+ * group. Index 0 is the probe, the rest the value list. The result is aligned with
94
+ * the input array; `null` at a position means "leave that operand alone".
95
+ *
96
+ * This is more than a `map` over {@link crossTypeCoercion} because the probe is a
97
+ * SINGLE operand shared by every value, so it can convert at most once:
98
+ *
99
+ * - **A value-side conversion is per value** and never conflicts: an
100
+ * object-physical or numeric probe leaves the probe alone and converts each
101
+ * value independently, so a mixed list (`case i when '1' when 2 …`) gets a
102
+ * per-clause decision for free.
103
+ * - **A probe-side conversion is hoisted** and therefore has to be unambiguous.
104
+ * For the object arm it always is: a conversion to JSON is lenient, so a textual
105
+ * value that is not JSON source survives as itself and still compares as text.
106
+ * For the numeric arm it is NOT — `cast('abc' as real)` is `0`, so hoisting a
107
+ * probe conversion over a MIXED list would make `t in (1, 'abc')` true for the
108
+ * stored text `'0'`, which `t = 1 or t = 'abc'` is not. So the numeric probe
109
+ * conversion applies only when every non-NULL value is numeric.
110
+ *
111
+ * NOTE: the leftover gap is a textual probe against a list mixing numeric and
112
+ * textual values (`text_col in (1, 'abc')`), which stays unconverted and so still
113
+ * disagrees with the `=` disjunction on the numeric member. Closing it needs a
114
+ * per-value probe, which `IN` cannot express — its members live in ONE key space
115
+ * (a BTree keyed under one collation, `runtime/emit/subquery.ts`). If that shape
116
+ * ever matters, desugar a mixed `IN` list into an `OR` of `=` comparisons at build
117
+ * time rather than widening the hoist here.
118
+ */
119
+ export function comparisonGroupCoercions(logicals) {
120
+ const none = logicals.map(() => null);
121
+ if (logicals.length < 2)
122
+ return none;
123
+ const probe = logicals[0];
124
+ const values = logicals.slice(1);
125
+ /** The value-side half of a pairwise decision against an already-settled probe type. */
126
+ const valueTarget = (probeType, value) => {
127
+ const coercion = crossTypeCoercion(probeType, value);
128
+ return coercion?.side === 'right' ? coercion.target : null;
129
+ };
130
+ // Object arm: the non-object side converts, exactly as the pairwise function decides.
131
+ const objectValue = values.find(isObject);
132
+ if (isObject(probe) || objectValue) {
133
+ const effectiveProbe = isObject(probe) ? probe : objectValue;
134
+ return [
135
+ isObject(probe) ? null : effectiveProbe,
136
+ ...values.map(value => valueTarget(effectiveProbe, value)),
137
+ ];
138
+ }
139
+ // Numeric probe: every textual value converts to the probe's numeric type, independently.
140
+ if (probe.isNumeric) {
141
+ return [null, ...values.map(value => valueTarget(probe, value))];
142
+ }
143
+ // Textual probe: one hoisted conversion, but only over an all-numeric value list.
144
+ if (probe.isTextual) {
145
+ const nonNull = values.filter(type => type !== NULL_TYPE);
146
+ if (nonNull.length > 0 && nonNull.every(type => type.isNumeric)) {
147
+ return [commonNumericType(nonNull), ...values.map(() => null)];
148
+ }
149
+ }
150
+ return none;
151
+ }
152
+ /**
153
+ * The conversion target for a hoisted probe over an all-numeric value list. One
154
+ * shared type means one key space; NUMERIC is the fallback because its value
155
+ * space (`number | bigint`) covers INTEGER and REAL together, so a list mixing a
156
+ * bigint literal with a real one does not have to pick a lossy winner.
157
+ */
158
+ function commonNumericType(valueTypes) {
159
+ const first = valueTypes[0];
160
+ return valueTypes.every(type => type === first) ? first : NUMERIC_TYPE;
161
+ }
162
+ //# sourceMappingURL=comparison-coercion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparison-coercion.js","sourceRoot":"","sources":["../../../src/types/comparison-coercion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACrC,YAAuC,EACvC,QAAgB;IAEhB,OAAO,YAAY,KAAK,KAAK;QAC5B,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,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kFAAkF;IAClF,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QACrB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;QAC1D,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACjE,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAChE,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,UAAkC;IAC5D,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5B,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC;AACxE,CAAC"}
@@ -1,7 +1,7 @@
1
1
  export { PhysicalType, type LogicalType, getPhysicalType, physicalTypeName, compareNulls } from './logical-type.js';
2
- export { NULL_TYPE, INTEGER_TYPE, REAL_TYPE, TEXT_TYPE, BLOB_TYPE, BOOLEAN_TYPE, NUMERIC_TYPE, ANY_TYPE } from './builtin-types.js';
2
+ export { NULL_TYPE, INTEGER_TYPE, REAL_TYPE, TEXT_TYPE, BLOB_TYPE, BOOLEAN_TYPE, NUMERIC_TYPE, ANY_TYPE, isNumericOrUnknownType } from './builtin-types.js';
3
3
  export { DATE_TYPE, TIME_TYPE, DATETIME_TYPE, TIMESPAN_TYPE } from './temporal-types.js';
4
4
  export { JSON_TYPE } from './json-type.js';
5
5
  export { typeRegistry, registerType, getType, getTypeOrDefault, inferType } from './registry.js';
6
- export { validateValue, parseValue, validateAndParse, coerceRowToSchema, isValidForType, tryParse } from './validation.js';
6
+ export { validateValue, parseValue, validateAndParse, coerceRowToSchema, foldDefaultToType, isValidForType, tryParse } from './validation.js';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGpH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAGpI,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGjG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGpH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAG5J,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGjG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  // Core type system exports
2
2
  export { PhysicalType, getPhysicalType, physicalTypeName, compareNulls } from './logical-type.js';
3
3
  // Built-in types
4
- export { NULL_TYPE, INTEGER_TYPE, REAL_TYPE, TEXT_TYPE, BLOB_TYPE, BOOLEAN_TYPE, NUMERIC_TYPE, ANY_TYPE } from './builtin-types.js';
4
+ export { NULL_TYPE, INTEGER_TYPE, REAL_TYPE, TEXT_TYPE, BLOB_TYPE, BOOLEAN_TYPE, NUMERIC_TYPE, ANY_TYPE, isNumericOrUnknownType } from './builtin-types.js';
5
5
  // Temporal types
6
6
  export { DATE_TYPE, TIME_TYPE, DATETIME_TYPE, TIMESPAN_TYPE } from './temporal-types.js';
7
7
  // JSON type
@@ -9,5 +9,5 @@ export { JSON_TYPE } from './json-type.js';
9
9
  // Type registry
10
10
  export { typeRegistry, registerType, getType, getTypeOrDefault, inferType } from './registry.js';
11
11
  // Validation utilities
12
- export { validateValue, parseValue, validateAndParse, coerceRowToSchema, isValidForType, tryParse } from './validation.js';
12
+ export { validateValue, parseValue, validateAndParse, coerceRowToSchema, foldDefaultToType, isValidForType, tryParse } from './validation.js';
13
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,YAAY,EAAoB,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;A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AU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
@@ -58,6 +58,13 @@ export interface LogicalType {
58
58
  parse?(value: SqlValue): SqlValue;
59
59
  /** Type-specific comparison function */
60
60
  compare?(a: SqlValue, b: SqlValue, collation?: CollationFunction): number;
61
+ /**
62
+ * True when {@link compare} actually applies the collation function it is handed
63
+ * (TEXT, ANY). When unset, the type's compare is collation-blind, so a key
64
+ * structure over such a column must be keyed under BINARY regardless of the
65
+ * column's declared COLLATE — see `pkKeyCollationName`.
66
+ */
67
+ collationAware?: boolean;
61
68
  /**
62
69
  * True when {@link compare} defines an order that OBSERVABLY differs from
63
70
  * storage-class + collation ordering of the stored representation (e.g. TIMESPAN
@@ -1 +1 @@
1
- {"version":3,"file":"logical-type.d.ts","sourceRoot":"","sources":["../../../src/types/logical-type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAEjE;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,aAAa,EAAE,MAAM,KAAK,iBAAiB,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,KAAK,aAAa,CAAC;AAEzF;;;GAGG;AACH,oBAAY,YAAY;IACvB,IAAI,IAAI;IACR,OAAO,IAAI,CAAK,kBAAkB;IAClC,IAAI,IAAI,CAAQ,0BAA0B;IAC1C,IAAI,IAAI,CAAQ,SAAS;IACzB,IAAI,IAAI,CAAQ,aAAa;IAC7B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AAC,CAAC,OAAO,QAAQ,CAAC;QAC1C,OAAO,CAAC,CAAC,OAAO,SAAS,CAAC;IAC3B,CAAC;AACF,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import type { Row, SqlValue } from '../common/types.js';
2
2
  import type { LogicalType } from './logical-type.js';
3
3
  import type { ColumnSchema } from '../schema/column.js';
4
+ import type { Expression } from '../parser/ast.js';
4
5
  /**
5
6
  * Validate a value against a logical type.
6
7
  * Throws an error if the value is invalid.
@@ -71,6 +72,61 @@ export declare function coerceRowToSchema(row: Row, columns: readonly ColumnSche
71
72
  * guard, mirroring {@link coerceRowToSchema}'s map-over-present-cells behavior.
72
73
  */
73
74
  export declare function buildRowCoercion(sourceTypes: ReadonlyArray<LogicalType | undefined>, columns: readonly ColumnSchema[]): ((row: Row) => Row) | undefined;
75
+ /**
76
+ * Fold a DEFAULT expression to a literal AND convert it to the column's declared
77
+ * logical type — the value a fresh INSERT under the same DEFAULT would store. Every
78
+ * ALTER backfill site (ADD COLUMN literal default, SET NOT NULL backfill, and their
79
+ * event-image remaps, across the memory module, the store module and the isolation
80
+ * overlay) goes through here, so a backfilled cell is indistinguishable from an
81
+ * inserted one and the sites cannot drift apart.
82
+ *
83
+ * Returns `undefined` when the expression does not fold to a literal (the caller's
84
+ * per-row evaluator path owns that case) and `null` when it folds to NULL. An AST
85
+ * literal is always raw source form (a TEXT literal `'"abc"'`, never an already-parsed
86
+ * JSON value), so unlike {@link buildRowCoercion} this needs no identity guard — the
87
+ * conversion is always the first one applied to the value.
88
+ *
89
+ * NOTE: that "raw source form" invariant holds because every DEFAULT expression here comes
90
+ * from the parser (schema round-trips re-stringify and re-parse it). If a path ever
91
+ * synthesizes a DEFAULT AST node from an already-stored value, this becomes a second
92
+ * conversion and needs the same identity guard `buildRowCoercion` carries.
93
+ *
94
+ * @throws QuereusError (MISMATCH) when the literal cannot be converted, carrying the
95
+ * same message text the INSERT path produces.
96
+ */
97
+ export declare function foldDefaultToType(expr: Expression | null | undefined, logicalType: LogicalType, columnName: string): SqlValue | undefined;
98
+ /** What {@link planRetypeConversion} decided for one `alter column … set data type`. */
99
+ export interface RetypeConversion {
100
+ /** The target's logical type, resolved via {@link inferType}. */
101
+ readonly newLogicalType: LogicalType;
102
+ /**
103
+ * `null` for a metadata-only (alias) retype — nothing to rewrite. Otherwise converts one
104
+ * non-NULL value; callers route NULLs around it themselves (`set data type` leaves them
105
+ * untouched, a NOT NULL backfill maps them to DEFAULT before this ever sees them).
106
+ */
107
+ readonly convert: ((value: SqlValue) => SqlValue) | null;
108
+ }
109
+ /**
110
+ * Decide whether `alter column … set data type` rewrites stored values, and if so, build the
111
+ * per-value converter. Shared by every backend that implements SET DATA TYPE (the memory
112
+ * module, the KV store module, and the isolation overlay's staged-row migration) so the
113
+ * "does this retype touch anything" gate and the conversion failure's message/status code
114
+ * cannot drift between them — the isolation layer keys its own error routing off that status
115
+ * code, deciding whether another connection's staged rows are marked unusable rather than
116
+ * aborting the ALTER outright.
117
+ *
118
+ * Gated on logical-type IDENTITY, not physical storage class: {@link inferType} flattens
119
+ * aliases to the shared type object (`varchar(50)` IS `TEXT_TYPE`), so an alias retype
120
+ * returns a `null` converter. Any other retype — including a same-storage-class move like
121
+ * text → date — returns one that validates AND normalizes to the new type's canonical
122
+ * spelling, rethrowing a parse/validate failure as `QuereusError(MISMATCH)`.
123
+ *
124
+ * @param dataType The target type name as written in the ALTER statement (echoed into the
125
+ * failure message verbatim)
126
+ * @param oldLogicalType The column's CURRENT logical type
127
+ * @param columnName The column name (echoed into the failure message)
128
+ */
129
+ export declare function planRetypeConversion(dataType: string, oldLogicalType: LogicalType, columnName: string): RetypeConversion;
74
130
  /**
75
131
  * Check if a value is compatible with a logical type without throwing.
76
132
  *
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/types/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG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