@luma.gl/graph 10.0.0-beta.2 → 10.0.0-beta.4

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 (317) hide show
  1. package/dist/arrow/gpu/arrow-gpu-analytics-adapters.cjs +22 -9
  2. package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts +11 -2
  3. package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts.map +1 -1
  4. package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js +27 -10
  5. package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js.map +1 -1
  6. package/dist/arrow/gpu/arrow-gpu-analytics-readback.cjs +24 -13
  7. package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts +9 -1
  8. package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts.map +1 -1
  9. package/dist/arrow/gpu/arrow-gpu-analytics-readback.js +41 -14
  10. package/dist/arrow/gpu/arrow-gpu-analytics-readback.js.map +1 -1
  11. package/dist/arrow/gpu/arrow-gpu-table-conversion.cjs +82 -23
  12. package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts +16 -1
  13. package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts.map +1 -1
  14. package/dist/arrow/gpu/arrow-gpu-table-conversion.js +98 -24
  15. package/dist/arrow/gpu/arrow-gpu-table-conversion.js.map +1 -1
  16. package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +7 -0
  17. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts +2 -0
  18. package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
  19. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +14 -0
  20. package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
  21. package/dist/arrow/index.cjs +2 -0
  22. package/dist/arrow/index.cjs.map +3 -3
  23. package/dist/arrow/index.d.ts +1 -1
  24. package/dist/arrow/index.d.ts.map +1 -1
  25. package/dist/arrow/index.js +1 -1
  26. package/dist/arrow/index.js.map +1 -1
  27. package/dist/arrow/vectors/arrow-temporal-gpu-vector.cjs +1 -2
  28. package/dist/arrow/vectors/arrow-temporal-gpu-vector.js +2 -2
  29. package/dist/arrow/vectors/arrow-temporal-gpu-vector.js.map +1 -1
  30. package/dist/dist.dev.js +62 -27
  31. package/dist/dist.min.js +48 -47
  32. package/dist/gpu-core/gpu-bvh-bounds.cjs +63 -0
  33. package/dist/gpu-core/gpu-bvh-bounds.d.ts +32 -0
  34. package/dist/gpu-core/gpu-bvh-bounds.d.ts.map +1 -0
  35. package/dist/gpu-core/gpu-bvh-bounds.js +56 -0
  36. package/dist/gpu-core/gpu-bvh-bounds.js.map +1 -0
  37. package/dist/gpu-core/gpu-command-graph-budget-controller.cjs +10 -2
  38. package/dist/gpu-core/gpu-command-graph-budget-controller.d.ts +4 -0
  39. package/dist/gpu-core/gpu-command-graph-budget-controller.d.ts.map +1 -1
  40. package/dist/gpu-core/gpu-command-graph-budget-controller.js +10 -2
  41. package/dist/gpu-core/gpu-command-graph-budget-controller.js.map +1 -1
  42. package/dist/gpu-core/gpu-command-graph-submission-pacer.cjs +92 -0
  43. package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts +41 -0
  44. package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts.map +1 -0
  45. package/dist/gpu-core/gpu-command-graph-submission-pacer.js +85 -0
  46. package/dist/gpu-core/gpu-command-graph-submission-pacer.js.map +1 -0
  47. package/dist/gpu-core/gpu-group-aggregation.cjs +45 -21
  48. package/dist/gpu-core/gpu-group-aggregation.d.ts +4 -0
  49. package/dist/gpu-core/gpu-group-aggregation.d.ts.map +1 -1
  50. package/dist/gpu-core/gpu-group-aggregation.js +58 -24
  51. package/dist/gpu-core/gpu-group-aggregation.js.map +1 -1
  52. package/dist/gpu-core/index.cjs +6 -0
  53. package/dist/gpu-core/index.cjs.map +3 -3
  54. package/dist/gpu-core/index.d.ts +4 -0
  55. package/dist/gpu-core/index.d.ts.map +1 -1
  56. package/dist/gpu-core/index.js +2 -0
  57. package/dist/gpu-core/index.js.map +1 -1
  58. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.cjs +6 -6
  59. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts +1 -1
  60. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts.map +1 -1
  61. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js +6 -6
  62. package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js.map +1 -1
  63. package/dist/gpu-dataframe/gpu-data-frame-query.cjs +55 -14
  64. package/dist/gpu-dataframe/gpu-data-frame-query.d.ts +13 -2
  65. package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
  66. package/dist/gpu-dataframe/gpu-data-frame-query.js +58 -17
  67. package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
  68. package/dist/gpu-dataframe/gpu-data-frame.cjs +1 -3
  69. package/dist/gpu-dataframe/gpu-data-frame.d.ts +10 -0
  70. package/dist/gpu-dataframe/gpu-data-frame.d.ts.map +1 -1
  71. package/dist/gpu-dataframe/gpu-data-frame.js +1 -3
  72. package/dist/gpu-dataframe/gpu-data-frame.js.map +1 -1
  73. package/dist/gpu-dataframe/gpu-expression-shader.cjs +94 -44
  74. package/dist/gpu-dataframe/gpu-expression-shader.d.ts +8 -5
  75. package/dist/gpu-dataframe/gpu-expression-shader.d.ts.map +1 -1
  76. package/dist/gpu-dataframe/gpu-expression-shader.js +110 -47
  77. package/dist/gpu-dataframe/gpu-expression-shader.js.map +1 -1
  78. package/dist/gpu-dataframe/gpu-expression.cjs +14 -8
  79. package/dist/gpu-dataframe/gpu-expression.d.ts +12 -1
  80. package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
  81. package/dist/gpu-dataframe/gpu-expression.js +11 -6
  82. package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
  83. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.cjs +8 -4
  84. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts +2 -1
  85. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts.map +1 -1
  86. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js +10 -4
  87. package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js.map +1 -1
  88. package/dist/gpu-dataframe/gpu-global-aggregation-query.cjs +2 -2
  89. package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts +5 -1
  90. package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts.map +1 -1
  91. package/dist/gpu-dataframe/gpu-global-aggregation-query.js +6 -2
  92. package/dist/gpu-dataframe/gpu-global-aggregation-query.js.map +1 -1
  93. package/dist/gpu-dataframe/gpu-global-sort-compiler.cjs +156 -124
  94. package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts +12 -2
  95. package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts.map +1 -1
  96. package/dist/gpu-dataframe/gpu-global-sort-compiler.js +160 -128
  97. package/dist/gpu-dataframe/gpu-global-sort-compiler.js.map +1 -1
  98. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.cjs +366 -53
  99. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts +26 -4
  100. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts.map +1 -1
  101. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js +378 -47
  102. package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js.map +1 -1
  103. package/dist/gpu-dataframe/gpu-group-by-query.cjs +20 -9
  104. package/dist/gpu-dataframe/gpu-group-by-query.d.ts +15 -2
  105. package/dist/gpu-dataframe/gpu-group-by-query.d.ts.map +1 -1
  106. package/dist/gpu-dataframe/gpu-group-by-query.js +22 -8
  107. package/dist/gpu-dataframe/gpu-group-by-query.js.map +1 -1
  108. package/dist/gpu-dataframe/gpu-join-compiler.cjs +61 -8
  109. package/dist/gpu-dataframe/gpu-join-compiler.d.ts +10 -2
  110. package/dist/gpu-dataframe/gpu-join-compiler.d.ts.map +1 -1
  111. package/dist/gpu-dataframe/gpu-join-compiler.js +60 -7
  112. package/dist/gpu-dataframe/gpu-join-compiler.js.map +1 -1
  113. package/dist/gpu-dataframe/gpu-query-compiler.cjs +61 -11
  114. package/dist/gpu-dataframe/gpu-query-compiler.d.ts +5 -1
  115. package/dist/gpu-dataframe/gpu-query-compiler.d.ts.map +1 -1
  116. package/dist/gpu-dataframe/gpu-query-compiler.js +61 -10
  117. package/dist/gpu-dataframe/gpu-query-compiler.js.map +1 -1
  118. package/dist/gpu-dataframe/index.cjs +4 -2
  119. package/dist/gpu-dataframe/index.cjs.map +3 -3
  120. package/dist/gpu-dataframe/index.d.ts +1 -1
  121. package/dist/gpu-dataframe/index.d.ts.map +1 -1
  122. package/dist/gpu-dataframe/index.js +1 -1
  123. package/dist/gpu-dataframe/index.js.map +1 -1
  124. package/dist/gpu-graph/index.cjs.map +1 -1
  125. package/dist/gpu-graph-algorithms/benchmarks.cjs.map +2 -2
  126. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.cjs +182 -62
  127. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.d.ts +29 -2
  128. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.d.ts.map +1 -1
  129. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.js +200 -64
  130. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.js.map +1 -1
  131. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.cjs +135 -9
  132. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.d.ts +55 -8
  133. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.d.ts.map +1 -1
  134. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.js +145 -14
  135. package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.js.map +1 -1
  136. package/dist/gpu-graph-algorithms/index.cjs.map +3 -3
  137. package/dist/gpu-physics/articulation-tree-shader.cjs +177 -0
  138. package/dist/gpu-physics/articulation-tree-shader.d.ts +3 -0
  139. package/dist/gpu-physics/articulation-tree-shader.d.ts.map +1 -0
  140. package/dist/gpu-physics/articulation-tree-shader.js +159 -0
  141. package/dist/gpu-physics/articulation-tree-shader.js.map +1 -0
  142. package/dist/gpu-physics/gpu-articulation-tree.cjs +203 -0
  143. package/dist/gpu-physics/gpu-articulation-tree.d.ts +81 -0
  144. package/dist/gpu-physics/gpu-articulation-tree.d.ts.map +1 -0
  145. package/dist/gpu-physics/gpu-articulation-tree.js +205 -0
  146. package/dist/gpu-physics/gpu-articulation-tree.js.map +1 -0
  147. package/dist/gpu-physics/gpu-physics-batch.cjs +11 -10
  148. package/dist/gpu-physics/gpu-physics-batch.d.ts +1 -0
  149. package/dist/gpu-physics/gpu-physics-batch.d.ts.map +1 -1
  150. package/dist/gpu-physics/gpu-physics-batch.js +14 -10
  151. package/dist/gpu-physics/gpu-physics-batch.js.map +1 -1
  152. package/dist/gpu-physics/gpu-physics-ensemble.cjs +9 -4
  153. package/dist/gpu-physics/gpu-physics-ensemble.d.ts +10 -1
  154. package/dist/gpu-physics/gpu-physics-ensemble.d.ts.map +1 -1
  155. package/dist/gpu-physics/gpu-physics-ensemble.js +11 -4
  156. package/dist/gpu-physics/gpu-physics-ensemble.js.map +1 -1
  157. package/dist/gpu-physics/gpu-rigid-body-world.cjs +323 -68
  158. package/dist/gpu-physics/gpu-rigid-body-world.d.ts +59 -2
  159. package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
  160. package/dist/gpu-physics/gpu-rigid-body-world.js +400 -75
  161. package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
  162. package/dist/gpu-physics/index.cjs +3 -0
  163. package/dist/gpu-physics/index.cjs.map +3 -3
  164. package/dist/gpu-physics/index.d.ts +3 -1
  165. package/dist/gpu-physics/index.d.ts.map +1 -1
  166. package/dist/gpu-physics/index.js +1 -0
  167. package/dist/gpu-physics/index.js.map +1 -1
  168. package/dist/gpu-physics/rigid-body-cache-shaders.cjs +10 -6
  169. package/dist/gpu-physics/rigid-body-cache-shaders.d.ts +2 -1
  170. package/dist/gpu-physics/rigid-body-cache-shaders.d.ts.map +1 -1
  171. package/dist/gpu-physics/rigid-body-cache-shaders.js +15 -6
  172. package/dist/gpu-physics/rigid-body-cache-shaders.js.map +1 -1
  173. package/dist/gpu-physics/rigid-body-capacity.cjs +15 -2
  174. package/dist/gpu-physics/rigid-body-capacity.d.ts +3 -1
  175. package/dist/gpu-physics/rigid-body-capacity.d.ts.map +1 -1
  176. package/dist/gpu-physics/rigid-body-capacity.js +21 -2
  177. package/dist/gpu-physics/rigid-body-capacity.js.map +1 -1
  178. package/dist/gpu-physics/rigid-body-cast-index.cjs +192 -0
  179. package/dist/gpu-physics/rigid-body-cast-index.d.ts +44 -0
  180. package/dist/gpu-physics/rigid-body-cast-index.d.ts.map +1 -0
  181. package/dist/gpu-physics/rigid-body-cast-index.js +194 -0
  182. package/dist/gpu-physics/rigid-body-cast-index.js.map +1 -0
  183. package/dist/gpu-physics/rigid-body-ensemble-layout.cjs +4 -2
  184. package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts +2 -1
  185. package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts.map +1 -1
  186. package/dist/gpu-physics/rigid-body-ensemble-layout.js +5 -2
  187. package/dist/gpu-physics/rigid-body-ensemble-layout.js.map +1 -1
  188. package/dist/gpu-physics/rigid-body-ensemble-reset.cjs +11 -9
  189. package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts +1 -1
  190. package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts.map +1 -1
  191. package/dist/gpu-physics/rigid-body-ensemble-reset.js +13 -9
  192. package/dist/gpu-physics/rigid-body-ensemble-reset.js.map +1 -1
  193. package/dist/gpu-physics/rigid-body-ensemble-shaders.cjs +14 -7
  194. package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts +5 -0
  195. package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts.map +1 -1
  196. package/dist/gpu-physics/rigid-body-ensemble-shaders.js +17 -7
  197. package/dist/gpu-physics/rigid-body-ensemble-shaders.js.map +1 -1
  198. package/dist/gpu-physics/rigid-body-ensemble-transaction.cjs +21 -11
  199. package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts +2 -2
  200. package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts.map +1 -1
  201. package/dist/gpu-physics/rigid-body-ensemble-transaction.js +28 -12
  202. package/dist/gpu-physics/rigid-body-ensemble-transaction.js.map +1 -1
  203. package/dist/gpu-physics/rigid-body-event-compaction.cjs +184 -0
  204. package/dist/gpu-physics/rigid-body-event-compaction.d.ts +35 -0
  205. package/dist/gpu-physics/rigid-body-event-compaction.d.ts.map +1 -0
  206. package/dist/gpu-physics/rigid-body-event-compaction.js +168 -0
  207. package/dist/gpu-physics/rigid-body-event-compaction.js.map +1 -0
  208. package/dist/gpu-physics/rigid-body-event-snapshot.cjs +51 -0
  209. package/dist/gpu-physics/rigid-body-event-snapshot.d.ts +33 -0
  210. package/dist/gpu-physics/rigid-body-event-snapshot.d.ts.map +1 -0
  211. package/dist/gpu-physics/rigid-body-event-snapshot.js +34 -0
  212. package/dist/gpu-physics/rigid-body-event-snapshot.js.map +1 -0
  213. package/dist/gpu-physics/rigid-body-events.cjs +57 -25
  214. package/dist/gpu-physics/rigid-body-events.d.ts +2 -1
  215. package/dist/gpu-physics/rigid-body-events.d.ts.map +1 -1
  216. package/dist/gpu-physics/rigid-body-events.js +60 -25
  217. package/dist/gpu-physics/rigid-body-events.js.map +1 -1
  218. package/dist/gpu-physics/rigid-body-joints.cjs +8 -3
  219. package/dist/gpu-physics/rigid-body-joints.d.ts +2 -0
  220. package/dist/gpu-physics/rigid-body-joints.d.ts.map +1 -1
  221. package/dist/gpu-physics/rigid-body-joints.js +10 -6
  222. package/dist/gpu-physics/rigid-body-joints.js.map +1 -1
  223. package/dist/gpu-physics/rigid-body-queries.cjs +159 -16
  224. package/dist/gpu-physics/rigid-body-queries.d.ts +24 -1
  225. package/dist/gpu-physics/rigid-body-queries.d.ts.map +1 -1
  226. package/dist/gpu-physics/rigid-body-queries.js +166 -14
  227. package/dist/gpu-physics/rigid-body-queries.js.map +1 -1
  228. package/dist/gpu-physics/rigid-body-shaders.cjs +3 -3
  229. package/dist/gpu-physics/rigid-body-shaders.d.ts +1 -1
  230. package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
  231. package/dist/gpu-physics/rigid-body-shaders.js +3 -3
  232. package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
  233. package/dist/gpu-physics/rigid-body-triggers.cjs +53 -15
  234. package/dist/gpu-physics/rigid-body-triggers.d.ts +1 -0
  235. package/dist/gpu-physics/rigid-body-triggers.d.ts.map +1 -1
  236. package/dist/gpu-physics/rigid-body-triggers.js +55 -15
  237. package/dist/gpu-physics/rigid-body-triggers.js.map +1 -1
  238. package/dist/gpu-physics/sphere-world-shaders.cjs +48 -20
  239. package/dist/gpu-physics/sphere-world-shaders.d.ts.map +1 -1
  240. package/dist/gpu-physics/sphere-world-shaders.js +51 -21
  241. package/dist/gpu-physics/sphere-world-shaders.js.map +1 -1
  242. package/dist/gpu-project/benchmarks.cjs.map +2 -2
  243. package/dist/gpu-project/crs.cjs.map +2 -2
  244. package/dist/gpu-project/graph.cjs.map +2 -2
  245. package/dist/gpu-project/index.cjs.map +2 -2
  246. package/dist/gpu-project/projection-program.cjs +2 -9
  247. package/dist/gpu-project/projection-program.d.ts.map +1 -1
  248. package/dist/gpu-project/projection-program.js +1 -8
  249. package/dist/gpu-project/projection-program.js.map +1 -1
  250. package/dist/gpu-simple-graph/index.cjs.map +2 -2
  251. package/dist/gpu-sql/gpu-sql.cjs +345 -81
  252. package/dist/gpu-sql/gpu-sql.d.ts +42 -2
  253. package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
  254. package/dist/gpu-sql/gpu-sql.js +393 -90
  255. package/dist/gpu-sql/gpu-sql.js.map +1 -1
  256. package/dist/gpu-sql/index.cjs.map +3 -3
  257. package/dist/gpu-sql/index.d.ts +1 -1
  258. package/dist/gpu-sql/index.d.ts.map +1 -1
  259. package/dist/index.cjs.map +1 -1
  260. package/dist/utils/float32.cjs +35 -0
  261. package/dist/utils/float32.d.ts +3 -0
  262. package/dist/utils/float32.d.ts.map +1 -0
  263. package/dist/utils/float32.js +16 -0
  264. package/dist/utils/float32.js.map +1 -0
  265. package/package.json +8 -8
  266. package/src/arrow/gpu/arrow-gpu-analytics-adapters.ts +77 -25
  267. package/src/arrow/gpu/arrow-gpu-analytics-readback.ts +52 -16
  268. package/src/arrow/gpu/arrow-gpu-table-conversion.ts +130 -31
  269. package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +19 -0
  270. package/src/arrow/index.ts +1 -0
  271. package/src/arrow/vectors/arrow-temporal-gpu-vector.ts +2 -2
  272. package/src/gpu-core/gpu-bvh-bounds.ts +84 -0
  273. package/src/gpu-core/gpu-command-graph-budget-controller.ts +22 -2
  274. package/src/gpu-core/gpu-command-graph-submission-pacer.ts +102 -0
  275. package/src/gpu-core/gpu-group-aggregation.ts +68 -30
  276. package/src/gpu-core/index.ts +5 -0
  277. package/src/gpu-dataframe/gpu-analytics-compiler-utils.ts +7 -10
  278. package/src/gpu-dataframe/gpu-data-frame-query.ts +106 -25
  279. package/src/gpu-dataframe/gpu-data-frame.ts +35 -2
  280. package/src/gpu-dataframe/gpu-expression-shader.ts +172 -58
  281. package/src/gpu-dataframe/gpu-expression.ts +62 -9
  282. package/src/gpu-dataframe/gpu-global-aggregation-compiler.ts +15 -4
  283. package/src/gpu-dataframe/gpu-global-aggregation-query.ts +12 -3
  284. package/src/gpu-dataframe/gpu-global-sort-compiler.ts +231 -156
  285. package/src/gpu-dataframe/gpu-group-aggregation-compiler.ts +645 -61
  286. package/src/gpu-dataframe/gpu-group-by-query.ts +51 -14
  287. package/src/gpu-dataframe/gpu-join-compiler.ts +87 -6
  288. package/src/gpu-dataframe/gpu-query-compiler.ts +100 -18
  289. package/src/gpu-dataframe/index.ts +1 -1
  290. package/src/gpu-graph-algorithms/README.md +4 -2
  291. package/src/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.ts +248 -66
  292. package/src/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.ts +218 -20
  293. package/src/gpu-physics/articulation-tree-shader.ts +169 -0
  294. package/src/gpu-physics/gpu-articulation-tree.ts +279 -0
  295. package/src/gpu-physics/gpu-physics-batch.ts +19 -13
  296. package/src/gpu-physics/gpu-physics-ensemble.ts +20 -4
  297. package/src/gpu-physics/gpu-rigid-body-world.ts +510 -93
  298. package/src/gpu-physics/index.ts +16 -0
  299. package/src/gpu-physics/rigid-body-cache-shaders.ts +18 -6
  300. package/src/gpu-physics/rigid-body-capacity.ts +25 -4
  301. package/src/gpu-physics/rigid-body-cast-index.ts +277 -0
  302. package/src/gpu-physics/rigid-body-ensemble-layout.ts +6 -2
  303. package/src/gpu-physics/rigid-body-ensemble-reset.ts +21 -9
  304. package/src/gpu-physics/rigid-body-ensemble-shaders.ts +18 -7
  305. package/src/gpu-physics/rigid-body-ensemble-transaction.ts +31 -13
  306. package/src/gpu-physics/rigid-body-event-compaction.ts +252 -0
  307. package/src/gpu-physics/rigid-body-event-snapshot.ts +76 -0
  308. package/src/gpu-physics/rigid-body-events.ts +63 -25
  309. package/src/gpu-physics/rigid-body-joints.ts +11 -11
  310. package/src/gpu-physics/rigid-body-queries.ts +202 -14
  311. package/src/gpu-physics/rigid-body-shaders.ts +4 -3
  312. package/src/gpu-physics/rigid-body-triggers.ts +64 -20
  313. package/src/gpu-physics/sphere-world-shaders.ts +53 -21
  314. package/src/gpu-project/projection-program.ts +1 -9
  315. package/src/gpu-sql/gpu-sql.ts +629 -124
  316. package/src/gpu-sql/index.ts +1 -1
  317. package/src/utils/float32.ts +16 -0
@@ -6,8 +6,23 @@
6
6
  import {parseSQLSelectStatement} from '@math.gl/sql/parser';
7
7
  import type {Expression} from '@math.gl/sql/expressions';
8
8
  import type {GPUCommandGraph} from '@luma.gl/graph/gpu-core';
9
+ import type {GPUTypeMap} from '@luma.gl/graph/gpu-tables';
10
+
9
11
  import {GPUDataFrame} from '../gpu-dataframe/gpu-data-frame';
10
- import {GPUDataFrameQuery} from '../gpu-dataframe/gpu-data-frame-query';
12
+ import {
13
+ GPUDataFrameQuery,
14
+ type GPUDataFrameDerivedColumn
15
+ } from '../gpu-dataframe/gpu-data-frame-query';
16
+ import {
17
+ compileGPUDataFrameGroupedAggregation,
18
+ compileGPUDataFrameObservedAggregation
19
+ } from '../gpu-dataframe/gpu-group-aggregation-compiler';
20
+ import {normalizeGPUDataFrameAggregations} from '../gpu-dataframe/gpu-group-by-query';
21
+ import {
22
+ compileGPUDataFrameGlobalSort,
23
+ type GPUGlobalSortKey
24
+ } from '../gpu-dataframe/gpu-global-sort-compiler';
25
+ import type {GPUDataFrameNormalizedSortOptions} from '../gpu-dataframe/gpu-sort-query';
11
26
  import {
12
27
  GPUExpression,
13
28
  column,
@@ -16,7 +31,13 @@ import {
16
31
  type GPUExpressionNode
17
32
  } from '../gpu-dataframe/gpu-expression';
18
33
  import {lowerPortableExpression} from '../gpu-dataframe/portable-expression';
19
- import type {GPUDataFrameJoinType} from '../gpu-dataframe/gpu-join-query';
34
+ import {compileGPUDataFrameAggregation} from '../gpu-dataframe/gpu-global-aggregation-compiler';
35
+ import type {GPUDataFrameAggregationDefinition} from '../gpu-dataframe/gpu-group-by-query';
36
+ import {compileGPUDataFrameJoin, type GPUAggregateJoin} from '../gpu-dataframe/gpu-join-compiler';
37
+ import type {
38
+ GPUDataFrameJoinType,
39
+ GPUDataFrameNormalizedJoinOptions
40
+ } from '../gpu-dataframe/gpu-join-query';
20
41
  import type {
21
42
  CompiledGPUDataFrameQuery,
22
43
  GPUDataFrameQueryParameters
@@ -25,16 +46,23 @@ import type {
25
46
  /** Explicit GPU dataframe registrations; Arrow remains exclusively an adapter boundary. */
26
47
  export type GPUSQLTables = Readonly<Record<string, GPUDataFrame>>;
27
48
 
28
- /** Defaults for named SQL parameters such as `:minimumFare`; values remain caller-controlled. */
29
- export type GPUSQLQueryOptions = Readonly<{parameters?: GPUDataFrameQueryParameters}>;
49
+ /** Configuration for GPU-only SQL planning. */
50
+ export type GPUSQLQueryOptions = Readonly<{
51
+ /** Defaults for named SQL parameters such as :minimumFare. */
52
+ parameters?: GPUDataFrameQueryParameters;
53
+ /** Maximum temporary count bytes per grouped AVG operation. */
54
+ maxMeanScratchBytes?: number;
55
+ }>;
30
56
 
31
57
  /** A source column name with its optional, separately parsed table qualifier. */
32
58
  type GPUSQLColumnReference = Readonly<{name: string; qualifier?: string}>;
33
59
 
60
+ /** A bound-column spelling or a one-based SELECT position. */
61
+
34
62
  type GPUSQLSelectItem = Readonly<{
35
63
  expression?: Expression;
36
64
  aggregate?: 'count' | 'sum' | 'min' | 'max' | 'mean';
37
- aggregateColumn?: GPUSQLColumnReference;
65
+ aggregateInput?: Expression;
38
66
  alias?: string;
39
67
  star?: boolean;
40
68
  }>;
@@ -50,27 +78,72 @@ type GPUSQLStatement = Readonly<{
50
78
  right: GPUSQLColumnReference;
51
79
  }>;
52
80
  predicate?: Expression;
53
- groupBy?: GPUSQLColumnReference;
54
- orderBy?: Readonly<{
55
- column: GPUSQLColumnReference;
81
+ groupBy?: readonly Expression[];
82
+ having?: Expression;
83
+ orderBy?: readonly Readonly<{
84
+ expression: Expression;
56
85
  direction: 'ascending' | 'descending';
57
86
  nulls?: 'first' | 'last';
58
- }>;
87
+ }>[];
59
88
  limit?: number;
60
89
  offset?: number;
61
90
  }>;
62
91
 
92
+ /** Execution route selected by the GPU SQL planner. */
93
+ export type GPUSQLExecution =
94
+ | 'projection'
95
+ | 'global-sort'
96
+ | 'global-aggregation'
97
+ | 'dense-grouping'
98
+ | 'observed-grouping'
99
+ | 'unique-right-join';
100
+
101
+ /** CPU-only description of the bound GPU SQL plan. */
102
+ export type GPUSQLExplanation = Readonly<{
103
+ /** Registered input table. */
104
+ table: string;
105
+ /** Whether a source-row WHERE predicate runs before the terminal operation. */
106
+ filtered: boolean;
107
+ /** A post-aggregation HAVING predicate filters the grouped result. */
108
+ having?: true;
109
+ /** Terminal GPU dataframe execution route. */
110
+ execution: GPUSQLExecution;
111
+ /** Result fields in SELECT order. */
112
+ columns: readonly string[];
113
+ /** Columns used internally, including derived or hidden keys when applicable. */
114
+ workingColumns: readonly string[];
115
+ /** Number of resolved grouping or ordering keys. */
116
+ keyCount: number;
117
+ /** Registered right table and join type for join plans. */
118
+ join?: Readonly<{table: string; type: GPUDataFrameJoinType}>;
119
+ /** Applied global page bounds, when supplied. */
120
+ page?: Readonly<{offset: number; limit?: number}>;
121
+ }>;
122
+
123
+ /** Binds executable operations to the immutable description produced at planning time. */
124
+ type GPUSQLBoundPlan = {plan: GPUSQLCompiledPlan; explanation: GPUSQLExplanation};
125
+
63
126
  type GPUSQLCompiledPlan = Readonly<{
64
127
  compile: (graph: GPUCommandGraph<GPUDataFrameQueryParameters>) => CompiledGPUDataFrameQuery;
65
128
  }>;
66
129
 
67
130
  type GPUSQLAggregationDefinitions = Record<
68
131
  string,
69
- 'count' | {sum: string} | {min: string} | {max: string} | {mean: string}
132
+ 'count' | {count: string} | {sum: string} | {min: string} | {max: string} | {mean: string}
70
133
  >;
71
134
 
135
+ /** Existing global-sort plan and its already-validated controls. */
136
+ type GPUSQLSortPlan = GPUSQLCompiledPlan & {readonly options: GPUDataFrameNormalizedSortOptions};
137
+
138
+ /** Validated join plan with normalized key and hash-index controls. */
139
+
140
+ type GPUSQLJoinPlan = GPUSQLCompiledPlan & {readonly options: GPUDataFrameNormalizedJoinOptions};
141
+
72
142
  /** Runtime-validated SQL names cross the strongly typed dataframe boundary exactly once. */
73
143
  type GPUSQLDynamicQuery = GPUSQLCompiledPlan & {
144
+ readonly selectedColumns: readonly string[];
145
+ readonly predicates: readonly GPUExpression<boolean, string>[];
146
+ readonly derivedColumns: readonly GPUDataFrameDerivedColumn[];
74
147
  filter: (predicate: GPUExpression<boolean, string>) => GPUSQLDynamicQuery;
75
148
  select: (names: readonly string[]) => GPUSQLDynamicQuery;
76
149
  withColumn: (
@@ -78,20 +151,19 @@ type GPUSQLDynamicQuery = GPUSQLCompiledPlan & {
78
151
  expression: GPUExpression<number | null, string>
79
152
  ) => GPUSQLDynamicQuery;
80
153
  groupBy: (key: string) => {
81
- aggregate: (definitions: GPUSQLAggregationDefinitions) => GPUSQLCompiledPlan;
154
+ readonly groupCount: number;
82
155
  };
83
- aggregate: (definitions: GPUSQLAggregationDefinitions) => GPUSQLCompiledPlan;
156
+ aggregate: (
157
+ definitions: GPUSQLAggregationDefinitions
158
+ ) => GPUSQLCompiledPlan & {readonly definitions: readonly GPUDataFrameAggregationDefinition[]};
84
159
  sortByGlobal: (
85
160
  name: string,
86
161
  options: {direction: 'ascending' | 'descending'; nulls?: 'first' | 'last'}
87
- ) => GPUSQLCompiledPlan & {page: (offset: number, limit?: number) => GPUSQLCompiledPlan};
88
- innerJoin: (
89
- right: GPUDataFrame,
90
- options: {leftOn: string; rightOn: string}
91
- ) => GPUSQLCompiledPlan;
92
- leftJoin: (right: GPUDataFrame, options: {leftOn: string; rightOn: string}) => GPUSQLCompiledPlan;
93
- semiJoin: (right: GPUDataFrame, options: {leftOn: string; rightOn: string}) => GPUSQLCompiledPlan;
94
- antiJoin: (right: GPUDataFrame, options: {leftOn: string; rightOn: string}) => GPUSQLCompiledPlan;
162
+ ) => GPUSQLSortPlan & {page: (offset: number, limit?: number) => GPUSQLSortPlan};
163
+ innerJoin: (right: GPUDataFrame, options: {leftOn: string; rightOn: string}) => GPUSQLJoinPlan;
164
+ leftJoin: (right: GPUDataFrame, options: {leftOn: string; rightOn: string}) => GPUSQLJoinPlan;
165
+ semiJoin: (right: GPUDataFrame, options: {leftOn: string; rightOn: string}) => GPUSQLJoinPlan;
166
+ antiJoin: (right: GPUDataFrame, options: {leftOn: string; rightOn: string}) => GPUSQLJoinPlan;
95
167
  };
96
168
 
97
169
  /**
@@ -122,7 +194,7 @@ export class GPUSQLContext {
122
194
  const statement = parseGPUSQLStatement(source);
123
195
  return new GPUSQLQuery(
124
196
  source,
125
- buildGPUSQLPlan(this.tables, statement, options.parameters ?? {})
197
+ buildGPUSQLPlan(this.tables, statement, options.parameters ?? {}, options.maxMeanScratchBytes)
126
198
  );
127
199
  }
128
200
  }
@@ -131,26 +203,32 @@ export class GPUSQLContext {
131
203
  export class GPUSQLQuery {
132
204
  /** Original application-owned SQL text, retained solely for diagnostics and inspection. */
133
205
  readonly sql: string;
134
- private readonly plan: GPUSQLCompiledPlan;
206
+ private readonly plan: GPUSQLBoundPlan;
135
207
 
136
208
  /** @internal */
137
- constructor(sql: string, plan: GPUSQLCompiledPlan) {
209
+ constructor(sql: string, plan: GPUSQLBoundPlan) {
138
210
  this.sql = sql;
139
211
  this.plan = plan;
140
212
  Object.freeze(this);
141
213
  }
142
214
 
215
+ /** Returns a frozen plan description without allocating GPU resources. */
216
+ explain(): GPUSQLExplanation {
217
+ return this.plan.explanation;
218
+ }
219
+
143
220
  /** Compiles existing dataframe operations into the caller-owned GPU command graph. */
144
221
  compile(graph: GPUCommandGraph<GPUDataFrameQueryParameters>): CompiledGPUDataFrameQuery {
145
- return this.plan.compile(graph);
222
+ return this.plan.plan.compile(graph);
146
223
  }
147
224
  }
148
225
 
149
226
  function buildGPUSQLPlan(
150
227
  tables: Readonly<Record<string, GPUDataFrame>>,
151
228
  statement: GPUSQLStatement,
152
- parameters: GPUDataFrameQueryParameters
153
- ): GPUSQLCompiledPlan {
229
+ parameters: GPUDataFrameQueryParameters,
230
+ maxMeanScratchBytes?: number
231
+ ): GPUSQLBoundPlan {
154
232
  const frame = tables[statement.table.toLowerCase()];
155
233
  if (!frame) throw new Error(`GPUSQL table "${statement.table}" is not registered`);
156
234
  let query = new GPUDataFrameQuery(frame, [], frame.columnNames) as unknown as GPUSQLDynamicQuery;
@@ -165,47 +243,375 @@ function buildGPUSQLPlan(
165
243
  );
166
244
  }
167
245
 
246
+ /** Captures the route chosen by the same branch that supplies the executable plan. */
247
+ const describe = (
248
+ plan: GPUSQLCompiledPlan,
249
+ execution: GPUSQLExecution,
250
+ columns: readonly string[],
251
+ workingColumns: readonly string[] = columns,
252
+ keyCount = 0
253
+ ): GPUSQLBoundPlan => ({
254
+ plan,
255
+ explanation: Object.freeze({
256
+ table: statement.table,
257
+ filtered: Boolean(statement.predicate),
258
+ ...(statement.having ? {having: true as const} : {}),
259
+ execution,
260
+ columns: Object.freeze([...columns]),
261
+ workingColumns: Object.freeze([...workingColumns]),
262
+ keyCount,
263
+ ...(statement.join
264
+ ? {join: Object.freeze({table: statement.join.table, type: statement.join.type})}
265
+ : {}),
266
+ ...(statement.limit !== undefined || statement.offset !== undefined
267
+ ? {page: Object.freeze({offset: statement.offset ?? 0, limit: statement.limit})}
268
+ : {})
269
+ })
270
+ });
271
+
272
+ /** Binds a single equality join for row-returning and aggregate plans. */
273
+ const bindJoin = (join: NonNullable<GPUSQLStatement['join']>) => {
274
+ const right = tables[join.table.toLowerCase()];
275
+ if (!right) throw new Error(`GPUSQL table "${join.table}" is not registered`);
276
+ const rightQualifier = join.alias ?? join.table;
277
+ const {left: firstOperand, right: secondOperand} = join;
278
+ const matchesLeft = (reference: GPUSQLColumnReference) =>
279
+ matchesGPUSQLColumn(reference, qualifier, frame.columnNames);
280
+ const matchesRight = (reference: GPUSQLColumnReference) =>
281
+ matchesGPUSQLColumn(reference, rightQualifier, right.columnNames);
282
+ const forward = matchesLeft(firstOperand) && matchesRight(secondOperand);
283
+ const reversed = matchesLeft(secondOperand) && matchesRight(firstOperand);
284
+ if (forward && reversed) {
285
+ throw new Error('GPUSQL JOIN key references are ambiguous; qualify the columns');
286
+ }
287
+ const leftKey = resolve(reversed ? secondOperand : firstOperand);
288
+ const rightKey = resolveGPUSQLColumn(
289
+ reversed ? firstOperand : secondOperand,
290
+ rightQualifier,
291
+ right.columnNames
292
+ );
293
+ return {right, leftKey, rightKey};
294
+ };
295
+ const joinMethods = {
296
+ left: 'leftJoin',
297
+ semi: 'semiJoin',
298
+ anti: 'antiJoin',
299
+ inner: 'innerJoin'
300
+ } as const;
301
+
168
302
  const aggregates = statement.items.filter(item => item.aggregate);
169
- if (aggregates.length > 0) {
303
+ if (statement.having && !statement.groupBy) {
304
+ throw new Error('GPUSQL HAVING requires GROUP BY');
305
+ }
306
+ if (aggregates.length > 0 || statement.having || (statement.groupBy && statement.orderBy)) {
170
307
  if (
171
- statement.join ||
172
- statement.orderBy ||
173
- statement.limit !== undefined ||
174
- statement.offset !== undefined
308
+ !statement.groupBy &&
309
+ (statement.orderBy || statement.limit !== undefined || statement.offset !== undefined)
175
310
  ) {
176
- throw new Error('GPUSQL aggregate queries do not yet support joins, ordering, or pagination');
311
+ throw new Error(
312
+ 'GPUSQL aggregate queries without GROUP BY do not yet support ordering or pagination'
313
+ );
177
314
  }
178
- const definitions: GPUSQLAggregationDefinitions = {};
179
- for (const item of aggregates) {
180
- const inputColumn = item.aggregateColumn && resolve(item.aggregateColumn);
181
- const name = item.alias ?? `${item.aggregate}_${inputColumn ?? 'all'}`;
182
- if (definitions[name]) throw new Error(`GPUSQL aggregate alias "${name}" is duplicated`);
315
+ let aggregateJoin: GPUAggregateJoin | undefined;
316
+ if (statement.join) {
317
+ const {right, leftKey, rightKey} = bindJoin(statement.join);
318
+ const type = statement.join.type;
319
+ const join = query[joinMethods[type]](right, {leftOn: leftKey, rightOn: rightKey});
320
+ aggregateJoin = {right, type, options: join.options};
321
+ }
322
+ const definitions: GPUSQLAggregationDefinitions = Object.create(null);
323
+ const reservedNames = new Set(frame.columnNames);
324
+ const outputNames = new Map<GPUSQLSelectItem, string>();
325
+ const aggregateOutputs = new Map<string, string>();
326
+ let inputIndex = 0;
327
+ /** Registers an aggregate and materializes its computed input when needed. */
328
+ const registerAggregate = (
329
+ operation: NonNullable<GPUSQLSelectItem['aggregate']>,
330
+ input?: GPUExpressionNode,
331
+ alias?: string
332
+ ): string => {
333
+ let inputColumn = input?.kind === 'column' ? input.name : undefined;
334
+ if (input && input.kind !== 'column') {
335
+ if (!alias)
336
+ throw new Error('GPUSQL computed aggregate inputs require an explicit AS alias');
337
+ do {
338
+ inputColumn = '__sqlAggregateInput' + inputIndex++;
339
+ } while (reservedNames.has(inputColumn));
340
+ reservedNames.add(inputColumn);
341
+ query = query.withColumn(inputColumn, new GPUExpression<number | null, string>(input));
342
+ }
343
+ const name = alias ?? `${operation}_${inputColumn ?? 'all'}`;
344
+ if (Object.hasOwn(definitions, name)) {
345
+ throw new Error(`GPUSQL aggregate alias "${name}" is duplicated`);
346
+ }
347
+ aggregateOutputs.set(JSON.stringify([operation, input ?? null]), name);
183
348
  definitions[name] =
184
- item.aggregate === 'count'
185
- ? 'count'
186
- : ({[item.aggregate!]: inputColumn!} as
349
+ operation === 'count'
350
+ ? inputColumn === undefined
351
+ ? 'count'
352
+ : {count: inputColumn}
353
+ : ({[operation]: inputColumn!} as
187
354
  | {sum: string}
188
355
  | {min: string}
189
356
  | {max: string}
190
357
  | {mean: string});
358
+ return name;
359
+ };
360
+ for (const item of aggregates) {
361
+ const input =
362
+ item.aggregateInput && lowerSQLExpression(item.aggregateInput, parameters, resolve);
363
+ outputNames.set(item, registerAggregate(item.aggregate!, input, item.alias));
191
364
  }
192
- if (statement.groupBy) {
193
- const key = resolve(statement.groupBy);
194
- const nonAggregates = statement.items.filter(item => !item.aggregate);
365
+ if (statement.groupBy !== undefined) {
195
366
  if (
196
- nonAggregates.length !== 1 ||
197
- resolveGPUSQLProjectionName(nonAggregates[0], resolve) !== key
367
+ maxMeanScratchBytes !== undefined &&
368
+ (!Number.isSafeInteger(maxMeanScratchBytes) || maxMeanScratchBytes < 4)
198
369
  ) {
199
- throw new Error('GPUSQL grouped queries must select their single GROUP BY key');
370
+ throw new Error('GPUSQL mean scratch budget requires at least four bytes');
371
+ }
372
+ const keyItems = statement.items.filter(item => !item.aggregate);
373
+ const occupied = new Set(Object.keys(definitions));
374
+ const selectedKeys = new Map<string, {source: string; output: string}>();
375
+ const keyByItem = new Map<GPUSQLSelectItem, {source: string; output: string}>();
376
+ /** Reuses a source field or creates an internal column for a computed group key. */
377
+
378
+ const materializeKey = (expression: GPUExpressionNode): string => {
379
+ if (expression.kind === 'column') return expression.name;
380
+ let source: string;
381
+ do {
382
+ source = '__sqlGroupKey' + inputIndex++;
383
+ } while (reservedNames.has(source));
384
+ reservedNames.add(source);
385
+ query = query.withColumn(source, new GPUExpression<number | null, string>(expression));
386
+ return source;
387
+ };
388
+ for (const item of keyItems) {
389
+ if (!item.expression) {
390
+ throw new Error('GPUSQL grouped SELECT requires explicit key expressions');
391
+ }
392
+ const expression = lowerSQLExpression(item.expression, parameters, resolve);
393
+ const output = item.alias ?? (expression.kind === 'column' ? expression.name : undefined);
394
+ if (!output) throw new Error('GPUSQL computed group keys require an explicit AS alias');
395
+ if (occupied.has(output)) {
396
+ throw new Error('GPUSQL output column "' + output + '" is duplicated');
397
+ }
398
+ const signature = JSON.stringify(expression);
399
+ if (selectedKeys.has(signature)) {
400
+ throw new Error('GPUSQL grouped queries must select each GROUP BY key exactly once');
401
+ }
402
+ const key = {source: materializeKey(expression), output};
403
+ selectedKeys.set(signature, key);
404
+ keyByItem.set(item, key);
405
+ occupied.add(output);
406
+ outputNames.set(item, output);
407
+ }
408
+
409
+ const hiddenKeys = new Map<string, {source: string}>();
410
+ const keys = statement.groupBy.map<{source: string; output?: string}>(reference => {
411
+ if (reference.type === 'Literal' && typeof reference.value === 'number') {
412
+ const item = getGPUSQLProjectionItem(statement.items, reference.value, 'GROUP BY');
413
+ const key = keyByItem.get(item);
414
+ if (!key) throw new Error('GPUSQL GROUP BY position must reference a group key directly');
415
+ return key;
416
+ }
417
+ if (
418
+ reference.type === 'Identifier' &&
419
+ !('gpuSQLParameter' in reference) &&
420
+ !frame.columnNames.includes(reference.name)
421
+ ) {
422
+ const alias = keyItems.find(item => item.alias === reference.name);
423
+ if (alias) return keyByItem.get(alias)!;
424
+ }
425
+ const expression = lowerSQLExpression(reference, parameters, resolve);
426
+ const signature = JSON.stringify(expression);
427
+ const existing = selectedKeys.get(signature) ?? hiddenKeys.get(signature);
428
+ if (existing) return existing;
429
+ const key = {source: materializeKey(expression)};
430
+ hiddenKeys.set(signature, key);
431
+ return key;
432
+ });
433
+ const uniqueKeys = new Set(keys);
434
+ if (uniqueKeys.size !== keys.length) {
435
+ throw new Error('GPUSQL GROUP BY keys must be distinct');
436
+ }
437
+ if ([...selectedKeys.values()].some(key => !uniqueKeys.has(key))) {
438
+ throw new Error(
439
+ 'GPUSQL grouped queries must group by every non-aggregate SELECT expression'
440
+ );
200
441
  }
201
- return query.groupBy(key).aggregate(definitions);
442
+
443
+ const columns = statement.items.map(item => outputNames.get(item)!);
444
+ if (!statement.orderBy && (statement.limit !== undefined || statement.offset !== undefined)) {
445
+ throw new Error('GPUSQL LIMIT or OFFSET currently requires ORDER BY');
446
+ }
447
+ /** Resolves or registers an aggregate used by a post-group clause. */
448
+ const bindAggregateCall = (call: Extract<Expression, {type: 'CallExpression'}>) => {
449
+ const name =
450
+ call.callee.type === 'Identifier' ? String(call.callee['name']).toLowerCase() : '';
451
+ const operation = name === 'avg' ? 'mean' : name;
452
+ if (
453
+ operation !== 'count' &&
454
+ operation !== 'sum' &&
455
+ operation !== 'min' &&
456
+ operation !== 'max' &&
457
+ operation !== 'mean'
458
+ )
459
+ return undefined;
460
+ if (call.arguments.length !== 1) throw new Error('GPUSQL aggregates require one argument');
461
+ const argument = call.arguments[0] as Expression;
462
+ const wildcard = argument.type === 'Identifier' && argument['sqlWildcard'] === true;
463
+ if (wildcard && operation !== 'count') {
464
+ throw new Error('GPUSQL only permits COUNT(*) as a wildcard aggregation');
465
+ }
466
+ const input = wildcard ? undefined : lowerSQLExpression(argument, parameters, resolve);
467
+ const output = aggregateOutputs.get(JSON.stringify([operation, input ?? null]));
468
+ if (output !== undefined) return column(output).node;
469
+ let hiddenName: string;
470
+ do {
471
+ hiddenName = '__sqlPostGroupAggregate' + inputIndex++;
472
+ } while (occupied.has(hiddenName));
473
+ occupied.add(hiddenName);
474
+ return column(registerAggregate(operation, input, hiddenName)).node;
475
+ };
476
+ const having = statement.having
477
+ ? new GPUExpression<boolean, string>(
478
+ lowerSQLExpression(
479
+ statement.having,
480
+ parameters,
481
+ reference => resolveGPUSQLColumn(reference, '', columns),
482
+ bindAggregateCall
483
+ )
484
+ )
485
+ : undefined;
486
+ const ordering: GPUGlobalSortKey[] | undefined = statement.orderBy?.map(
487
+ ({expression, direction, nulls}, index) => {
488
+ const column =
489
+ expression.type === 'Literal' && typeof expression.value === 'number'
490
+ ? getGPUSQLProjectionItem(columns, expression.value, 'ORDER BY')
491
+ : expression.type === 'Identifier' && !('gpuSQLParameter' in expression)
492
+ ? expression.name
493
+ : undefined;
494
+ const aggregate =
495
+ expression.type === 'CallExpression' ? bindAggregateCall(expression) : undefined;
496
+ const sortColumn = aggregate?.kind === 'column' ? aggregate.name : column;
497
+ if (sortColumn === undefined || (!aggregate && !columns.includes(sortColumn))) {
498
+ throw new Error(
499
+ 'GPUSQL grouped ORDER BY requires a SELECT output name, position, or aggregate call'
500
+ );
501
+ }
502
+ return {
503
+ column: sortColumn,
504
+ options: {
505
+ direction,
506
+ nulls: nulls ?? 'last',
507
+ nans: 'last',
508
+ algorithm: 'auto',
509
+ ...(index === 0 ? {limit: statement.limit, offset: statement.offset} : {})
510
+ }
511
+ };
512
+ }
513
+ );
514
+ const {predicates, selectedColumns, derivedColumns} = query;
515
+ if (Object.keys(definitions).length === 0) {
516
+ throw new Error('GPUSQL GROUP BY requires at least one aggregation');
517
+ }
518
+ const normalized = normalizeGPUDataFrameAggregations<GPUTypeMap, string, GPUTypeMap>(
519
+ {...query, source: frame},
520
+ keys[0].output,
521
+ definitions
522
+ );
523
+
524
+ if (keys.length > 1 || keys[0].output === undefined || !frame.dictionaries[keys[0].source]) {
525
+ for (const {source} of keys) {
526
+ const format = frame.schema.fields.find(field => field.name === source)?.format;
527
+ if (
528
+ !derivedColumns.some(column => column.name === source) &&
529
+ format !== 'uint32' &&
530
+ format !== 'sint32' &&
531
+ format !== 'float32'
532
+ ) {
533
+ throw new Error('GPUSQL GROUP BY requires 32-bit numeric or dictionary keys');
534
+ }
535
+ }
536
+ return describe(
537
+ {
538
+ compile: graph =>
539
+ compileGPUDataFrameObservedAggregation(
540
+ frame,
541
+ predicates,
542
+ selectedColumns,
543
+ derivedColumns,
544
+ keys,
545
+ normalized,
546
+ graph,
547
+ columns,
548
+ ordering,
549
+ having,
550
+ aggregateJoin,
551
+ maxMeanScratchBytes
552
+ )
553
+ },
554
+ 'observed-grouping',
555
+ columns,
556
+ selectedColumns,
557
+ keys.length
558
+ );
559
+ }
560
+
561
+ const [key] = keys;
562
+ const {groupCount} = query.groupBy(key.source);
563
+ return describe(
564
+ {
565
+ compile: graph =>
566
+ compileGPUDataFrameGroupedAggregation(
567
+ frame,
568
+ predicates,
569
+ selectedColumns,
570
+ derivedColumns,
571
+ key.source,
572
+ groupCount,
573
+ normalized,
574
+ graph,
575
+ {key: key.output!, columns},
576
+ ordering,
577
+ having,
578
+ aggregateJoin,
579
+ maxMeanScratchBytes
580
+ )
581
+ },
582
+ 'dense-grouping',
583
+ columns,
584
+ selectedColumns,
585
+ 1
586
+ );
202
587
  }
203
588
  if (aggregates.length !== statement.items.length) {
204
589
  throw new Error('GPUSQL global aggregates cannot mix ordinary source columns');
205
590
  }
206
- return query.aggregate(definitions);
591
+ const aggregate = query.aggregate(definitions);
592
+ const {predicates, selectedColumns, derivedColumns} = query;
593
+ return describe(
594
+ aggregateJoin
595
+ ? {
596
+ compile: graph =>
597
+ compileGPUDataFrameAggregation(
598
+ frame,
599
+ predicates,
600
+ selectedColumns,
601
+ derivedColumns,
602
+ aggregate.definitions,
603
+ graph,
604
+ aggregateJoin
605
+ )
606
+ }
607
+ : aggregate,
608
+ 'global-aggregation',
609
+ statement.items.map(item => outputNames.get(item)!),
610
+ query.selectedColumns
611
+ );
207
612
  }
208
- if (statement.groupBy) throw new Error('GPUSQL GROUP BY requires at least one aggregation');
613
+ if (statement.groupBy !== undefined)
614
+ throw new Error('GPUSQL GROUP BY requires at least one aggregation');
209
615
 
210
616
  const selected: string[] = [];
211
617
  for (const item of statement.items) {
@@ -232,70 +638,112 @@ function buildGPUSQLPlan(
232
638
  if (statement.orderBy || statement.limit !== undefined || statement.offset !== undefined) {
233
639
  throw new Error('GPUSQL joined results do not yet support ORDER BY or pagination');
234
640
  }
235
- const right = tables[statement.join.table.toLowerCase()];
236
- if (!right) throw new Error(`GPUSQL table "${statement.join.table}" is not registered`);
237
- const rightQualifier = statement.join.alias ?? statement.join.table;
238
- const {left: firstOperand, right: secondOperand} = statement.join;
239
- const matchesLeft = (reference: GPUSQLColumnReference) =>
240
- matchesGPUSQLColumn(reference, qualifier, frame.columnNames);
241
- const matchesRight = (reference: GPUSQLColumnReference) =>
242
- matchesGPUSQLColumn(reference, rightQualifier, right.columnNames);
243
- const forward = matchesLeft(firstOperand) && matchesRight(secondOperand);
244
- const reversed = !forward && matchesLeft(secondOperand) && matchesRight(firstOperand);
245
- const leftKey = resolve(reversed ? secondOperand : firstOperand);
246
- const rightKey = resolveGPUSQLColumn(
247
- reversed ? firstOperand : secondOperand,
248
- rightQualifier,
249
- right.columnNames
641
+ const {right, leftKey, rightKey} = bindJoin(statement.join);
642
+ const keyIsSelected = selected.includes(leftKey);
643
+ const workingColumns = keyIsSelected ? selected : [...selected, leftKey];
644
+ const workingQuery = query.select(workingColumns);
645
+ const joinType = statement.join.type;
646
+ const join = workingQuery[joinMethods[joinType]](right, {leftOn: leftKey, rightOn: rightKey});
647
+ if (keyIsSelected) return describe(join, 'unique-right-join', selected, workingColumns, 1);
648
+
649
+ const {predicates, derivedColumns} = workingQuery;
650
+ return describe(
651
+ {
652
+ compile: graph =>
653
+ compileGPUDataFrameJoin(
654
+ frame,
655
+ predicates,
656
+ workingColumns,
657
+ derivedColumns,
658
+ right,
659
+ join.options,
660
+ joinType,
661
+ graph,
662
+ selected
663
+ )
664
+ },
665
+ 'unique-right-join',
666
+ selected,
667
+ workingColumns,
668
+ 1
250
669
  );
251
- if (!selected.includes(leftKey)) {
252
- throw new Error('GPUSQL joins require the left join key to remain selected');
253
- }
254
- query = query.select(selected);
255
- const options = {leftOn: leftKey, rightOn: rightKey};
256
- switch (statement.join.type) {
257
- case 'left':
258
- return query.leftJoin(right, options);
259
- case 'semi':
260
- return query.semiJoin(right, options);
261
- case 'anti':
262
- return query.antiJoin(right, options);
263
- default:
264
- return query.innerJoin(right, options);
265
- }
266
670
  }
267
671
 
268
672
  if (statement.orderBy) {
269
- const {column: requested, direction, nulls} = statement.orderBy;
270
- const orderColumn =
271
- requested.qualifier === undefined && selected.includes(requested.name)
272
- ? requested.name
273
- : resolve(requested);
274
- if (!selected.includes(orderColumn)) {
275
- throw new Error('GPUSQL ORDER BY requires the sort column in the SELECT projection');
276
- }
277
- const sort = query.select(selected).sortByGlobal(orderColumn, {
278
- direction,
279
- ...(nulls ? {nulls} : {})
673
+ const workingColumns = new Set(selected);
674
+ const resolvedKeys = statement.orderBy.map(({expression, direction, nulls}) => {
675
+ let orderColumn: string;
676
+ if (expression.type === 'Literal' && typeof expression.value === 'number') {
677
+ orderColumn = getGPUSQLProjectionItem(selected, expression.value, 'ORDER BY');
678
+ } else if (
679
+ expression.type === 'Identifier' &&
680
+ !('gpuSQLParameter' in expression) &&
681
+ selected.includes(expression.name)
682
+ ) {
683
+ orderColumn = expression.name;
684
+ } else {
685
+ const sortExpression = lowerSQLExpression(expression, parameters, resolve);
686
+ if (sortExpression.kind === 'column') {
687
+ orderColumn = sortExpression.name;
688
+ } else {
689
+ orderColumn = '__sqlOrderKey';
690
+ while (frame.columnNames.includes(orderColumn) || workingColumns.has(orderColumn)) {
691
+ orderColumn += '_';
692
+ }
693
+ query = query.withColumn(
694
+ orderColumn,
695
+ new GPUExpression<number | null, string>(sortExpression)
696
+ );
697
+ }
698
+ }
699
+ workingColumns.add(orderColumn);
700
+ return {column: orderColumn, direction, nulls};
280
701
  });
281
- return statement.limit === undefined && statement.offset === undefined
282
- ? sort
283
- : sort.page(statement.offset ?? 0, statement.limit);
702
+
703
+ const columns = [...workingColumns];
704
+ const workingQuery = query.select(columns);
705
+ const plans = resolvedKeys.map(({column, direction, nulls}) => ({
706
+ column,
707
+ plan: workingQuery.sortByGlobal(column, {direction, nulls})
708
+ }));
709
+ const [{column, plan: sort}, ...secondary] = plans;
710
+ const page =
711
+ statement.limit === undefined && statement.offset === undefined
712
+ ? sort
713
+ : sort.page(statement.offset ?? 0, statement.limit);
714
+ const projection = columns.length > selected.length ? selected : undefined;
715
+ if (!projection && secondary.length === 0)
716
+ return describe(page, 'global-sort', selected, columns, plans.length);
717
+
718
+ const {predicates, derivedColumns} = workingQuery;
719
+ const additionalKeys: GPUGlobalSortKey[] = secondary.map(key => ({
720
+ column: key.column,
721
+ options: key.plan.options
722
+ }));
723
+ return describe(
724
+ {
725
+ compile: graph =>
726
+ compileGPUDataFrameGlobalSort(
727
+ frame,
728
+ predicates,
729
+ columns,
730
+ derivedColumns,
731
+ column,
732
+ page.options,
733
+ graph,
734
+ projection,
735
+ additionalKeys
736
+ )
737
+ },
738
+ 'global-sort',
739
+ selected,
740
+ columns,
741
+ plans.length
742
+ );
284
743
  }
285
744
  if (statement.limit !== undefined || statement.offset !== undefined)
286
745
  throw new Error('GPUSQL LIMIT or OFFSET currently requires ORDER BY');
287
- return query.select(selected);
288
- }
289
-
290
- /** Resolves the only non-aggregate item in a grouped projection. */
291
- function resolveGPUSQLProjectionName(
292
- item: GPUSQLSelectItem,
293
- resolve: (reference: GPUSQLColumnReference) => string
294
- ): string {
295
- if (item.expression?.type !== 'Identifier' && item.expression?.type !== 'MemberExpression') {
296
- throw new Error('GPUSQL grouped source expressions must reference the group key directly');
297
- }
298
- return resolve(readGPUSQLColumn(item.expression));
746
+ return describe(query.select(selected), 'projection', selected);
299
747
  }
300
748
 
301
749
  /** Formats the source spelling for diagnostics. */
@@ -336,21 +784,53 @@ function resolveGPUSQLColumn(
336
784
  return reference.name;
337
785
  }
338
786
 
787
+ /** Isolates the top-level HAVING clause until the shared SELECT parser exposes it. */
788
+ function splitGPUSQLHaving(source: string): {select: string; having?: string} {
789
+ const tokens = /"(?:""|[^"])*"|'(?:''|[^'])*'|:[A-Za-z_]\w*|[A-Za-z_]\w*|[();]|--[^\r\n]*|\/\*/g;
790
+ let depth = 0;
791
+ let start = -1;
792
+ let predicateStart = -1;
793
+ let end = source.length;
794
+ let tailStarted = false;
795
+ for (const token of source.matchAll(tokens)) {
796
+ if (token[0].startsWith('--')) continue;
797
+ if (token[0] === '/*') {
798
+ throw new Error('GPUSQL does not support SQL comments');
799
+ }
800
+ if (token[0] === '(') depth++;
801
+ if (token[0] === ')') depth--;
802
+ if (depth !== 0) continue;
803
+ const keyword = token[0].toUpperCase();
804
+ if (start !== -1 && ['ORDER', 'LIMIT', 'OFFSET', ';'].includes(keyword)) {
805
+ end = token.index;
806
+ break;
807
+ }
808
+ if (start === -1 && ['ORDER', 'LIMIT', 'OFFSET', ';'].includes(keyword)) tailStarted = true;
809
+ if (start === -1 && keyword === 'HAVING') {
810
+ if (tailStarted) throw new Error('GPUSQL HAVING must precede ORDER BY and pagination');
811
+ start = token.index;
812
+ predicateStart = start + token[0].length;
813
+ }
814
+ }
815
+ return start === -1
816
+ ? {select: source}
817
+ : {
818
+ select: source.slice(0, start) + ' ' + source.slice(end),
819
+ having: source.slice(predicateStart, end)
820
+ };
821
+ }
822
+
339
823
  /** Parses the SQL subset supported by the GPU relational planner. */
340
824
  function parseGPUSQLStatement(source: string): GPUSQLStatement {
341
- const statement = parseSQLSelectStatement(source, {
342
- parseParameter: name => ({type: 'Identifier', name, gpuSQLParameter: true})
343
- });
825
+ const {select, having} = splitGPUSQLHaving(source);
826
+ const options = {
827
+ parseParameter: (name: string) => ({type: 'Identifier' as const, name, gpuSQLParameter: true})
828
+ };
829
+ const statement = parseSQLSelectStatement(select, options);
344
830
  if (statement.offset !== undefined && statement.offset > 0xffffffff) {
345
831
  throw new Error('GPUSQL OFFSET must fit an unsigned 32-bit row count');
346
832
  }
347
833
  if (statement.joins.length > 1) throw new Error('GPUSQL currently supports one JOIN');
348
- if ((statement.groupBy?.length ?? 0) > 1) {
349
- throw new Error('GPUSQL currently supports one GROUP BY column');
350
- }
351
- if ((statement.orderBy?.length ?? 0) > 1) {
352
- throw new Error('GPUSQL currently supports one ORDER BY column');
353
- }
354
834
  if (statement.limit !== undefined && statement.limit > 0xffffffff) {
355
835
  throw new Error('GPUSQL LIMIT must fit an unsigned 32-bit row count');
356
836
  }
@@ -369,12 +849,12 @@ function parseGPUSQLStatement(source: string): GPUSQLStatement {
369
849
  }
370
850
  const argument = expression.arguments[0] as Expression;
371
851
  const wildcard = argument.type === 'Identifier' && argument['sqlWildcard'] === true;
372
- if ((aggregate === 'count') !== wildcard) {
852
+ if (wildcard && aggregate !== 'count') {
373
853
  throw new Error('GPUSQL only permits COUNT(*) as a wildcard aggregation');
374
854
  }
375
855
  return {
376
856
  aggregate,
377
- ...(wildcard ? {} : {aggregateColumn: readGPUSQLColumn(argument)}),
857
+ ...(wildcard ? {} : {aggregateInput: argument}),
378
858
  alias
379
859
  };
380
860
  }
@@ -401,24 +881,44 @@ function parseGPUSQLStatement(source: string): GPUSQLStatement {
401
881
  right: readGPUSQLColumn(join.on.right)
402
882
  };
403
883
  }
404
- const sort = statement.orderBy?.[0];
405
884
  return {
406
885
  items,
407
886
  table: statement.from.name,
408
887
  alias: statement.from.alias,
409
888
  join: loweredJoin,
410
889
  predicate: statement.where as Expression | undefined,
411
- groupBy: statement.groupBy?.[0] && readGPUSQLColumn(statement.groupBy[0]),
412
- orderBy: sort && {
413
- column: readGPUSQLColumn(sort.expression),
414
- direction: sort.direction === 'desc' ? 'descending' : 'ascending',
415
- nulls: sort.nulls
416
- },
890
+ having:
891
+ having === undefined
892
+ ? undefined
893
+ : parseSQLSelectStatement('SELECT (' + having + '\n) FROM __gpu_having', options).select![0]
894
+ .expression,
895
+ groupBy: statement.groupBy?.length
896
+ ? statement.groupBy.map(expression => expression as Expression)
897
+ : undefined,
898
+ orderBy: statement.orderBy?.length
899
+ ? statement.orderBy.map(sort => ({
900
+ expression: sort.expression as Expression,
901
+ direction: sort.direction === 'desc' ? 'descending' : 'ascending',
902
+ nulls: sort.nulls
903
+ }))
904
+ : undefined,
417
905
  offset: statement.offset,
418
906
  limit: statement.limit
419
907
  };
420
908
  }
421
909
 
910
+ /** Resolves a one-based projection position with a clause-specific diagnostic. */
911
+ function getGPUSQLProjectionItem<Item>(
912
+ projection: readonly Item[],
913
+ position: number,
914
+ clause: 'ORDER BY' | 'GROUP BY'
915
+ ): Item {
916
+ if (!Number.isSafeInteger(position) || position < 1 || position > projection.length) {
917
+ throw new Error('GPUSQL ' + clause + ' position must be a one-based SELECT column number');
918
+ }
919
+ return projection[position - 1];
920
+ }
921
+
422
922
  /** Reads a source column name or a two-part qualified column reference. */
423
923
  function readGPUSQLColumn(
424
924
  node: Extract<Expression, {type: 'BinaryExpression'}>['left']
@@ -445,7 +945,10 @@ function readGPUSQLColumn(
445
945
  function lowerSQLExpression(
446
946
  node: Extract<Expression, {type: 'BinaryExpression'}>['left'],
447
947
  parameters: GPUDataFrameQueryParameters,
448
- resolve: (reference: GPUSQLColumnReference) => string
948
+ resolve: (reference: GPUSQLColumnReference) => string,
949
+ resolveCall?: (
950
+ call: Extract<Expression, {type: 'CallExpression'}>
951
+ ) => GPUExpressionNode | undefined
449
952
  ): GPUExpressionNode {
450
953
  const expression = node as Expression;
451
954
  try {
@@ -461,6 +964,8 @@ function lowerSQLExpression(
461
964
  return column(resolve(readGPUSQLColumn(leaf))).node;
462
965
  }
463
966
  if (leaf.type === 'CallExpression' && leaf.callee.type === 'Identifier') {
967
+ const replacement = resolveCall?.(leaf);
968
+ if (replacement) return replacement;
464
969
  const name = leaf.callee['name'];
465
970
  const functionName =
466
971
  typeof name === 'string' && leaf['sqlFunction'] === true ? name.toLowerCase() : name;