@nshiab/simple-data-analysis-core 2.0.8 → 2.1.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 (513) hide show
  1. package/esm/class/SDAError.d.ts +6 -6
  2. package/esm/class/SDAError.js +6 -6
  3. package/esm/class/Simple.d.ts +9 -9
  4. package/esm/class/Simple.js +9 -9
  5. package/esm/class/SimpleDB.d.ts +80 -76
  6. package/esm/class/SimpleDB.d.ts.map +1 -1
  7. package/esm/class/SimpleDB.js +80 -76
  8. package/esm/class/SimpleTable.d.ts +2805 -1077
  9. package/esm/class/SimpleTable.d.ts.map +1 -1
  10. package/esm/class/SimpleTable.js +2777 -1077
  11. package/esm/helpers/appendColumnBatches.d.ts +3 -0
  12. package/esm/helpers/appendColumnBatches.d.ts.map +1 -0
  13. package/esm/helpers/appendColumnBatches.js +21 -0
  14. package/esm/helpers/buildApproximateMutualReachabilityMst.d.ts +45 -0
  15. package/esm/helpers/buildApproximateMutualReachabilityMst.d.ts.map +1 -0
  16. package/esm/helpers/buildApproximateMutualReachabilityMst.js +212 -0
  17. package/esm/helpers/buildChronologicalGraphComponentsSql.d.ts +14 -0
  18. package/esm/helpers/buildChronologicalGraphComponentsSql.d.ts.map +1 -0
  19. package/esm/helpers/buildChronologicalGraphComponentsSql.js +167 -0
  20. package/esm/helpers/buildExactMutualReachabilityMst.d.ts +28 -0
  21. package/esm/helpers/buildExactMutualReachabilityMst.d.ts.map +1 -0
  22. package/esm/helpers/buildExactMutualReachabilityMst.js +97 -0
  23. package/esm/helpers/buildGraphTemporalCostStateSql.d.ts +12 -0
  24. package/esm/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -0
  25. package/esm/helpers/buildGraphTemporalCostStateSql.js +86 -0
  26. package/esm/helpers/buildGraphTemporalReachabilitySql.d.ts +13 -0
  27. package/esm/helpers/buildGraphTemporalReachabilitySql.d.ts.map +1 -0
  28. package/esm/helpers/buildGraphTemporalReachabilitySql.js +70 -0
  29. package/esm/helpers/buildSparseMutualReachabilityMst.d.ts +10 -0
  30. package/esm/helpers/buildSparseMutualReachabilityMst.d.ts.map +1 -0
  31. package/esm/helpers/buildSparseMutualReachabilityMst.js +47 -0
  32. package/esm/helpers/buildUmapGraph.d.ts +21 -0
  33. package/esm/helpers/buildUmapGraph.d.ts.map +1 -0
  34. package/esm/helpers/buildUmapGraph.js +61 -0
  35. package/esm/helpers/buildVectorNeighbors.d.ts +45 -0
  36. package/esm/helpers/buildVectorNeighbors.d.ts.map +1 -0
  37. package/esm/helpers/buildVectorNeighbors.js +170 -0
  38. package/esm/helpers/buildWeakGraphComponentsSql.d.ts +3 -0
  39. package/esm/helpers/buildWeakGraphComponentsSql.d.ts.map +1 -0
  40. package/esm/helpers/buildWeakGraphComponentsSql.js +32 -0
  41. package/esm/helpers/cacheDatabase.d.ts.map +1 -1
  42. package/esm/helpers/cacheDatabase.js +2 -1
  43. package/esm/helpers/camelCase.d.ts +7 -5
  44. package/esm/helpers/camelCase.d.ts.map +1 -1
  45. package/esm/helpers/camelCase.js +7 -5
  46. package/esm/helpers/capitalize.d.ts +6 -4
  47. package/esm/helpers/capitalize.d.ts.map +1 -1
  48. package/esm/helpers/capitalize.js +6 -4
  49. package/esm/helpers/clusterHdbscan.d.ts +18 -0
  50. package/esm/helpers/clusterHdbscan.d.ts.map +1 -0
  51. package/esm/helpers/clusterHdbscan.js +342 -0
  52. package/esm/helpers/computeCovariance.d.ts +16 -0
  53. package/esm/helpers/computeCovariance.d.ts.map +1 -0
  54. package/esm/helpers/computeCovariance.js +99 -0
  55. package/esm/helpers/computeMahalanobisDistances.d.ts +14 -0
  56. package/esm/helpers/computeMahalanobisDistances.d.ts.map +1 -0
  57. package/esm/helpers/computeMahalanobisDistances.js +87 -0
  58. package/esm/helpers/createDirectory.d.ts +4 -3
  59. package/esm/helpers/createDirectory.d.ts.map +1 -1
  60. package/esm/helpers/createDirectory.js +4 -3
  61. package/esm/helpers/dataToArrays.d.ts +6 -4
  62. package/esm/helpers/dataToArrays.d.ts.map +1 -1
  63. package/esm/helpers/dataToArrays.js +6 -4
  64. package/esm/helpers/extractTypes.d.ts +1 -1
  65. package/esm/helpers/extractTypes.js +4 -9
  66. package/esm/helpers/factorCovariance.d.ts +17 -0
  67. package/esm/helpers/factorCovariance.d.ts.map +1 -0
  68. package/esm/helpers/factorCovariance.js +189 -0
  69. package/esm/helpers/findGeoColumn.d.ts +6 -4
  70. package/esm/helpers/findGeoColumn.d.ts.map +1 -1
  71. package/esm/helpers/findGeoColumn.js +6 -4
  72. package/esm/helpers/findGeoColumnFromSchema.d.ts +8 -5
  73. package/esm/helpers/findGeoColumnFromSchema.d.ts.map +1 -1
  74. package/esm/helpers/findGeoColumnFromSchema.js +8 -5
  75. package/esm/helpers/fitUmapCurve.d.ts +2 -0
  76. package/esm/helpers/fitUmapCurve.d.ts.map +1 -0
  77. package/esm/helpers/fitUmapCurve.js +66 -0
  78. package/esm/helpers/formatDate.d.ts +12 -6
  79. package/esm/helpers/formatDate.d.ts.map +1 -1
  80. package/esm/helpers/formatDate.js +12 -6
  81. package/esm/helpers/formatMissingTables.d.ts +8 -5
  82. package/esm/helpers/formatMissingTables.d.ts.map +1 -1
  83. package/esm/helpers/formatMissingTables.js +8 -5
  84. package/esm/helpers/formatNumber.d.ts +19 -10
  85. package/esm/helpers/formatNumber.d.ts.map +1 -1
  86. package/esm/helpers/formatNumber.js +32 -17
  87. package/esm/helpers/getGraphEdgeIdColumn.d.ts +9 -0
  88. package/esm/helpers/getGraphEdgeIdColumn.d.ts.map +1 -0
  89. package/esm/helpers/getGraphEdgeIdColumn.js +25 -0
  90. package/esm/helpers/getGraphEndpointColumns.d.ts +11 -0
  91. package/esm/helpers/getGraphEndpointColumns.d.ts.map +1 -0
  92. package/esm/helpers/getGraphEndpointColumns.js +160 -0
  93. package/esm/helpers/getGraphWeightColumn.d.ts +10 -0
  94. package/esm/helpers/getGraphWeightColumn.d.ts.map +1 -0
  95. package/esm/helpers/getGraphWeightColumn.js +40 -0
  96. package/esm/helpers/graphRouteResultSchema.d.ts +4 -0
  97. package/esm/helpers/graphRouteResultSchema.d.ts.map +1 -0
  98. package/esm/helpers/graphRouteResultSchema.js +12 -0
  99. package/esm/helpers/graphRouteResultSelect.d.ts +4 -0
  100. package/esm/helpers/graphRouteResultSelect.d.ts.map +1 -0
  101. package/esm/helpers/graphRouteResultSelect.js +22 -0
  102. package/esm/helpers/hasGeometryColumn.d.ts +4 -3
  103. package/esm/helpers/hasGeometryColumn.d.ts.map +1 -1
  104. package/esm/helpers/hasGeometryColumn.js +4 -3
  105. package/esm/helpers/initialUmapCoordinates.d.ts +2 -0
  106. package/esm/helpers/initialUmapCoordinates.d.ts.map +1 -0
  107. package/esm/helpers/initialUmapCoordinates.js +5 -0
  108. package/esm/helpers/inspectGraphConnectivity.d.ts +10 -0
  109. package/esm/helpers/inspectGraphConnectivity.d.ts.map +1 -0
  110. package/esm/helpers/inspectGraphConnectivity.js +55 -0
  111. package/esm/helpers/mergeOptions.d.ts +24 -13
  112. package/esm/helpers/mergeOptions.d.ts.map +1 -1
  113. package/esm/helpers/mergeOptions.js +24 -13
  114. package/esm/helpers/optimizeUmapLayout.d.ts +7 -0
  115. package/esm/helpers/optimizeUmapLayout.d.ts.map +1 -0
  116. package/esm/helpers/optimizeUmapLayout.js +93 -0
  117. package/esm/helpers/parseValue.d.ts +6 -4
  118. package/esm/helpers/parseValue.d.ts.map +1 -1
  119. package/esm/helpers/parseValue.js +6 -4
  120. package/esm/helpers/prepareGraphRouteSql.d.ts +31 -0
  121. package/esm/helpers/prepareGraphRouteSql.d.ts.map +1 -0
  122. package/esm/helpers/prepareGraphRouteSql.js +86 -0
  123. package/esm/helpers/prepareGraphStarts.d.ts +9 -0
  124. package/esm/helpers/prepareGraphStarts.d.ts.map +1 -0
  125. package/esm/helpers/prepareGraphStarts.js +68 -0
  126. package/esm/helpers/prepareGraphTemporalSql.d.ts +28 -0
  127. package/esm/helpers/prepareGraphTemporalSql.d.ts.map +1 -0
  128. package/esm/helpers/prepareGraphTemporalSql.js +154 -0
  129. package/esm/helpers/prepareGraphTraversal.d.ts +19 -0
  130. package/esm/helpers/prepareGraphTraversal.d.ts.map +1 -0
  131. package/esm/helpers/prepareGraphTraversal.js +79 -0
  132. package/esm/helpers/prepareNumericFeatures.d.ts +41 -0
  133. package/esm/helpers/prepareNumericFeatures.d.ts.map +1 -0
  134. package/esm/helpers/prepareNumericFeatures.js +210 -0
  135. package/esm/helpers/prepareUmapLayoutOptions.d.ts +14 -0
  136. package/esm/helpers/prepareUmapLayoutOptions.d.ts.map +1 -0
  137. package/esm/helpers/prepareUmapLayoutOptions.js +23 -0
  138. package/esm/helpers/prettyDuration.d.ts +14 -8
  139. package/esm/helpers/prettyDuration.d.ts.map +1 -1
  140. package/esm/helpers/prettyDuration.js +14 -8
  141. package/esm/helpers/printTable.d.ts +18 -13
  142. package/esm/helpers/printTable.d.ts.map +1 -1
  143. package/esm/helpers/printTable.js +18 -13
  144. package/esm/helpers/publishPreparedColumns.d.ts +37 -0
  145. package/esm/helpers/publishPreparedColumns.d.ts.map +1 -0
  146. package/esm/helpers/publishPreparedColumns.js +113 -0
  147. package/esm/helpers/queryDB.d.ts +24 -13
  148. package/esm/helpers/queryDB.d.ts.map +1 -1
  149. package/esm/helpers/queryDB.js +24 -13
  150. package/esm/helpers/queueAsyncBarrier.d.ts +12 -7
  151. package/esm/helpers/queueAsyncBarrier.d.ts.map +1 -1
  152. package/esm/helpers/queueAsyncBarrier.js +12 -7
  153. package/esm/helpers/queueGraphResult.d.ts +18 -0
  154. package/esm/helpers/queueGraphResult.d.ts.map +1 -0
  155. package/esm/helpers/queueGraphResult.js +39 -0
  156. package/esm/helpers/quoteIdentifier.d.ts +4 -3
  157. package/esm/helpers/quoteIdentifier.d.ts.map +1 -1
  158. package/esm/helpers/quoteIdentifier.js +4 -3
  159. package/esm/helpers/quoteQualifiedIdentifier.d.ts +6 -4
  160. package/esm/helpers/quoteQualifiedIdentifier.d.ts.map +1 -1
  161. package/esm/helpers/quoteQualifiedIdentifier.js +6 -4
  162. package/esm/helpers/readScalarNumber.d.ts +3 -0
  163. package/esm/helpers/readScalarNumber.d.ts.map +1 -0
  164. package/esm/helpers/readScalarNumber.js +4 -0
  165. package/esm/helpers/runQuery.d.ts.map +1 -1
  166. package/esm/helpers/runQuery.js +17 -3
  167. package/esm/helpers/selectFuzzyReplacements.d.ts +11 -0
  168. package/esm/helpers/selectFuzzyReplacements.d.ts.map +1 -0
  169. package/esm/helpers/selectFuzzyReplacements.js +124 -0
  170. package/esm/helpers/stabilizeCosineVectors.d.ts +14 -0
  171. package/esm/helpers/stabilizeCosineVectors.d.ts.map +1 -0
  172. package/esm/helpers/stabilizeCosineVectors.js +34 -0
  173. package/esm/helpers/stringToArray.d.ts +4 -3
  174. package/esm/helpers/stringToArray.d.ts.map +1 -1
  175. package/esm/helpers/stringToArray.js +4 -3
  176. package/esm/helpers/umapRandom.d.ts +2 -0
  177. package/esm/helpers/umapRandom.d.ts.map +1 -0
  178. package/esm/helpers/umapRandom.js +10 -0
  179. package/esm/helpers/updateColumnsWithJS.d.ts +12 -6
  180. package/esm/helpers/updateColumnsWithJS.d.ts.map +1 -1
  181. package/esm/helpers/updateColumnsWithJS.js +12 -6
  182. package/esm/helpers/validateGraphRouteResultSchema.d.ts +4 -0
  183. package/esm/helpers/validateGraphRouteResultSchema.d.ts.map +1 -0
  184. package/esm/helpers/validateGraphRouteResultSchema.js +13 -0
  185. package/esm/helpers/validateGraphTemporalEvents.d.ts +7 -0
  186. package/esm/helpers/validateGraphTemporalEvents.d.ts.map +1 -0
  187. package/esm/helpers/validateGraphTemporalEvents.js +47 -0
  188. package/esm/helpers/validateNumericalAnalysis.d.ts +10 -6
  189. package/esm/helpers/validateNumericalAnalysis.d.ts.map +1 -1
  190. package/esm/helpers/validateNumericalAnalysis.js +10 -6
  191. package/esm/helpers/validateVectorRowIds.d.ts +4 -0
  192. package/esm/helpers/validateVectorRowIds.d.ts.map +1 -0
  193. package/esm/helpers/validateVectorRowIds.js +16 -0
  194. package/esm/helpers/vectorDistanceExpression.d.ts +6 -0
  195. package/esm/helpers/vectorDistanceExpression.d.ts.map +1 -0
  196. package/esm/helpers/vectorDistanceExpression.js +11 -0
  197. package/esm/helpers/wrapString.d.ts +10 -7
  198. package/esm/helpers/wrapString.d.ts.map +1 -1
  199. package/esm/helpers/wrapString.js +10 -7
  200. package/esm/methods/addId.d.ts +5 -0
  201. package/esm/methods/addId.d.ts.map +1 -0
  202. package/esm/methods/addId.js +38 -0
  203. package/esm/methods/cache.js +1 -1
  204. package/esm/methods/commonNeighbors.d.ts +10 -0
  205. package/esm/methods/commonNeighbors.d.ts.map +1 -0
  206. package/esm/methods/commonNeighbors.js +101 -0
  207. package/esm/methods/connectedComponents.d.ts +9 -0
  208. package/esm/methods/connectedComponents.d.ts.map +1 -0
  209. package/esm/methods/connectedComponents.js +147 -0
  210. package/esm/methods/degree.d.ts +9 -0
  211. package/esm/methods/degree.d.ts.map +1 -0
  212. package/esm/methods/degree.js +135 -0
  213. package/esm/methods/distances.d.ts +12 -0
  214. package/esm/methods/distances.d.ts.map +1 -0
  215. package/esm/methods/distances.js +164 -0
  216. package/esm/methods/findCycles.d.ts +12 -0
  217. package/esm/methods/findCycles.d.ts.map +1 -0
  218. package/esm/methods/findCycles.js +330 -0
  219. package/esm/methods/fuzzyClean.d.ts.map +1 -1
  220. package/esm/methods/fuzzyClean.js +17 -136
  221. package/esm/methods/fuzzyJoin.js +70 -16
  222. package/esm/methods/getTypes.d.ts +1 -1
  223. package/esm/methods/hdbscan.d.ts +5 -0
  224. package/esm/methods/hdbscan.d.ts.map +1 -0
  225. package/esm/methods/hdbscan.js +208 -0
  226. package/esm/methods/loadArray.d.ts.map +1 -1
  227. package/esm/methods/loadArray.js +3 -20
  228. package/esm/methods/mahalanobis.d.ts +5 -0
  229. package/esm/methods/mahalanobis.d.ts.map +1 -0
  230. package/esm/methods/mahalanobis.js +92 -0
  231. package/esm/methods/neighbors.d.ts +9 -0
  232. package/esm/methods/neighbors.d.ts.map +1 -0
  233. package/esm/methods/neighbors.js +81 -0
  234. package/esm/methods/normalizeVector.d.ts +5 -0
  235. package/esm/methods/normalizeVector.d.ts.map +1 -0
  236. package/esm/methods/normalizeVector.js +132 -0
  237. package/esm/methods/paths.d.ts +12 -0
  238. package/esm/methods/paths.d.ts.map +1 -0
  239. package/esm/methods/paths.js +287 -0
  240. package/esm/methods/reachable.d.ts +11 -0
  241. package/esm/methods/reachable.d.ts.map +1 -0
  242. package/esm/methods/reachable.js +131 -0
  243. package/esm/methods/rowToVector.d.ts +5 -0
  244. package/esm/methods/rowToVector.d.ts.map +1 -0
  245. package/esm/methods/rowToVector.js +77 -0
  246. package/esm/methods/shortestPath.d.ts +12 -0
  247. package/esm/methods/shortestPath.d.ts.map +1 -0
  248. package/esm/methods/shortestPath.js +337 -0
  249. package/esm/methods/topologicalSort.d.ts +7 -0
  250. package/esm/methods/topologicalSort.d.ts.map +1 -0
  251. package/esm/methods/topologicalSort.js +164 -0
  252. package/esm/methods/umap.d.ts +5 -0
  253. package/esm/methods/umap.d.ts.map +1 -0
  254. package/esm/methods/umap.js +156 -0
  255. package/esm/methods/updateWithJS.js +9 -21
  256. package/llm.md +2170 -128
  257. package/llms.txt +1 -1
  258. package/package.json +1 -1
  259. package/script/class/SDAError.d.ts +6 -6
  260. package/script/class/SDAError.js +6 -6
  261. package/script/class/Simple.d.ts +9 -9
  262. package/script/class/Simple.js +9 -9
  263. package/script/class/SimpleDB.d.ts +80 -76
  264. package/script/class/SimpleDB.d.ts.map +1 -1
  265. package/script/class/SimpleDB.js +80 -76
  266. package/script/class/SimpleTable.d.ts +2805 -1077
  267. package/script/class/SimpleTable.d.ts.map +1 -1
  268. package/script/class/SimpleTable.js +2777 -1077
  269. package/script/helpers/appendColumnBatches.d.ts +3 -0
  270. package/script/helpers/appendColumnBatches.d.ts.map +1 -0
  271. package/script/helpers/appendColumnBatches.js +24 -0
  272. package/script/helpers/buildApproximateMutualReachabilityMst.d.ts +45 -0
  273. package/script/helpers/buildApproximateMutualReachabilityMst.d.ts.map +1 -0
  274. package/script/helpers/buildApproximateMutualReachabilityMst.js +219 -0
  275. package/script/helpers/buildChronologicalGraphComponentsSql.d.ts +14 -0
  276. package/script/helpers/buildChronologicalGraphComponentsSql.d.ts.map +1 -0
  277. package/script/helpers/buildChronologicalGraphComponentsSql.js +174 -0
  278. package/script/helpers/buildExactMutualReachabilityMst.d.ts +28 -0
  279. package/script/helpers/buildExactMutualReachabilityMst.d.ts.map +1 -0
  280. package/script/helpers/buildExactMutualReachabilityMst.js +103 -0
  281. package/script/helpers/buildGraphTemporalCostStateSql.d.ts +12 -0
  282. package/script/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -0
  283. package/script/helpers/buildGraphTemporalCostStateSql.js +92 -0
  284. package/script/helpers/buildGraphTemporalReachabilitySql.d.ts +13 -0
  285. package/script/helpers/buildGraphTemporalReachabilitySql.d.ts.map +1 -0
  286. package/script/helpers/buildGraphTemporalReachabilitySql.js +76 -0
  287. package/script/helpers/buildSparseMutualReachabilityMst.d.ts +10 -0
  288. package/script/helpers/buildSparseMutualReachabilityMst.d.ts.map +1 -0
  289. package/script/helpers/buildSparseMutualReachabilityMst.js +50 -0
  290. package/script/helpers/buildUmapGraph.d.ts +21 -0
  291. package/script/helpers/buildUmapGraph.d.ts.map +1 -0
  292. package/script/helpers/buildUmapGraph.js +67 -0
  293. package/script/helpers/buildVectorNeighbors.d.ts +45 -0
  294. package/script/helpers/buildVectorNeighbors.d.ts.map +1 -0
  295. package/script/helpers/buildVectorNeighbors.js +176 -0
  296. package/script/helpers/buildWeakGraphComponentsSql.d.ts +3 -0
  297. package/script/helpers/buildWeakGraphComponentsSql.d.ts.map +1 -0
  298. package/script/helpers/buildWeakGraphComponentsSql.js +38 -0
  299. package/script/helpers/cacheDatabase.d.ts.map +1 -1
  300. package/script/helpers/cacheDatabase.js +2 -1
  301. package/script/helpers/camelCase.d.ts +7 -5
  302. package/script/helpers/camelCase.d.ts.map +1 -1
  303. package/script/helpers/camelCase.js +7 -5
  304. package/script/helpers/capitalize.d.ts +6 -4
  305. package/script/helpers/capitalize.d.ts.map +1 -1
  306. package/script/helpers/capitalize.js +6 -4
  307. package/script/helpers/clusterHdbscan.d.ts +18 -0
  308. package/script/helpers/clusterHdbscan.d.ts.map +1 -0
  309. package/script/helpers/clusterHdbscan.js +346 -0
  310. package/script/helpers/computeCovariance.d.ts +16 -0
  311. package/script/helpers/computeCovariance.d.ts.map +1 -0
  312. package/script/helpers/computeCovariance.js +105 -0
  313. package/script/helpers/computeMahalanobisDistances.d.ts +14 -0
  314. package/script/helpers/computeMahalanobisDistances.d.ts.map +1 -0
  315. package/script/helpers/computeMahalanobisDistances.js +93 -0
  316. package/script/helpers/createDirectory.d.ts +4 -3
  317. package/script/helpers/createDirectory.d.ts.map +1 -1
  318. package/script/helpers/createDirectory.js +4 -3
  319. package/script/helpers/dataToArrays.d.ts +6 -4
  320. package/script/helpers/dataToArrays.d.ts.map +1 -1
  321. package/script/helpers/dataToArrays.js +6 -4
  322. package/script/helpers/extractTypes.d.ts +1 -1
  323. package/script/helpers/extractTypes.js +4 -9
  324. package/script/helpers/factorCovariance.d.ts +17 -0
  325. package/script/helpers/factorCovariance.d.ts.map +1 -0
  326. package/script/helpers/factorCovariance.js +194 -0
  327. package/script/helpers/findGeoColumn.d.ts +6 -4
  328. package/script/helpers/findGeoColumn.d.ts.map +1 -1
  329. package/script/helpers/findGeoColumn.js +6 -4
  330. package/script/helpers/findGeoColumnFromSchema.d.ts +8 -5
  331. package/script/helpers/findGeoColumnFromSchema.d.ts.map +1 -1
  332. package/script/helpers/findGeoColumnFromSchema.js +8 -5
  333. package/script/helpers/fitUmapCurve.d.ts +2 -0
  334. package/script/helpers/fitUmapCurve.d.ts.map +1 -0
  335. package/script/helpers/fitUmapCurve.js +69 -0
  336. package/script/helpers/formatDate.d.ts +12 -6
  337. package/script/helpers/formatDate.d.ts.map +1 -1
  338. package/script/helpers/formatDate.js +12 -6
  339. package/script/helpers/formatMissingTables.d.ts +8 -5
  340. package/script/helpers/formatMissingTables.d.ts.map +1 -1
  341. package/script/helpers/formatMissingTables.js +8 -5
  342. package/script/helpers/formatNumber.d.ts +19 -10
  343. package/script/helpers/formatNumber.d.ts.map +1 -1
  344. package/script/helpers/formatNumber.js +32 -17
  345. package/script/helpers/getGraphEdgeIdColumn.d.ts +9 -0
  346. package/script/helpers/getGraphEdgeIdColumn.d.ts.map +1 -0
  347. package/script/helpers/getGraphEdgeIdColumn.js +31 -0
  348. package/script/helpers/getGraphEndpointColumns.d.ts +11 -0
  349. package/script/helpers/getGraphEndpointColumns.d.ts.map +1 -0
  350. package/script/helpers/getGraphEndpointColumns.js +166 -0
  351. package/script/helpers/getGraphWeightColumn.d.ts +10 -0
  352. package/script/helpers/getGraphWeightColumn.d.ts.map +1 -0
  353. package/script/helpers/getGraphWeightColumn.js +46 -0
  354. package/script/helpers/graphRouteResultSchema.d.ts +4 -0
  355. package/script/helpers/graphRouteResultSchema.d.ts.map +1 -0
  356. package/script/helpers/graphRouteResultSchema.js +18 -0
  357. package/script/helpers/graphRouteResultSelect.d.ts +4 -0
  358. package/script/helpers/graphRouteResultSelect.d.ts.map +1 -0
  359. package/script/helpers/graphRouteResultSelect.js +28 -0
  360. package/script/helpers/hasGeometryColumn.d.ts +4 -3
  361. package/script/helpers/hasGeometryColumn.d.ts.map +1 -1
  362. package/script/helpers/hasGeometryColumn.js +4 -3
  363. package/script/helpers/initialUmapCoordinates.d.ts +2 -0
  364. package/script/helpers/initialUmapCoordinates.d.ts.map +1 -0
  365. package/script/helpers/initialUmapCoordinates.js +11 -0
  366. package/script/helpers/inspectGraphConnectivity.d.ts +10 -0
  367. package/script/helpers/inspectGraphConnectivity.d.ts.map +1 -0
  368. package/script/helpers/inspectGraphConnectivity.js +58 -0
  369. package/script/helpers/mergeOptions.d.ts +24 -13
  370. package/script/helpers/mergeOptions.d.ts.map +1 -1
  371. package/script/helpers/mergeOptions.js +24 -13
  372. package/script/helpers/optimizeUmapLayout.d.ts +7 -0
  373. package/script/helpers/optimizeUmapLayout.d.ts.map +1 -0
  374. package/script/helpers/optimizeUmapLayout.js +99 -0
  375. package/script/helpers/parseValue.d.ts +6 -4
  376. package/script/helpers/parseValue.d.ts.map +1 -1
  377. package/script/helpers/parseValue.js +6 -4
  378. package/script/helpers/prepareGraphRouteSql.d.ts +31 -0
  379. package/script/helpers/prepareGraphRouteSql.d.ts.map +1 -0
  380. package/script/helpers/prepareGraphRouteSql.js +127 -0
  381. package/script/helpers/prepareGraphStarts.d.ts +9 -0
  382. package/script/helpers/prepareGraphStarts.d.ts.map +1 -0
  383. package/script/helpers/prepareGraphStarts.js +71 -0
  384. package/script/helpers/prepareGraphTemporalSql.d.ts +28 -0
  385. package/script/helpers/prepareGraphTemporalSql.d.ts.map +1 -0
  386. package/script/helpers/prepareGraphTemporalSql.js +161 -0
  387. package/script/helpers/prepareGraphTraversal.d.ts +19 -0
  388. package/script/helpers/prepareGraphTraversal.d.ts.map +1 -0
  389. package/script/helpers/prepareGraphTraversal.js +87 -0
  390. package/script/helpers/prepareNumericFeatures.d.ts +41 -0
  391. package/script/helpers/prepareNumericFeatures.d.ts.map +1 -0
  392. package/script/helpers/prepareNumericFeatures.js +217 -0
  393. package/script/helpers/prepareUmapLayoutOptions.d.ts +14 -0
  394. package/script/helpers/prepareUmapLayoutOptions.d.ts.map +1 -0
  395. package/script/helpers/prepareUmapLayoutOptions.js +29 -0
  396. package/script/helpers/prettyDuration.d.ts +14 -8
  397. package/script/helpers/prettyDuration.d.ts.map +1 -1
  398. package/script/helpers/prettyDuration.js +14 -8
  399. package/script/helpers/printTable.d.ts +18 -13
  400. package/script/helpers/printTable.d.ts.map +1 -1
  401. package/script/helpers/printTable.js +18 -13
  402. package/script/helpers/publishPreparedColumns.d.ts +37 -0
  403. package/script/helpers/publishPreparedColumns.d.ts.map +1 -0
  404. package/script/helpers/publishPreparedColumns.js +119 -0
  405. package/script/helpers/queryDB.d.ts +24 -13
  406. package/script/helpers/queryDB.d.ts.map +1 -1
  407. package/script/helpers/queryDB.js +24 -13
  408. package/script/helpers/queueAsyncBarrier.d.ts +12 -7
  409. package/script/helpers/queueAsyncBarrier.d.ts.map +1 -1
  410. package/script/helpers/queueAsyncBarrier.js +12 -7
  411. package/script/helpers/queueGraphResult.d.ts +18 -0
  412. package/script/helpers/queueGraphResult.d.ts.map +1 -0
  413. package/script/helpers/queueGraphResult.js +45 -0
  414. package/script/helpers/quoteIdentifier.d.ts +4 -3
  415. package/script/helpers/quoteIdentifier.d.ts.map +1 -1
  416. package/script/helpers/quoteIdentifier.js +4 -3
  417. package/script/helpers/quoteQualifiedIdentifier.d.ts +6 -4
  418. package/script/helpers/quoteQualifiedIdentifier.d.ts.map +1 -1
  419. package/script/helpers/quoteQualifiedIdentifier.js +6 -4
  420. package/script/helpers/readScalarNumber.d.ts +3 -0
  421. package/script/helpers/readScalarNumber.d.ts.map +1 -0
  422. package/script/helpers/readScalarNumber.js +7 -0
  423. package/script/helpers/runQuery.d.ts.map +1 -1
  424. package/script/helpers/runQuery.js +17 -3
  425. package/script/helpers/selectFuzzyReplacements.d.ts +11 -0
  426. package/script/helpers/selectFuzzyReplacements.d.ts.map +1 -0
  427. package/script/helpers/selectFuzzyReplacements.js +127 -0
  428. package/script/helpers/stabilizeCosineVectors.d.ts +14 -0
  429. package/script/helpers/stabilizeCosineVectors.d.ts.map +1 -0
  430. package/script/helpers/stabilizeCosineVectors.js +40 -0
  431. package/script/helpers/stringToArray.d.ts +4 -3
  432. package/script/helpers/stringToArray.d.ts.map +1 -1
  433. package/script/helpers/stringToArray.js +4 -3
  434. package/script/helpers/umapRandom.d.ts +2 -0
  435. package/script/helpers/umapRandom.d.ts.map +1 -0
  436. package/script/helpers/umapRandom.js +13 -0
  437. package/script/helpers/updateColumnsWithJS.d.ts +12 -6
  438. package/script/helpers/updateColumnsWithJS.d.ts.map +1 -1
  439. package/script/helpers/updateColumnsWithJS.js +12 -6
  440. package/script/helpers/validateGraphRouteResultSchema.d.ts +4 -0
  441. package/script/helpers/validateGraphRouteResultSchema.d.ts.map +1 -0
  442. package/script/helpers/validateGraphRouteResultSchema.js +19 -0
  443. package/script/helpers/validateGraphTemporalEvents.d.ts +7 -0
  444. package/script/helpers/validateGraphTemporalEvents.d.ts.map +1 -0
  445. package/script/helpers/validateGraphTemporalEvents.js +53 -0
  446. package/script/helpers/validateNumericalAnalysis.d.ts +10 -6
  447. package/script/helpers/validateNumericalAnalysis.d.ts.map +1 -1
  448. package/script/helpers/validateNumericalAnalysis.js +10 -6
  449. package/script/helpers/validateVectorRowIds.d.ts +4 -0
  450. package/script/helpers/validateVectorRowIds.d.ts.map +1 -0
  451. package/script/helpers/validateVectorRowIds.js +19 -0
  452. package/script/helpers/vectorDistanceExpression.d.ts +6 -0
  453. package/script/helpers/vectorDistanceExpression.d.ts.map +1 -0
  454. package/script/helpers/vectorDistanceExpression.js +14 -0
  455. package/script/helpers/wrapString.d.ts +10 -7
  456. package/script/helpers/wrapString.d.ts.map +1 -1
  457. package/script/helpers/wrapString.js +10 -7
  458. package/script/methods/addId.d.ts +5 -0
  459. package/script/methods/addId.d.ts.map +1 -0
  460. package/script/methods/addId.js +44 -0
  461. package/script/methods/cache.js +1 -1
  462. package/script/methods/commonNeighbors.d.ts +10 -0
  463. package/script/methods/commonNeighbors.d.ts.map +1 -0
  464. package/script/methods/commonNeighbors.js +140 -0
  465. package/script/methods/connectedComponents.d.ts +9 -0
  466. package/script/methods/connectedComponents.d.ts.map +1 -0
  467. package/script/methods/connectedComponents.js +186 -0
  468. package/script/methods/degree.d.ts +9 -0
  469. package/script/methods/degree.d.ts.map +1 -0
  470. package/script/methods/degree.js +141 -0
  471. package/script/methods/distances.d.ts +12 -0
  472. package/script/methods/distances.d.ts.map +1 -0
  473. package/script/methods/distances.js +203 -0
  474. package/script/methods/findCycles.d.ts +12 -0
  475. package/script/methods/findCycles.d.ts.map +1 -0
  476. package/script/methods/findCycles.js +369 -0
  477. package/script/methods/fuzzyClean.d.ts.map +1 -1
  478. package/script/methods/fuzzyClean.js +17 -136
  479. package/script/methods/fuzzyJoin.js +70 -16
  480. package/script/methods/getTypes.d.ts +1 -1
  481. package/script/methods/hdbscan.d.ts +5 -0
  482. package/script/methods/hdbscan.d.ts.map +1 -0
  483. package/script/methods/hdbscan.js +214 -0
  484. package/script/methods/loadArray.d.ts.map +1 -1
  485. package/script/methods/loadArray.js +2 -19
  486. package/script/methods/mahalanobis.d.ts +5 -0
  487. package/script/methods/mahalanobis.d.ts.map +1 -0
  488. package/script/methods/mahalanobis.js +98 -0
  489. package/script/methods/neighbors.d.ts +9 -0
  490. package/script/methods/neighbors.d.ts.map +1 -0
  491. package/script/methods/neighbors.js +120 -0
  492. package/script/methods/normalizeVector.d.ts +5 -0
  493. package/script/methods/normalizeVector.d.ts.map +1 -0
  494. package/script/methods/normalizeVector.js +138 -0
  495. package/script/methods/paths.d.ts +12 -0
  496. package/script/methods/paths.d.ts.map +1 -0
  497. package/script/methods/paths.js +326 -0
  498. package/script/methods/reachable.d.ts +11 -0
  499. package/script/methods/reachable.d.ts.map +1 -0
  500. package/script/methods/reachable.js +170 -0
  501. package/script/methods/rowToVector.d.ts +5 -0
  502. package/script/methods/rowToVector.d.ts.map +1 -0
  503. package/script/methods/rowToVector.js +83 -0
  504. package/script/methods/shortestPath.d.ts +12 -0
  505. package/script/methods/shortestPath.d.ts.map +1 -0
  506. package/script/methods/shortestPath.js +376 -0
  507. package/script/methods/topologicalSort.d.ts +7 -0
  508. package/script/methods/topologicalSort.d.ts.map +1 -0
  509. package/script/methods/topologicalSort.js +170 -0
  510. package/script/methods/umap.d.ts +5 -0
  511. package/script/methods/umap.d.ts.map +1 -0
  512. package/script/methods/umap.js +162 -0
  513. package/script/methods/updateWithJS.js +9 -21
@@ -0,0 +1,164 @@
1
+ import buildWeakGraphComponentsSql from "../helpers/buildWeakGraphComponentsSql.js";
2
+ import getGraphEndpointColumns from "../helpers/getGraphEndpointColumns.js";
3
+ import { prepareGraphSql } from "../helpers/prepareGraphTraversal.js";
4
+ import queueGraphResult from "../helpers/queueGraphResult.js";
5
+ import queueOp from "../helpers/queueOp.js";
6
+ import quoteIdentifier from "../helpers/quoteIdentifier.js";
7
+ export default function topologicalSort(simpleTable, sourceColumn, targetColumn, options = {}) {
8
+ if (typeof sourceColumn !== "string") {
9
+ throw new TypeError("topologicalSort() sourceColumn must be a string.");
10
+ }
11
+ if (typeof targetColumn !== "string") {
12
+ throw new TypeError("topologicalSort() targetColumn must be a string.");
13
+ }
14
+ if (options === null || typeof options !== "object" || Array.isArray(options)) {
15
+ throw new TypeError("topologicalSort() options must be an object.");
16
+ }
17
+ if (options.outputTable !== undefined &&
18
+ typeof options.outputTable !== "string" &&
19
+ typeof options.outputTable !== "boolean") {
20
+ throw new TypeError("topologicalSort() options.outputTable must be a string or boolean.");
21
+ }
22
+ options = structuredClone(options);
23
+ const parameters = { sourceColumn, targetColumn, options };
24
+ const result = queueGraphResult(simpleTable, {
25
+ method: "topologicalSort()",
26
+ parameters,
27
+ outputTable: options.outputTable,
28
+ values: (schema) => {
29
+ validateEndpoints(schema, sourceColumn, targetColumn);
30
+ return [];
31
+ },
32
+ buildSelect: (input, schema) => topologicalSortSelect(input, schema, sourceColumn, targetColumn),
33
+ outputSchema: (schema) => ({
34
+ node: validateEndpoints(schema, sourceColumn, targetColumn).idType,
35
+ componentId: "BIGINT",
36
+ order: "BIGINT",
37
+ }),
38
+ });
39
+ // Materialize the sorting computation before downstream operations: DuckDB
40
+ // can otherwise discard even its terminal cycle check for LIMIT 0 or FALSE.
41
+ // This barrier adds no query or separate validation traversal, and upstream
42
+ // preparation still fuses into the sorting statement.
43
+ queueOp(result, {
44
+ kind: "barrier",
45
+ method: "topologicalSort()",
46
+ parameters,
47
+ execute: () => Promise.resolve(),
48
+ });
49
+ return result;
50
+ }
51
+ function validateEndpoints(schema, source, target) {
52
+ return getGraphEndpointColumns(schema, source, target, "topologicalSort()");
53
+ }
54
+ function topologicalSortSelect(input, schema, source, target) {
55
+ const prepared = prepareGraphSql(input, schema, source, target, "topologicalSort()");
56
+ const relations = prepared.relationNames([
57
+ "graph_edges",
58
+ "graph_nodes",
59
+ "graph_topological_order",
60
+ "graph_topological_result",
61
+ "graph_component_edges",
62
+ "graph_component_labels",
63
+ "graph_component_roots",
64
+ "graph_ordered_nodes",
65
+ ]);
66
+ const edges = relations.graph_edges;
67
+ const nodes = relations.graph_nodes;
68
+ const ordering = relations.graph_topological_order;
69
+ const result = relations.graph_topological_result;
70
+ const componentEdges = relations.graph_component_edges;
71
+ const labels = relations.graph_component_labels;
72
+ const roots = relations.graph_component_roots;
73
+ const orderedNodes = relations.graph_ordered_nodes;
74
+ const q = quoteIdentifier;
75
+ return `WITH RECURSIVE ${edges} AS (
76
+ ${prepared.edges("outgoing")}
77
+ ), ${nodes} AS (
78
+ SELECT ${q("__from")} AS ${q("node")},
79
+ ${q("__from_key")} AS ${q("__key")}
80
+ FROM ${edges}
81
+ UNION
82
+ SELECT ${q("__to")} AS ${q("node")},
83
+ ${q("__to_key")} AS ${q("__key")}
84
+ FROM ${edges}
85
+ ), ${componentEdges} AS (
86
+ SELECT * FROM ${edges}
87
+ UNION ALL
88
+ SELECT ${q("__to")}, ${q("__from")},
89
+ ${q("__to_key")}, ${q("__from_key")}
90
+ FROM ${edges}
91
+ ), ${buildWeakGraphComponentsSql(componentEdges, nodes, labels, roots)},
92
+ ${ordering}(
93
+ ${q("node")}, ${q("__key")}, ${q("order")}, ${q("__ordered")}
94
+ ) AS (
95
+ SELECT ${q("eligible")}.${q("node")},
96
+ ${q("eligible")}.${q("__key")}, CAST(1 AS BIGINT),
97
+ list_value(${q("eligible")}.${q("__key")})
98
+ FROM (
99
+ SELECT ${q("candidate")}.${q("node")},
100
+ ${q("candidate")}.${q("__key")}
101
+ FROM ${nodes} AS ${q("candidate")}
102
+ WHERE NOT EXISTS (
103
+ SELECT 1 FROM ${edges} AS ${q("edge")}
104
+ WHERE ${q("edge")}.${q("__to_key")} =
105
+ ${q("candidate")}.${q("__key")}
106
+ )
107
+ ORDER BY ${q("candidate")}.${q("__key")}
108
+ LIMIT 1
109
+ ) AS ${q("eligible")}
110
+ UNION ALL
111
+ SELECT ${q("eligible")}.${q("node")},
112
+ ${q("eligible")}.${q("__key")},
113
+ ${q("ordered")}.${q("order")} + 1,
114
+ list_append(
115
+ ${q("ordered")}.${q("__ordered")},
116
+ ${q("eligible")}.${q("__key")}
117
+ )
118
+ FROM ${ordering} AS ${q("ordered")}
119
+ CROSS JOIN LATERAL (
120
+ SELECT ${q("candidate")}.${q("node")},
121
+ ${q("candidate")}.${q("__key")}
122
+ FROM ${nodes} AS ${q("candidate")}
123
+ WHERE NOT list_contains(
124
+ ${q("ordered")}.${q("__ordered")},
125
+ ${q("candidate")}.${q("__key")}
126
+ )
127
+ AND NOT EXISTS (
128
+ SELECT 1 FROM ${edges} AS ${q("edge")}
129
+ WHERE ${q("edge")}.${q("__to_key")} =
130
+ ${q("candidate")}.${q("__key")}
131
+ AND NOT list_contains(
132
+ ${q("ordered")}.${q("__ordered")},
133
+ ${q("edge")}.${q("__from_key")}
134
+ )
135
+ )
136
+ ORDER BY ${q("candidate")}.${q("__key")}
137
+ LIMIT 1
138
+ ) AS ${q("eligible")}
139
+ ), ${result} AS (
140
+ SELECT CASE WHEN count(*) < (SELECT count(*) FROM ${nodes})
141
+ THEN error(
142
+ 'topologicalSort() cannot order the graph because it contains a directed cycle.'
143
+ )
144
+ ELSE list(${q("node")} ORDER BY ${q("order")})
145
+ END AS ${q("__nodes")}
146
+ FROM ${ordering}
147
+ ), ${orderedNodes} AS (
148
+ SELECT unnest(${q("__nodes")}) AS ${q("node")},
149
+ generate_subscripts(${q("__nodes")}, 1) AS ${q("__order")}
150
+ FROM ${result}
151
+ )
152
+ SELECT ${q("ordered")}.${q("node")}, ${q("roots")}.${q("componentId")},
153
+ row_number() OVER (
154
+ PARTITION BY ${q("roots")}.${q("componentId")}
155
+ ORDER BY ${q("ordered")}.${q("__order")}
156
+ ) AS ${q("order")}
157
+ FROM ${orderedNodes} AS ${q("ordered")}
158
+ INNER JOIN ${labels} AS ${q("labels")}
159
+ ON ${prepared.key(`${q("ordered")}.${q("node")}`)} =
160
+ ${q("labels")}.${q("__node_key")}
161
+ INNER JOIN ${roots} AS ${q("roots")}
162
+ ON ${q("labels")}.${q("__root_key")} = ${q("roots")}.${q("__root_key")}
163
+ ORDER BY ${q("componentId")}, ${q("order")}`;
164
+ }
@@ -0,0 +1,5 @@
1
+ import type SimpleTable from "../class/SimpleTable.js";
2
+ type Options = NonNullable<Parameters<SimpleTable["umap"]>[1]>;
3
+ export default function umap(table: SimpleTable, column: string, options?: Options): void;
4
+ export {};
5
+ //# sourceMappingURL=umap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"umap.d.ts","sourceRoot":"","sources":["../../src/methods/umap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAavD,KAAK,OAAO,GAAG,WAAW,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/D,MAAM,CAAC,OAAO,UAAU,IAAI,CAC1B,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,OAAY,QAStB"}
@@ -0,0 +1,156 @@
1
+ import queueOp from "../helpers/queueOp.js";
2
+ import quoteIdentifier from "../helpers/quoteIdentifier.js";
3
+ import queryDB from "../helpers/queryDB.js";
4
+ import mergeOptions from "../helpers/mergeOptions.js";
5
+ import buildUmapGraph from "../helpers/buildUmapGraph.js";
6
+ import prepareUmapLayoutOptions from "../helpers/prepareUmapLayoutOptions.js";
7
+ import readScalarNumber from "../helpers/readScalarNumber.js";
8
+ import optimizeUmapLayout from "../helpers/optimizeUmapLayout.js";
9
+ import initialUmapCoordinates from "../helpers/initialUmapCoordinates.js";
10
+ import appendColumnBatches from "../helpers/appendColumnBatches.js";
11
+ import { DOUBLE, INTEGER } from "@duckdb/node-api";
12
+ export default function umap(table, column, options = {}) {
13
+ const settings = structuredClone(options);
14
+ queueOp(table, {
15
+ kind: "barrier",
16
+ method: "umap()",
17
+ parameters: { column, options: settings },
18
+ execute: () => execute(table, column, settings),
19
+ });
20
+ }
21
+ async function execute(table, column, options) {
22
+ const { neighbors = 15, metric = "euclidean" } = options;
23
+ if (!Number.isSafeInteger(neighbors) || neighbors < 2) {
24
+ throw new Error("neighbors must be a safe integer of at least 2.");
25
+ }
26
+ const layoutOptions = prepareUmapLayoutOptions(options);
27
+ if (!["euclidean", "cosine"].includes(metric)) {
28
+ throw new Error("metric must be euclidean or cosine.");
29
+ }
30
+ const types = await table.getTypes();
31
+ const columns = Object.keys(types);
32
+ const resolve = (name) => {
33
+ const found = columns.find((c) => c.toLowerCase() === name.toLowerCase());
34
+ if (found === undefined)
35
+ throw new Error(`Column ${name} does not exist.`);
36
+ return found;
37
+ };
38
+ const vector = resolve(column);
39
+ if (columns.some((c) => ["umapx", "umapy"].includes(c.toLowerCase()))) {
40
+ throw new Error("UMAP output columns umapX and umapY must not already exist.");
41
+ }
42
+ if (!/^(FLOAT|DOUBLE|TINYINT|SMALLINT|INTEGER|BIGINT|HUGEINT|UTINYINT|USMALLINT|UINTEGER|UBIGINT|UHUGEINT|DECIMAL\(\d+,\d+\))\[\d*\]$/
43
+ .test(types[vector])) {
44
+ throw new Error("UMAP requires a one-dimensional numeric LIST or ARRAY column.");
45
+ }
46
+ const connection = table.connection;
47
+ const [sourceOid, sourceTemporary] = (await connection.runAndReadAll(`SELECT table_oid,temporary FROM duckdb_tables()
48
+ WHERE lower(table_name)=lower($1) AND schema_name=current_schema()
49
+ AND database_name IN (current_database(),'temp')
50
+ ORDER BY temporary DESC LIMIT 1`, [table.name])).getRowsJS()[0] ?? [];
51
+ if (typeof sourceOid !== "number" && typeof sourceOid !== "bigint") {
52
+ throw new Error("UMAP requires a materialized source table.");
53
+ }
54
+ const q = quoteIdentifier;
55
+ const suffix = crypto.randomUUID().replaceAll("-", "");
56
+ const name = (part) => `__sda_umap_${suffix}_${part}`;
57
+ const ordinal = q(name("ordinal"));
58
+ const source = q(table.name), snapshot = q(name("snapshot"));
59
+ const layoutName = name("layout"), layout = q(layoutName);
60
+ const names = {
61
+ rows: q(name("rows")),
62
+ knn: q(name("knn")),
63
+ search: q(name("search")),
64
+ hnsw: q(name("hnsw")),
65
+ candidates: q(name("candidates")),
66
+ scales: q(name("scales")),
67
+ directed: q(name("directed")),
68
+ graph: q(name("graph")),
69
+ };
70
+ const scratch = [
71
+ snapshot,
72
+ layout,
73
+ ...Object.entries(names)
74
+ .filter(([key]) => key !== "hnsw").map(([, value]) => value),
75
+ ];
76
+ try {
77
+ // Retain payloads in native DuckDB types. A private ordinal distinguishes
78
+ // duplicate rows and is independent of any user column named rowid.
79
+ await connection.run(`CREATE TEMP TABLE ${snapshot} AS
80
+ SELECT *, row_number() OVER () - 1 AS ${ordinal} FROM ${source}`);
81
+ const count = await readScalarNumber(connection, `SELECT count(*) FROM ${snapshot}`);
82
+ if (count < 3 || count > 0x7fffffff) {
83
+ throw new Error("UMAP requires between 3 and 2147483647 rows.");
84
+ }
85
+ if (await readScalarNumber(connection, `SELECT count(*) FROM ${snapshot}
86
+ WHERE ${q(vector)} IS NULL OR len(${q(vector)})=0
87
+ OR list_count(${q(vector)}) != len(${q(vector)})
88
+ OR NOT list_bool_and(list_transform(${q(vector)}, x -> isfinite(x::DOUBLE)))`)) {
89
+ throw new Error("Vectors must be nonempty, non-null and contain finite numbers only.");
90
+ }
91
+ if (await readScalarNumber(connection, `SELECT count(DISTINCT len(${q(vector)})) FROM ${snapshot}`) !== 1) {
92
+ throw new Error("Vectors must have equal dimensions.");
93
+ }
94
+ const dimensions = await readScalarNumber(connection, `SELECT len(${q(vector)}) FROM ${snapshot} LIMIT 1`);
95
+ await connection.run(`CREATE TEMP TABLE ${names.rows} AS
96
+ SELECT (row_number() OVER (ORDER BY ${ordinal})-1)::INTEGER AS vertex,
97
+ ${ordinal} AS ordinal, ${q(vector)}::DOUBLE[${dimensions}] AS vec FROM ${snapshot}`);
98
+ if (await readScalarNumber(connection, `SELECT count(*) FROM ${names.rows}
99
+ WHERE NOT isfinite(array_inner_product(vec,vec)) OR array_inner_product(vec,vec)>1e300
100
+ ${metric === "cosine" ? "OR array_inner_product(vec,vec)=0" : ""}`)) {
101
+ throw new Error("Vector norms overflow, or cosine distance received a zero vector.");
102
+ }
103
+ const graph = await buildUmapGraph(connection, {
104
+ count,
105
+ dimensions,
106
+ neighbors: Math.min(neighbors, count - 1),
107
+ }, {
108
+ metric,
109
+ search: count <= 1000 ? "exact" : "hnsw",
110
+ }, names);
111
+ // Release index and vector scratch before allocating optimizer state.
112
+ for (const relation of [
113
+ names.search,
114
+ names.candidates,
115
+ names.knn,
116
+ names.directed,
117
+ names.scales,
118
+ names.graph,
119
+ ]) {
120
+ await connection.run(`DROP TABLE IF EXISTS ${relation}`);
121
+ }
122
+ await connection.run(`ALTER TABLE ${names.rows} DROP COLUMN vec`);
123
+ const coordinates = optimizeUmapLayout(graph, initialUmapCoordinates(count, layoutOptions.seed), layoutOptions);
124
+ await connection.run(`CREATE TEMP TABLE ${layout} (vertex INTEGER,x DOUBLE,y DOUBLE)`);
125
+ await appendColumnBatches(connection, layoutName, [INTEGER, DOUBLE, DOUBLE], count, (column, start, end) => Array.from({ length: end - start }, (_, row) => column === 0
126
+ ? start + row
127
+ : coordinates[2 * (start + row) + column - 1]));
128
+ // Publish in one statement: failed fits never add partial columns. Existing
129
+ // native indexes must be restored because CREATE OR REPLACE drops them.
130
+ const indexes = (await connection.runAndReadAll("SELECT sql FROM duckdb_indexes() WHERE table_oid=$1", [sourceOid])).getRowsJS().map((row) => String(row[0]));
131
+ await connection.run("BEGIN TRANSACTION");
132
+ try {
133
+ await queryDB(table, `CREATE OR REPLACE ${sourceTemporary ? "TEMP " : ""}TABLE ${source} AS
134
+ SELECT ${columns.map((c) => `s.${q(c)}`).join(",")}, l.x AS "umapX", l.y AS "umapY"
135
+ FROM ${snapshot} s JOIN ${names.rows} r ON s.${ordinal}=r.ordinal
136
+ JOIN ${layout} l ON r.vertex=l.vertex ORDER BY s.${ordinal}`, mergeOptions(table, {
137
+ table: table.name,
138
+ method: "umap()",
139
+ parameters: { column, options },
140
+ noClean: true,
141
+ }));
142
+ for (const sql of indexes)
143
+ await connection.run(sql);
144
+ await connection.run("COMMIT");
145
+ }
146
+ catch (error) {
147
+ await connection.run("ROLLBACK");
148
+ throw error;
149
+ }
150
+ }
151
+ finally {
152
+ for (const relation of scratch) {
153
+ await connection.run(`DROP TABLE IF EXISTS ${relation}`);
154
+ }
155
+ }
156
+ }
@@ -4,7 +4,7 @@ import quoteIdentifier from "../helpers/quoteIdentifier.js";
4
4
  import { retainRegisteredTables } from "../helpers/tableRegistry.js";
5
5
  import queueOp from "../helpers/queueOp.js";
6
6
  import { prepareArray } from "./loadArray.js";
7
- import { DuckDBDataChunk } from "@duckdb/node-api";
7
+ import appendColumnBatches from "../helpers/appendColumnBatches.js";
8
8
  import readMutationRows from "../helpers/readMutationRows.js";
9
9
  import parseDuckDBType from "../helpers/parseDuckDBType.js";
10
10
  export default function updateWithJS(simpleTable, dataModifier, options = {}) {
@@ -133,26 +133,14 @@ async function executeUpdateWithJS(simpleTable, dataModifier, options) {
133
133
  parseDuckDBType(added.types[newKeys.indexOf(key)]));
134
134
  await simpleTable.sdb.customQuery(`CREATE OR REPLACE TABLE ${quoteIdentifier(scratch.name)} (${keys.map((key, i) => `${quoteIdentifier(key)} ${columnTypes[i]}`)
135
135
  .join(", ")})`);
136
- const appender = await simpleTable.connection.createAppender(scratch.name);
137
- try {
138
- for (let start = 0; start < modified.length; start += 2000) {
139
- const end = Math.min(start + 2000, modified.length);
140
- const chunk = DuckDBDataChunk.create(columnTypes, end - start);
141
- for (let i = 0; i < keys.length; i++) {
142
- const key = keys[i];
143
- chunk.setColumnValues(i, outputGeometry.includes(key)
144
- ? geometryData.get(key).slice(start, end)
145
- : source.types.has(key)
146
- ? modified.slice(start, end).map((row) => source.toNative(row[key], columnTypes[i]))
147
- : added.columnsData[newKeys.indexOf(key)].slice(start, end));
148
- }
149
- appender.appendDataChunk(chunk);
150
- }
151
- appender.flushSync();
152
- }
153
- finally {
154
- appender.closeSync();
155
- }
136
+ await appendColumnBatches(simpleTable.connection, scratch.name, columnTypes, modified.length, (column, start, end) => {
137
+ const key = keys[column];
138
+ return outputGeometry.includes(key)
139
+ ? geometryData.get(key).slice(start, end)
140
+ : source.types.has(key)
141
+ ? modified.slice(start, end).map((row) => source.toNative(row[key], columnTypes[column]))
142
+ : added.columnsData[newKeys.indexOf(key)].slice(start, end);
143
+ });
156
144
  const projection = keys.map((key) => outputGeometry.includes(key)
157
145
  ? `${geometryFromJSON(quoteIdentifier(key))} AS ${quoteIdentifier(key)}`
158
146
  : outputJSON.includes(key)