@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.
- package/esm/class/SDAError.d.ts +6 -6
- package/esm/class/SDAError.js +6 -6
- package/esm/class/Simple.d.ts +9 -9
- package/esm/class/Simple.js +9 -9
- package/esm/class/SimpleDB.d.ts +80 -76
- package/esm/class/SimpleDB.d.ts.map +1 -1
- package/esm/class/SimpleDB.js +80 -76
- package/esm/class/SimpleTable.d.ts +2805 -1077
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +2777 -1077
- package/esm/helpers/appendColumnBatches.d.ts +3 -0
- package/esm/helpers/appendColumnBatches.d.ts.map +1 -0
- package/esm/helpers/appendColumnBatches.js +21 -0
- package/esm/helpers/buildApproximateMutualReachabilityMst.d.ts +45 -0
- package/esm/helpers/buildApproximateMutualReachabilityMst.d.ts.map +1 -0
- package/esm/helpers/buildApproximateMutualReachabilityMst.js +212 -0
- package/esm/helpers/buildChronologicalGraphComponentsSql.d.ts +14 -0
- package/esm/helpers/buildChronologicalGraphComponentsSql.d.ts.map +1 -0
- package/esm/helpers/buildChronologicalGraphComponentsSql.js +167 -0
- package/esm/helpers/buildExactMutualReachabilityMst.d.ts +28 -0
- package/esm/helpers/buildExactMutualReachabilityMst.d.ts.map +1 -0
- package/esm/helpers/buildExactMutualReachabilityMst.js +97 -0
- package/esm/helpers/buildGraphTemporalCostStateSql.d.ts +12 -0
- package/esm/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -0
- package/esm/helpers/buildGraphTemporalCostStateSql.js +86 -0
- package/esm/helpers/buildGraphTemporalReachabilitySql.d.ts +13 -0
- package/esm/helpers/buildGraphTemporalReachabilitySql.d.ts.map +1 -0
- package/esm/helpers/buildGraphTemporalReachabilitySql.js +70 -0
- package/esm/helpers/buildSparseMutualReachabilityMst.d.ts +10 -0
- package/esm/helpers/buildSparseMutualReachabilityMst.d.ts.map +1 -0
- package/esm/helpers/buildSparseMutualReachabilityMst.js +47 -0
- package/esm/helpers/buildUmapGraph.d.ts +21 -0
- package/esm/helpers/buildUmapGraph.d.ts.map +1 -0
- package/esm/helpers/buildUmapGraph.js +61 -0
- package/esm/helpers/buildVectorNeighbors.d.ts +45 -0
- package/esm/helpers/buildVectorNeighbors.d.ts.map +1 -0
- package/esm/helpers/buildVectorNeighbors.js +170 -0
- package/esm/helpers/buildWeakGraphComponentsSql.d.ts +3 -0
- package/esm/helpers/buildWeakGraphComponentsSql.d.ts.map +1 -0
- package/esm/helpers/buildWeakGraphComponentsSql.js +32 -0
- package/esm/helpers/cacheDatabase.d.ts.map +1 -1
- package/esm/helpers/cacheDatabase.js +2 -1
- package/esm/helpers/camelCase.d.ts +7 -5
- package/esm/helpers/camelCase.d.ts.map +1 -1
- package/esm/helpers/camelCase.js +7 -5
- package/esm/helpers/capitalize.d.ts +6 -4
- package/esm/helpers/capitalize.d.ts.map +1 -1
- package/esm/helpers/capitalize.js +6 -4
- package/esm/helpers/clusterHdbscan.d.ts +18 -0
- package/esm/helpers/clusterHdbscan.d.ts.map +1 -0
- package/esm/helpers/clusterHdbscan.js +342 -0
- package/esm/helpers/computeCovariance.d.ts +16 -0
- package/esm/helpers/computeCovariance.d.ts.map +1 -0
- package/esm/helpers/computeCovariance.js +99 -0
- package/esm/helpers/computeMahalanobisDistances.d.ts +14 -0
- package/esm/helpers/computeMahalanobisDistances.d.ts.map +1 -0
- package/esm/helpers/computeMahalanobisDistances.js +87 -0
- package/esm/helpers/createDirectory.d.ts +4 -3
- package/esm/helpers/createDirectory.d.ts.map +1 -1
- package/esm/helpers/createDirectory.js +4 -3
- package/esm/helpers/dataToArrays.d.ts +6 -4
- package/esm/helpers/dataToArrays.d.ts.map +1 -1
- package/esm/helpers/dataToArrays.js +6 -4
- package/esm/helpers/extractTypes.d.ts +1 -1
- package/esm/helpers/extractTypes.js +4 -9
- package/esm/helpers/factorCovariance.d.ts +17 -0
- package/esm/helpers/factorCovariance.d.ts.map +1 -0
- package/esm/helpers/factorCovariance.js +189 -0
- package/esm/helpers/findGeoColumn.d.ts +6 -4
- package/esm/helpers/findGeoColumn.d.ts.map +1 -1
- package/esm/helpers/findGeoColumn.js +6 -4
- package/esm/helpers/findGeoColumnFromSchema.d.ts +8 -5
- package/esm/helpers/findGeoColumnFromSchema.d.ts.map +1 -1
- package/esm/helpers/findGeoColumnFromSchema.js +8 -5
- package/esm/helpers/fitUmapCurve.d.ts +2 -0
- package/esm/helpers/fitUmapCurve.d.ts.map +1 -0
- package/esm/helpers/fitUmapCurve.js +66 -0
- package/esm/helpers/formatDate.d.ts +12 -6
- package/esm/helpers/formatDate.d.ts.map +1 -1
- package/esm/helpers/formatDate.js +12 -6
- package/esm/helpers/formatMissingTables.d.ts +8 -5
- package/esm/helpers/formatMissingTables.d.ts.map +1 -1
- package/esm/helpers/formatMissingTables.js +8 -5
- package/esm/helpers/formatNumber.d.ts +19 -10
- package/esm/helpers/formatNumber.d.ts.map +1 -1
- package/esm/helpers/formatNumber.js +32 -17
- package/esm/helpers/getGraphEdgeIdColumn.d.ts +9 -0
- package/esm/helpers/getGraphEdgeIdColumn.d.ts.map +1 -0
- package/esm/helpers/getGraphEdgeIdColumn.js +25 -0
- package/esm/helpers/getGraphEndpointColumns.d.ts +11 -0
- package/esm/helpers/getGraphEndpointColumns.d.ts.map +1 -0
- package/esm/helpers/getGraphEndpointColumns.js +160 -0
- package/esm/helpers/getGraphWeightColumn.d.ts +10 -0
- package/esm/helpers/getGraphWeightColumn.d.ts.map +1 -0
- package/esm/helpers/getGraphWeightColumn.js +40 -0
- package/esm/helpers/graphRouteResultSchema.d.ts +4 -0
- package/esm/helpers/graphRouteResultSchema.d.ts.map +1 -0
- package/esm/helpers/graphRouteResultSchema.js +12 -0
- package/esm/helpers/graphRouteResultSelect.d.ts +4 -0
- package/esm/helpers/graphRouteResultSelect.d.ts.map +1 -0
- package/esm/helpers/graphRouteResultSelect.js +22 -0
- package/esm/helpers/hasGeometryColumn.d.ts +4 -3
- package/esm/helpers/hasGeometryColumn.d.ts.map +1 -1
- package/esm/helpers/hasGeometryColumn.js +4 -3
- package/esm/helpers/initialUmapCoordinates.d.ts +2 -0
- package/esm/helpers/initialUmapCoordinates.d.ts.map +1 -0
- package/esm/helpers/initialUmapCoordinates.js +5 -0
- package/esm/helpers/inspectGraphConnectivity.d.ts +10 -0
- package/esm/helpers/inspectGraphConnectivity.d.ts.map +1 -0
- package/esm/helpers/inspectGraphConnectivity.js +55 -0
- package/esm/helpers/mergeOptions.d.ts +24 -13
- package/esm/helpers/mergeOptions.d.ts.map +1 -1
- package/esm/helpers/mergeOptions.js +24 -13
- package/esm/helpers/optimizeUmapLayout.d.ts +7 -0
- package/esm/helpers/optimizeUmapLayout.d.ts.map +1 -0
- package/esm/helpers/optimizeUmapLayout.js +93 -0
- package/esm/helpers/parseValue.d.ts +6 -4
- package/esm/helpers/parseValue.d.ts.map +1 -1
- package/esm/helpers/parseValue.js +6 -4
- package/esm/helpers/prepareGraphRouteSql.d.ts +31 -0
- package/esm/helpers/prepareGraphRouteSql.d.ts.map +1 -0
- package/esm/helpers/prepareGraphRouteSql.js +86 -0
- package/esm/helpers/prepareGraphStarts.d.ts +9 -0
- package/esm/helpers/prepareGraphStarts.d.ts.map +1 -0
- package/esm/helpers/prepareGraphStarts.js +68 -0
- package/esm/helpers/prepareGraphTemporalSql.d.ts +28 -0
- package/esm/helpers/prepareGraphTemporalSql.d.ts.map +1 -0
- package/esm/helpers/prepareGraphTemporalSql.js +154 -0
- package/esm/helpers/prepareGraphTraversal.d.ts +19 -0
- package/esm/helpers/prepareGraphTraversal.d.ts.map +1 -0
- package/esm/helpers/prepareGraphTraversal.js +79 -0
- package/esm/helpers/prepareNumericFeatures.d.ts +41 -0
- package/esm/helpers/prepareNumericFeatures.d.ts.map +1 -0
- package/esm/helpers/prepareNumericFeatures.js +210 -0
- package/esm/helpers/prepareUmapLayoutOptions.d.ts +14 -0
- package/esm/helpers/prepareUmapLayoutOptions.d.ts.map +1 -0
- package/esm/helpers/prepareUmapLayoutOptions.js +23 -0
- package/esm/helpers/prettyDuration.d.ts +14 -8
- package/esm/helpers/prettyDuration.d.ts.map +1 -1
- package/esm/helpers/prettyDuration.js +14 -8
- package/esm/helpers/printTable.d.ts +18 -13
- package/esm/helpers/printTable.d.ts.map +1 -1
- package/esm/helpers/printTable.js +18 -13
- package/esm/helpers/publishPreparedColumns.d.ts +37 -0
- package/esm/helpers/publishPreparedColumns.d.ts.map +1 -0
- package/esm/helpers/publishPreparedColumns.js +113 -0
- package/esm/helpers/queryDB.d.ts +24 -13
- package/esm/helpers/queryDB.d.ts.map +1 -1
- package/esm/helpers/queryDB.js +24 -13
- package/esm/helpers/queueAsyncBarrier.d.ts +12 -7
- package/esm/helpers/queueAsyncBarrier.d.ts.map +1 -1
- package/esm/helpers/queueAsyncBarrier.js +12 -7
- package/esm/helpers/queueGraphResult.d.ts +18 -0
- package/esm/helpers/queueGraphResult.d.ts.map +1 -0
- package/esm/helpers/queueGraphResult.js +39 -0
- package/esm/helpers/quoteIdentifier.d.ts +4 -3
- package/esm/helpers/quoteIdentifier.d.ts.map +1 -1
- package/esm/helpers/quoteIdentifier.js +4 -3
- package/esm/helpers/quoteQualifiedIdentifier.d.ts +6 -4
- package/esm/helpers/quoteQualifiedIdentifier.d.ts.map +1 -1
- package/esm/helpers/quoteQualifiedIdentifier.js +6 -4
- package/esm/helpers/readScalarNumber.d.ts +3 -0
- package/esm/helpers/readScalarNumber.d.ts.map +1 -0
- package/esm/helpers/readScalarNumber.js +4 -0
- package/esm/helpers/runQuery.d.ts.map +1 -1
- package/esm/helpers/runQuery.js +17 -3
- package/esm/helpers/selectFuzzyReplacements.d.ts +11 -0
- package/esm/helpers/selectFuzzyReplacements.d.ts.map +1 -0
- package/esm/helpers/selectFuzzyReplacements.js +124 -0
- package/esm/helpers/stabilizeCosineVectors.d.ts +14 -0
- package/esm/helpers/stabilizeCosineVectors.d.ts.map +1 -0
- package/esm/helpers/stabilizeCosineVectors.js +34 -0
- package/esm/helpers/stringToArray.d.ts +4 -3
- package/esm/helpers/stringToArray.d.ts.map +1 -1
- package/esm/helpers/stringToArray.js +4 -3
- package/esm/helpers/umapRandom.d.ts +2 -0
- package/esm/helpers/umapRandom.d.ts.map +1 -0
- package/esm/helpers/umapRandom.js +10 -0
- package/esm/helpers/updateColumnsWithJS.d.ts +12 -6
- package/esm/helpers/updateColumnsWithJS.d.ts.map +1 -1
- package/esm/helpers/updateColumnsWithJS.js +12 -6
- package/esm/helpers/validateGraphRouteResultSchema.d.ts +4 -0
- package/esm/helpers/validateGraphRouteResultSchema.d.ts.map +1 -0
- package/esm/helpers/validateGraphRouteResultSchema.js +13 -0
- package/esm/helpers/validateGraphTemporalEvents.d.ts +7 -0
- package/esm/helpers/validateGraphTemporalEvents.d.ts.map +1 -0
- package/esm/helpers/validateGraphTemporalEvents.js +47 -0
- package/esm/helpers/validateNumericalAnalysis.d.ts +10 -6
- package/esm/helpers/validateNumericalAnalysis.d.ts.map +1 -1
- package/esm/helpers/validateNumericalAnalysis.js +10 -6
- package/esm/helpers/validateVectorRowIds.d.ts +4 -0
- package/esm/helpers/validateVectorRowIds.d.ts.map +1 -0
- package/esm/helpers/validateVectorRowIds.js +16 -0
- package/esm/helpers/vectorDistanceExpression.d.ts +6 -0
- package/esm/helpers/vectorDistanceExpression.d.ts.map +1 -0
- package/esm/helpers/vectorDistanceExpression.js +11 -0
- package/esm/helpers/wrapString.d.ts +10 -7
- package/esm/helpers/wrapString.d.ts.map +1 -1
- package/esm/helpers/wrapString.js +10 -7
- package/esm/methods/addId.d.ts +5 -0
- package/esm/methods/addId.d.ts.map +1 -0
- package/esm/methods/addId.js +38 -0
- package/esm/methods/cache.js +1 -1
- package/esm/methods/commonNeighbors.d.ts +10 -0
- package/esm/methods/commonNeighbors.d.ts.map +1 -0
- package/esm/methods/commonNeighbors.js +101 -0
- package/esm/methods/connectedComponents.d.ts +9 -0
- package/esm/methods/connectedComponents.d.ts.map +1 -0
- package/esm/methods/connectedComponents.js +147 -0
- package/esm/methods/degree.d.ts +9 -0
- package/esm/methods/degree.d.ts.map +1 -0
- package/esm/methods/degree.js +135 -0
- package/esm/methods/distances.d.ts +12 -0
- package/esm/methods/distances.d.ts.map +1 -0
- package/esm/methods/distances.js +164 -0
- package/esm/methods/findCycles.d.ts +12 -0
- package/esm/methods/findCycles.d.ts.map +1 -0
- package/esm/methods/findCycles.js +330 -0
- package/esm/methods/fuzzyClean.d.ts.map +1 -1
- package/esm/methods/fuzzyClean.js +17 -136
- package/esm/methods/fuzzyJoin.js +70 -16
- package/esm/methods/getTypes.d.ts +1 -1
- package/esm/methods/hdbscan.d.ts +5 -0
- package/esm/methods/hdbscan.d.ts.map +1 -0
- package/esm/methods/hdbscan.js +208 -0
- package/esm/methods/loadArray.d.ts.map +1 -1
- package/esm/methods/loadArray.js +3 -20
- package/esm/methods/mahalanobis.d.ts +5 -0
- package/esm/methods/mahalanobis.d.ts.map +1 -0
- package/esm/methods/mahalanobis.js +92 -0
- package/esm/methods/neighbors.d.ts +9 -0
- package/esm/methods/neighbors.d.ts.map +1 -0
- package/esm/methods/neighbors.js +81 -0
- package/esm/methods/normalizeVector.d.ts +5 -0
- package/esm/methods/normalizeVector.d.ts.map +1 -0
- package/esm/methods/normalizeVector.js +132 -0
- package/esm/methods/paths.d.ts +12 -0
- package/esm/methods/paths.d.ts.map +1 -0
- package/esm/methods/paths.js +287 -0
- package/esm/methods/reachable.d.ts +11 -0
- package/esm/methods/reachable.d.ts.map +1 -0
- package/esm/methods/reachable.js +131 -0
- package/esm/methods/rowToVector.d.ts +5 -0
- package/esm/methods/rowToVector.d.ts.map +1 -0
- package/esm/methods/rowToVector.js +77 -0
- package/esm/methods/shortestPath.d.ts +12 -0
- package/esm/methods/shortestPath.d.ts.map +1 -0
- package/esm/methods/shortestPath.js +337 -0
- package/esm/methods/topologicalSort.d.ts +7 -0
- package/esm/methods/topologicalSort.d.ts.map +1 -0
- package/esm/methods/topologicalSort.js +164 -0
- package/esm/methods/umap.d.ts +5 -0
- package/esm/methods/umap.d.ts.map +1 -0
- package/esm/methods/umap.js +156 -0
- package/esm/methods/updateWithJS.js +9 -21
- package/llm.md +2170 -128
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/script/class/SDAError.d.ts +6 -6
- package/script/class/SDAError.js +6 -6
- package/script/class/Simple.d.ts +9 -9
- package/script/class/Simple.js +9 -9
- package/script/class/SimpleDB.d.ts +80 -76
- package/script/class/SimpleDB.d.ts.map +1 -1
- package/script/class/SimpleDB.js +80 -76
- package/script/class/SimpleTable.d.ts +2805 -1077
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +2777 -1077
- package/script/helpers/appendColumnBatches.d.ts +3 -0
- package/script/helpers/appendColumnBatches.d.ts.map +1 -0
- package/script/helpers/appendColumnBatches.js +24 -0
- package/script/helpers/buildApproximateMutualReachabilityMst.d.ts +45 -0
- package/script/helpers/buildApproximateMutualReachabilityMst.d.ts.map +1 -0
- package/script/helpers/buildApproximateMutualReachabilityMst.js +219 -0
- package/script/helpers/buildChronologicalGraphComponentsSql.d.ts +14 -0
- package/script/helpers/buildChronologicalGraphComponentsSql.d.ts.map +1 -0
- package/script/helpers/buildChronologicalGraphComponentsSql.js +174 -0
- package/script/helpers/buildExactMutualReachabilityMst.d.ts +28 -0
- package/script/helpers/buildExactMutualReachabilityMst.d.ts.map +1 -0
- package/script/helpers/buildExactMutualReachabilityMst.js +103 -0
- package/script/helpers/buildGraphTemporalCostStateSql.d.ts +12 -0
- package/script/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -0
- package/script/helpers/buildGraphTemporalCostStateSql.js +92 -0
- package/script/helpers/buildGraphTemporalReachabilitySql.d.ts +13 -0
- package/script/helpers/buildGraphTemporalReachabilitySql.d.ts.map +1 -0
- package/script/helpers/buildGraphTemporalReachabilitySql.js +76 -0
- package/script/helpers/buildSparseMutualReachabilityMst.d.ts +10 -0
- package/script/helpers/buildSparseMutualReachabilityMst.d.ts.map +1 -0
- package/script/helpers/buildSparseMutualReachabilityMst.js +50 -0
- package/script/helpers/buildUmapGraph.d.ts +21 -0
- package/script/helpers/buildUmapGraph.d.ts.map +1 -0
- package/script/helpers/buildUmapGraph.js +67 -0
- package/script/helpers/buildVectorNeighbors.d.ts +45 -0
- package/script/helpers/buildVectorNeighbors.d.ts.map +1 -0
- package/script/helpers/buildVectorNeighbors.js +176 -0
- package/script/helpers/buildWeakGraphComponentsSql.d.ts +3 -0
- package/script/helpers/buildWeakGraphComponentsSql.d.ts.map +1 -0
- package/script/helpers/buildWeakGraphComponentsSql.js +38 -0
- package/script/helpers/cacheDatabase.d.ts.map +1 -1
- package/script/helpers/cacheDatabase.js +2 -1
- package/script/helpers/camelCase.d.ts +7 -5
- package/script/helpers/camelCase.d.ts.map +1 -1
- package/script/helpers/camelCase.js +7 -5
- package/script/helpers/capitalize.d.ts +6 -4
- package/script/helpers/capitalize.d.ts.map +1 -1
- package/script/helpers/capitalize.js +6 -4
- package/script/helpers/clusterHdbscan.d.ts +18 -0
- package/script/helpers/clusterHdbscan.d.ts.map +1 -0
- package/script/helpers/clusterHdbscan.js +346 -0
- package/script/helpers/computeCovariance.d.ts +16 -0
- package/script/helpers/computeCovariance.d.ts.map +1 -0
- package/script/helpers/computeCovariance.js +105 -0
- package/script/helpers/computeMahalanobisDistances.d.ts +14 -0
- package/script/helpers/computeMahalanobisDistances.d.ts.map +1 -0
- package/script/helpers/computeMahalanobisDistances.js +93 -0
- package/script/helpers/createDirectory.d.ts +4 -3
- package/script/helpers/createDirectory.d.ts.map +1 -1
- package/script/helpers/createDirectory.js +4 -3
- package/script/helpers/dataToArrays.d.ts +6 -4
- package/script/helpers/dataToArrays.d.ts.map +1 -1
- package/script/helpers/dataToArrays.js +6 -4
- package/script/helpers/extractTypes.d.ts +1 -1
- package/script/helpers/extractTypes.js +4 -9
- package/script/helpers/factorCovariance.d.ts +17 -0
- package/script/helpers/factorCovariance.d.ts.map +1 -0
- package/script/helpers/factorCovariance.js +194 -0
- package/script/helpers/findGeoColumn.d.ts +6 -4
- package/script/helpers/findGeoColumn.d.ts.map +1 -1
- package/script/helpers/findGeoColumn.js +6 -4
- package/script/helpers/findGeoColumnFromSchema.d.ts +8 -5
- package/script/helpers/findGeoColumnFromSchema.d.ts.map +1 -1
- package/script/helpers/findGeoColumnFromSchema.js +8 -5
- package/script/helpers/fitUmapCurve.d.ts +2 -0
- package/script/helpers/fitUmapCurve.d.ts.map +1 -0
- package/script/helpers/fitUmapCurve.js +69 -0
- package/script/helpers/formatDate.d.ts +12 -6
- package/script/helpers/formatDate.d.ts.map +1 -1
- package/script/helpers/formatDate.js +12 -6
- package/script/helpers/formatMissingTables.d.ts +8 -5
- package/script/helpers/formatMissingTables.d.ts.map +1 -1
- package/script/helpers/formatMissingTables.js +8 -5
- package/script/helpers/formatNumber.d.ts +19 -10
- package/script/helpers/formatNumber.d.ts.map +1 -1
- package/script/helpers/formatNumber.js +32 -17
- package/script/helpers/getGraphEdgeIdColumn.d.ts +9 -0
- package/script/helpers/getGraphEdgeIdColumn.d.ts.map +1 -0
- package/script/helpers/getGraphEdgeIdColumn.js +31 -0
- package/script/helpers/getGraphEndpointColumns.d.ts +11 -0
- package/script/helpers/getGraphEndpointColumns.d.ts.map +1 -0
- package/script/helpers/getGraphEndpointColumns.js +166 -0
- package/script/helpers/getGraphWeightColumn.d.ts +10 -0
- package/script/helpers/getGraphWeightColumn.d.ts.map +1 -0
- package/script/helpers/getGraphWeightColumn.js +46 -0
- package/script/helpers/graphRouteResultSchema.d.ts +4 -0
- package/script/helpers/graphRouteResultSchema.d.ts.map +1 -0
- package/script/helpers/graphRouteResultSchema.js +18 -0
- package/script/helpers/graphRouteResultSelect.d.ts +4 -0
- package/script/helpers/graphRouteResultSelect.d.ts.map +1 -0
- package/script/helpers/graphRouteResultSelect.js +28 -0
- package/script/helpers/hasGeometryColumn.d.ts +4 -3
- package/script/helpers/hasGeometryColumn.d.ts.map +1 -1
- package/script/helpers/hasGeometryColumn.js +4 -3
- package/script/helpers/initialUmapCoordinates.d.ts +2 -0
- package/script/helpers/initialUmapCoordinates.d.ts.map +1 -0
- package/script/helpers/initialUmapCoordinates.js +11 -0
- package/script/helpers/inspectGraphConnectivity.d.ts +10 -0
- package/script/helpers/inspectGraphConnectivity.d.ts.map +1 -0
- package/script/helpers/inspectGraphConnectivity.js +58 -0
- package/script/helpers/mergeOptions.d.ts +24 -13
- package/script/helpers/mergeOptions.d.ts.map +1 -1
- package/script/helpers/mergeOptions.js +24 -13
- package/script/helpers/optimizeUmapLayout.d.ts +7 -0
- package/script/helpers/optimizeUmapLayout.d.ts.map +1 -0
- package/script/helpers/optimizeUmapLayout.js +99 -0
- package/script/helpers/parseValue.d.ts +6 -4
- package/script/helpers/parseValue.d.ts.map +1 -1
- package/script/helpers/parseValue.js +6 -4
- package/script/helpers/prepareGraphRouteSql.d.ts +31 -0
- package/script/helpers/prepareGraphRouteSql.d.ts.map +1 -0
- package/script/helpers/prepareGraphRouteSql.js +127 -0
- package/script/helpers/prepareGraphStarts.d.ts +9 -0
- package/script/helpers/prepareGraphStarts.d.ts.map +1 -0
- package/script/helpers/prepareGraphStarts.js +71 -0
- package/script/helpers/prepareGraphTemporalSql.d.ts +28 -0
- package/script/helpers/prepareGraphTemporalSql.d.ts.map +1 -0
- package/script/helpers/prepareGraphTemporalSql.js +161 -0
- package/script/helpers/prepareGraphTraversal.d.ts +19 -0
- package/script/helpers/prepareGraphTraversal.d.ts.map +1 -0
- package/script/helpers/prepareGraphTraversal.js +87 -0
- package/script/helpers/prepareNumericFeatures.d.ts +41 -0
- package/script/helpers/prepareNumericFeatures.d.ts.map +1 -0
- package/script/helpers/prepareNumericFeatures.js +217 -0
- package/script/helpers/prepareUmapLayoutOptions.d.ts +14 -0
- package/script/helpers/prepareUmapLayoutOptions.d.ts.map +1 -0
- package/script/helpers/prepareUmapLayoutOptions.js +29 -0
- package/script/helpers/prettyDuration.d.ts +14 -8
- package/script/helpers/prettyDuration.d.ts.map +1 -1
- package/script/helpers/prettyDuration.js +14 -8
- package/script/helpers/printTable.d.ts +18 -13
- package/script/helpers/printTable.d.ts.map +1 -1
- package/script/helpers/printTable.js +18 -13
- package/script/helpers/publishPreparedColumns.d.ts +37 -0
- package/script/helpers/publishPreparedColumns.d.ts.map +1 -0
- package/script/helpers/publishPreparedColumns.js +119 -0
- package/script/helpers/queryDB.d.ts +24 -13
- package/script/helpers/queryDB.d.ts.map +1 -1
- package/script/helpers/queryDB.js +24 -13
- package/script/helpers/queueAsyncBarrier.d.ts +12 -7
- package/script/helpers/queueAsyncBarrier.d.ts.map +1 -1
- package/script/helpers/queueAsyncBarrier.js +12 -7
- package/script/helpers/queueGraphResult.d.ts +18 -0
- package/script/helpers/queueGraphResult.d.ts.map +1 -0
- package/script/helpers/queueGraphResult.js +45 -0
- package/script/helpers/quoteIdentifier.d.ts +4 -3
- package/script/helpers/quoteIdentifier.d.ts.map +1 -1
- package/script/helpers/quoteIdentifier.js +4 -3
- package/script/helpers/quoteQualifiedIdentifier.d.ts +6 -4
- package/script/helpers/quoteQualifiedIdentifier.d.ts.map +1 -1
- package/script/helpers/quoteQualifiedIdentifier.js +6 -4
- package/script/helpers/readScalarNumber.d.ts +3 -0
- package/script/helpers/readScalarNumber.d.ts.map +1 -0
- package/script/helpers/readScalarNumber.js +7 -0
- package/script/helpers/runQuery.d.ts.map +1 -1
- package/script/helpers/runQuery.js +17 -3
- package/script/helpers/selectFuzzyReplacements.d.ts +11 -0
- package/script/helpers/selectFuzzyReplacements.d.ts.map +1 -0
- package/script/helpers/selectFuzzyReplacements.js +127 -0
- package/script/helpers/stabilizeCosineVectors.d.ts +14 -0
- package/script/helpers/stabilizeCosineVectors.d.ts.map +1 -0
- package/script/helpers/stabilizeCosineVectors.js +40 -0
- package/script/helpers/stringToArray.d.ts +4 -3
- package/script/helpers/stringToArray.d.ts.map +1 -1
- package/script/helpers/stringToArray.js +4 -3
- package/script/helpers/umapRandom.d.ts +2 -0
- package/script/helpers/umapRandom.d.ts.map +1 -0
- package/script/helpers/umapRandom.js +13 -0
- package/script/helpers/updateColumnsWithJS.d.ts +12 -6
- package/script/helpers/updateColumnsWithJS.d.ts.map +1 -1
- package/script/helpers/updateColumnsWithJS.js +12 -6
- package/script/helpers/validateGraphRouteResultSchema.d.ts +4 -0
- package/script/helpers/validateGraphRouteResultSchema.d.ts.map +1 -0
- package/script/helpers/validateGraphRouteResultSchema.js +19 -0
- package/script/helpers/validateGraphTemporalEvents.d.ts +7 -0
- package/script/helpers/validateGraphTemporalEvents.d.ts.map +1 -0
- package/script/helpers/validateGraphTemporalEvents.js +53 -0
- package/script/helpers/validateNumericalAnalysis.d.ts +10 -6
- package/script/helpers/validateNumericalAnalysis.d.ts.map +1 -1
- package/script/helpers/validateNumericalAnalysis.js +10 -6
- package/script/helpers/validateVectorRowIds.d.ts +4 -0
- package/script/helpers/validateVectorRowIds.d.ts.map +1 -0
- package/script/helpers/validateVectorRowIds.js +19 -0
- package/script/helpers/vectorDistanceExpression.d.ts +6 -0
- package/script/helpers/vectorDistanceExpression.d.ts.map +1 -0
- package/script/helpers/vectorDistanceExpression.js +14 -0
- package/script/helpers/wrapString.d.ts +10 -7
- package/script/helpers/wrapString.d.ts.map +1 -1
- package/script/helpers/wrapString.js +10 -7
- package/script/methods/addId.d.ts +5 -0
- package/script/methods/addId.d.ts.map +1 -0
- package/script/methods/addId.js +44 -0
- package/script/methods/cache.js +1 -1
- package/script/methods/commonNeighbors.d.ts +10 -0
- package/script/methods/commonNeighbors.d.ts.map +1 -0
- package/script/methods/commonNeighbors.js +140 -0
- package/script/methods/connectedComponents.d.ts +9 -0
- package/script/methods/connectedComponents.d.ts.map +1 -0
- package/script/methods/connectedComponents.js +186 -0
- package/script/methods/degree.d.ts +9 -0
- package/script/methods/degree.d.ts.map +1 -0
- package/script/methods/degree.js +141 -0
- package/script/methods/distances.d.ts +12 -0
- package/script/methods/distances.d.ts.map +1 -0
- package/script/methods/distances.js +203 -0
- package/script/methods/findCycles.d.ts +12 -0
- package/script/methods/findCycles.d.ts.map +1 -0
- package/script/methods/findCycles.js +369 -0
- package/script/methods/fuzzyClean.d.ts.map +1 -1
- package/script/methods/fuzzyClean.js +17 -136
- package/script/methods/fuzzyJoin.js +70 -16
- package/script/methods/getTypes.d.ts +1 -1
- package/script/methods/hdbscan.d.ts +5 -0
- package/script/methods/hdbscan.d.ts.map +1 -0
- package/script/methods/hdbscan.js +214 -0
- package/script/methods/loadArray.d.ts.map +1 -1
- package/script/methods/loadArray.js +2 -19
- package/script/methods/mahalanobis.d.ts +5 -0
- package/script/methods/mahalanobis.d.ts.map +1 -0
- package/script/methods/mahalanobis.js +98 -0
- package/script/methods/neighbors.d.ts +9 -0
- package/script/methods/neighbors.d.ts.map +1 -0
- package/script/methods/neighbors.js +120 -0
- package/script/methods/normalizeVector.d.ts +5 -0
- package/script/methods/normalizeVector.d.ts.map +1 -0
- package/script/methods/normalizeVector.js +138 -0
- package/script/methods/paths.d.ts +12 -0
- package/script/methods/paths.d.ts.map +1 -0
- package/script/methods/paths.js +326 -0
- package/script/methods/reachable.d.ts +11 -0
- package/script/methods/reachable.d.ts.map +1 -0
- package/script/methods/reachable.js +170 -0
- package/script/methods/rowToVector.d.ts +5 -0
- package/script/methods/rowToVector.d.ts.map +1 -0
- package/script/methods/rowToVector.js +83 -0
- package/script/methods/shortestPath.d.ts +12 -0
- package/script/methods/shortestPath.d.ts.map +1 -0
- package/script/methods/shortestPath.js +376 -0
- package/script/methods/topologicalSort.d.ts +7 -0
- package/script/methods/topologicalSort.d.ts.map +1 -0
- package/script/methods/topologicalSort.js +170 -0
- package/script/methods/umap.d.ts +5 -0
- package/script/methods/umap.d.ts.map +1 -0
- package/script/methods/umap.js +162 -0
- package/script/methods/updateWithJS.js +9 -21
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import foldIdentifier from "./foldIdentifier.js";
|
|
2
|
+
import quoteIdentifier from "./quoteIdentifier.js";
|
|
3
|
+
const temporalTypes = new Set([
|
|
4
|
+
"DATE",
|
|
5
|
+
"TIMESTAMP",
|
|
6
|
+
"TIMESTAMP_S",
|
|
7
|
+
"TIMESTAMP_MS",
|
|
8
|
+
"TIMESTAMP_NS",
|
|
9
|
+
"TIMESTAMP WITH TIME ZONE",
|
|
10
|
+
]);
|
|
11
|
+
/** Validates chronological options before a graph operation is queued. */
|
|
12
|
+
export function prepareGraphTemporalOptions(options, direction, method) {
|
|
13
|
+
const startTimeColumn = options.startTimeColumn;
|
|
14
|
+
const endTimeColumn = options.endTimeColumn;
|
|
15
|
+
if (startTimeColumn !== undefined && typeof startTimeColumn !== "string") {
|
|
16
|
+
throw new TypeError(`${method} options.startTimeColumn must be a string.`);
|
|
17
|
+
}
|
|
18
|
+
if (endTimeColumn !== undefined && typeof endTimeColumn !== "string") {
|
|
19
|
+
throw new TypeError(`${method} options.endTimeColumn must be a string.`);
|
|
20
|
+
}
|
|
21
|
+
if (options.strictOrdering !== undefined &&
|
|
22
|
+
typeof options.strictOrdering !== "boolean") {
|
|
23
|
+
throw new TypeError(`${method} options.strictOrdering must be a boolean.`);
|
|
24
|
+
}
|
|
25
|
+
if (options.minGapMs !== undefined && typeof options.minGapMs !== "number") {
|
|
26
|
+
throw new TypeError(`${method} options.minGapMs must be a number.`);
|
|
27
|
+
}
|
|
28
|
+
const hasTimeColumn = startTimeColumn !== undefined ||
|
|
29
|
+
endTimeColumn !== undefined;
|
|
30
|
+
const hasTemporalSetting = options.minGapMs !== undefined ||
|
|
31
|
+
options.strictOrdering !== undefined;
|
|
32
|
+
if (!hasTimeColumn) {
|
|
33
|
+
if (hasTemporalSetting) {
|
|
34
|
+
throw new TypeError(`${method} options.minGapMs and options.strictOrdering require options.startTimeColumn or options.endTimeColumn.`);
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
if (direction === "both") {
|
|
39
|
+
throw new TypeError(`${method} options.direction cannot be "both" when chronological options are supplied.`);
|
|
40
|
+
}
|
|
41
|
+
const minGapMs = options.minGapMs ?? 0;
|
|
42
|
+
if (!Number.isFinite(minGapMs) || minGapMs < 0 || !Number.isInteger(minGapMs)) {
|
|
43
|
+
throw new TypeError(`${method} options.minGapMs must be a finite, non-negative integer.`);
|
|
44
|
+
}
|
|
45
|
+
if (minGapMs > Number.MAX_SAFE_INTEGER) {
|
|
46
|
+
throw new TypeError(`${method} options.minGapMs must not exceed Number.MAX_SAFE_INTEGER.`);
|
|
47
|
+
}
|
|
48
|
+
const gapMicroseconds = BigInt(minGapMs) * 1000n;
|
|
49
|
+
return {
|
|
50
|
+
endTimeColumn,
|
|
51
|
+
gapMicroseconds,
|
|
52
|
+
startTimeColumn,
|
|
53
|
+
strictOrdering: options.strictOrdering ?? true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Prepares native-precision event and transition SQL from a queued schema. */
|
|
57
|
+
export default function prepareGraphTemporalSql(schema, options, method) {
|
|
58
|
+
const start = options.startTimeColumn === undefined
|
|
59
|
+
? undefined
|
|
60
|
+
: getTemporalColumn(schema, options.startTimeColumn, method);
|
|
61
|
+
const end = options.endTimeColumn === undefined
|
|
62
|
+
? undefined
|
|
63
|
+
: getTemporalColumn(schema, options.endTimeColumn, method);
|
|
64
|
+
if (start?.zoned !== undefined && end?.zoned !== undefined) {
|
|
65
|
+
if (start.zoned !== end.zoned) {
|
|
66
|
+
throw new TypeError(`${method} cannot mix time-zone-aware and time-zone-naive chronological columns. Convert both columns to the same timestamp domain first.`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const startColumn = start?.column ?? end.column;
|
|
70
|
+
const endColumn = end?.column ?? start.column;
|
|
71
|
+
const startType = start?.type ?? end.type;
|
|
72
|
+
const endType = end?.type ?? start.type;
|
|
73
|
+
const gapUnit = start?.type === "TIMESTAMP_NS" ||
|
|
74
|
+
end?.type === "TIMESTAMP_NS"
|
|
75
|
+
? "nanosecond"
|
|
76
|
+
: "microsecond";
|
|
77
|
+
const gap = gapUnit === "nanosecond"
|
|
78
|
+
? options.gapMicroseconds * 1000n
|
|
79
|
+
: options.gapMicroseconds;
|
|
80
|
+
const q = quoteIdentifier;
|
|
81
|
+
const reference = (alias, column) => `${alias === undefined ? "" : `${q(alias)}.`}${q(column)}`;
|
|
82
|
+
const eventReference = (alias, name) => `${alias === undefined ? "" : `${q(alias)}.`}${q(name)}`;
|
|
83
|
+
return {
|
|
84
|
+
startTimeColumn: start?.column,
|
|
85
|
+
endTimeColumn: end?.column,
|
|
86
|
+
gapParameter: gap.toString(),
|
|
87
|
+
gapUnit,
|
|
88
|
+
eventSelections: (alias) => [
|
|
89
|
+
`row_number() OVER () AS ${q("__event_id")}`,
|
|
90
|
+
`${reference(alias, startColumn)} AS ${q("__event_start")}`,
|
|
91
|
+
`${reference(alias, endColumn)} AS ${q("__event_end")}`,
|
|
92
|
+
],
|
|
93
|
+
eventValidity: (alias) => {
|
|
94
|
+
const eventStart = eventReference(alias, "__event_start");
|
|
95
|
+
const eventEnd = eventReference(alias, "__event_end");
|
|
96
|
+
return `CASE
|
|
97
|
+
WHEN ${eventStart} IS NULL OR ${eventEnd} IS NULL THEN false
|
|
98
|
+
WHEN NOT isfinite(${eventStart}) OR NOT isfinite(${eventEnd}) THEN false
|
|
99
|
+
ELSE ${temporalUnits(eventEnd, endType, gapUnit)} >= ${temporalUnits(eventStart, startType, gapUnit)}
|
|
100
|
+
END`;
|
|
101
|
+
},
|
|
102
|
+
transition: (currentAlias, candidateAlias, direction, gapExpression) => {
|
|
103
|
+
const currentStart = eventReference(currentAlias, "__event_start");
|
|
104
|
+
const currentEnd = eventReference(currentAlias, "__event_end");
|
|
105
|
+
const candidateStart = eventReference(candidateAlias, "__event_start");
|
|
106
|
+
const candidateEnd = eventReference(candidateAlias, "__event_end");
|
|
107
|
+
const earlierEnd = direction === "outgoing" ? currentEnd : candidateEnd;
|
|
108
|
+
const laterStart = direction === "outgoing"
|
|
109
|
+
? candidateStart
|
|
110
|
+
: currentStart;
|
|
111
|
+
const elapsed = `${temporalUnits(laterStart, startType, gapUnit)} - ${temporalUnits(earlierEnd, endType, gapUnit)}`;
|
|
112
|
+
const ordering = options.strictOrdering
|
|
113
|
+
? `
|
|
114
|
+
AND ${elapsed} > 0`
|
|
115
|
+
: "";
|
|
116
|
+
return `${elapsed} >= ${gapExpression}${ordering}`;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function temporalUnits(expression, type, unit) {
|
|
121
|
+
// Widen before scaling/subtraction to preserve precision and the DATE range.
|
|
122
|
+
const scale = unit === "nanosecond" ? 1000n : 1n;
|
|
123
|
+
if (type === "DATE") {
|
|
124
|
+
return `(CAST(date_diff('day', DATE '1970-01-01', ${expression}) AS HUGEINT) * ${86400000000n * scale})`;
|
|
125
|
+
}
|
|
126
|
+
if (type === "TIMESTAMP_NS") {
|
|
127
|
+
return `CAST(epoch_ns(${expression}) AS HUGEINT)`;
|
|
128
|
+
}
|
|
129
|
+
return `(CAST(epoch_us(${expression}) AS HUGEINT) * ${scale})`;
|
|
130
|
+
}
|
|
131
|
+
function getTemporalColumn(schema, requested, method) {
|
|
132
|
+
const folded = foldIdentifier(requested);
|
|
133
|
+
const column = Object.keys(schema).find((name) => foldIdentifier(name) === folded);
|
|
134
|
+
if (column === undefined) {
|
|
135
|
+
throw new Error(`${method} the column ${quoteIdentifier(requested)} does not exist. Check for typos, or load the data first.`);
|
|
136
|
+
}
|
|
137
|
+
const type = normalizeTemporalType(schema[column]);
|
|
138
|
+
if (!temporalTypes.has(type)) {
|
|
139
|
+
throw new TypeError(`${method} requires DATE or TIMESTAMP chronological columns, but column ${quoteIdentifier(column)} has type ${schema[column].toUpperCase()}.`);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
column,
|
|
143
|
+
type,
|
|
144
|
+
zoned: type === "TIMESTAMP WITH TIME ZONE",
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function normalizeTemporalType(type) {
|
|
148
|
+
const normalized = type.toUpperCase();
|
|
149
|
+
if (normalized === "TIMESTAMPTZ")
|
|
150
|
+
return "TIMESTAMP WITH TIME ZONE";
|
|
151
|
+
if (normalized === "TIMESTAMP WITHOUT TIME ZONE")
|
|
152
|
+
return "TIMESTAMP";
|
|
153
|
+
return normalized;
|
|
154
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type GraphEndpointColumns } from "./getGraphEndpointColumns.js";
|
|
2
|
+
import type { TableSchema } from "./pendingOps.js";
|
|
3
|
+
import type { PreparedGraphStarts } from "./prepareGraphStarts.js";
|
|
4
|
+
export type GraphDirection = "outgoing" | "incoming" | "both";
|
|
5
|
+
export type PreparedGraphTraversal = {
|
|
6
|
+
edges: (direction: GraphDirection, selections?: string[]) => string;
|
|
7
|
+
endpoints: GraphEndpointColumns;
|
|
8
|
+
key: (expression: string) => string;
|
|
9
|
+
relationNames: (names: string[]) => Record<string, string>;
|
|
10
|
+
startValues: string;
|
|
11
|
+
};
|
|
12
|
+
export type PreparedGraphSql = Omit<PreparedGraphTraversal, "startValues">;
|
|
13
|
+
/** Prepares exact-ID SQL shared by graph traversal methods. */
|
|
14
|
+
export default function prepareGraphTraversal(input: string, schema: TableSchema, source: string, target: string, starts: PreparedGraphStarts, method: string, argument?: string): PreparedGraphTraversal;
|
|
15
|
+
/** Prepares exact-ID edge SQL for graph methods without starting nodes. */
|
|
16
|
+
export declare function prepareGraphSql(input: string, schema: TableSchema, source: string, target: string, method: string): PreparedGraphSql;
|
|
17
|
+
/** Validates supplied starts against resolved endpoint ID types. */
|
|
18
|
+
export declare function validateGraphStarts(schema: TableSchema, source: string, target: string, starts: PreparedGraphStarts, method: string, argument?: string): GraphEndpointColumns;
|
|
19
|
+
//# sourceMappingURL=prepareGraphTraversal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareGraphTraversal.d.ts","sourceRoot":"","sources":["../../src/helpers/prepareGraphTraversal.ts"],"names":[],"mappings":"AACA,OAAgC,EAC9B,KAAK,oBAAoB,EAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAGnE,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC;AAE9D,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,CAAC,SAAS,EAAE,cAAc,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;IACpE,SAAS,EAAE,oBAAoB,CAAC;IAChC,GAAG,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3D,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,EAAE,aAAa,CAAC,CAAC;AAE3E,+DAA+D;AAC/D,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC3C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,MAAM,EACd,QAAQ,SAAU,GACjB,sBAAsB,CAcxB;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,gBAAgB,CAKlB;AAwCD,oEAAoE;AACpE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,MAAM,EACd,QAAQ,SAAU,GACjB,oBAAoB,CAyBtB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import foldIdentifier from "./foldIdentifier.js";
|
|
2
|
+
import getGraphEndpointColumns from "./getGraphEndpointColumns.js";
|
|
3
|
+
import quoteIdentifier from "./quoteIdentifier.js";
|
|
4
|
+
/** Prepares exact-ID SQL shared by graph traversal methods. */
|
|
5
|
+
export default function prepareGraphTraversal(input, schema, source, target, starts, method, argument = "start") {
|
|
6
|
+
const endpoints = validateGraphStarts(schema, source, target, starts, method, argument);
|
|
7
|
+
return {
|
|
8
|
+
...prepareGraphSqlFromEndpoints(input, endpoints),
|
|
9
|
+
startValues: starts.values.map(() => `(TRY_CAST(? AS ${endpoints.idType}))`)
|
|
10
|
+
.join(", "),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Prepares exact-ID edge SQL for graph methods without starting nodes. */
|
|
14
|
+
export function prepareGraphSql(input, schema, source, target, method) {
|
|
15
|
+
return prepareGraphSqlFromEndpoints(input, getGraphEndpointColumns(schema, source, target, method));
|
|
16
|
+
}
|
|
17
|
+
function prepareGraphSqlFromEndpoints(input, endpoints) {
|
|
18
|
+
const sourceColumn = quoteIdentifier(endpoints.source);
|
|
19
|
+
const targetColumn = quoteIdentifier(endpoints.target);
|
|
20
|
+
const idType = endpoints.idType;
|
|
21
|
+
const cast = (expression) => `CAST(${expression} AS ${idType})`;
|
|
22
|
+
const key = endpoints.family === "string"
|
|
23
|
+
? (expression) => `ENCODE(${cast(expression)})`
|
|
24
|
+
: cast;
|
|
25
|
+
const edge = (from, to, selections) => `SELECT ${cast(from)} AS ${quoteIdentifier("__from")},
|
|
26
|
+
${cast(to)} AS ${quoteIdentifier("__to")},
|
|
27
|
+
${key(from)} AS ${quoteIdentifier("__from_key")},
|
|
28
|
+
${key(to)} AS ${quoteIdentifier("__to_key")}${selections.length === 0
|
|
29
|
+
? ""
|
|
30
|
+
: `,\n ${selections.join(",\n ")}`}
|
|
31
|
+
FROM ${input} AS ${quoteIdentifier("edges")}`;
|
|
32
|
+
const sourceReference = `${quoteIdentifier("edges")}.${sourceColumn}`;
|
|
33
|
+
const targetReference = `${quoteIdentifier("edges")}.${targetColumn}`;
|
|
34
|
+
return {
|
|
35
|
+
endpoints,
|
|
36
|
+
key,
|
|
37
|
+
edges: (direction, selections = []) => direction === "outgoing"
|
|
38
|
+
? edge(sourceReference, targetReference, selections)
|
|
39
|
+
: direction === "incoming"
|
|
40
|
+
? edge(targetReference, sourceReference, selections)
|
|
41
|
+
: `${edge(sourceReference, targetReference, selections)}\nUNION ALL\n${edge(targetReference, sourceReference, selections)}`,
|
|
42
|
+
relationNames: (names) => uniqueRelationNames(input, names),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Validates supplied starts against resolved endpoint ID types. */
|
|
46
|
+
export function validateGraphStarts(schema, source, target, starts, method, argument = "start") {
|
|
47
|
+
const endpoints = getGraphEndpointColumns(schema, source, target, method);
|
|
48
|
+
const verb = argument === "start" ? "contains" : "contain";
|
|
49
|
+
if (endpoints.family !== starts.family) {
|
|
50
|
+
throw new TypeError(`${method} ${argument} ${verb} ${starts.family} IDs, but endpoint columns ${quoteIdentifier(endpoints.source)} and ${quoteIdentifier(endpoints.target)} contain ${endpoints.family} IDs.`);
|
|
51
|
+
}
|
|
52
|
+
if (endpoints.floating) {
|
|
53
|
+
for (const value of starts.numericValues) {
|
|
54
|
+
const converted = endpoints.idType === "FLOAT"
|
|
55
|
+
? Math.fround(Number(value))
|
|
56
|
+
: Number(value);
|
|
57
|
+
if (!Number.isFinite(converted) || BigInt(converted) !== value) {
|
|
58
|
+
throw new TypeError(`${method} ${argument} ${verb} ${value}n, which ${endpoints.idType} cannot represent exactly.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return endpoints;
|
|
63
|
+
}
|
|
64
|
+
function uniqueRelationNames(input, requestedNames) {
|
|
65
|
+
const used = new Set([foldIdentifier(input)]);
|
|
66
|
+
const names = {};
|
|
67
|
+
for (const requested of requestedNames) {
|
|
68
|
+
let candidate = requested;
|
|
69
|
+
let suffix = 1;
|
|
70
|
+
while (used.has(foldIdentifier(quoteIdentifier(candidate)))) {
|
|
71
|
+
candidate = `${requested}_${suffix}`;
|
|
72
|
+
suffix++;
|
|
73
|
+
}
|
|
74
|
+
const quoted = quoteIdentifier(candidate);
|
|
75
|
+
used.add(foldIdentifier(quoted));
|
|
76
|
+
names[requested] = quoted;
|
|
77
|
+
}
|
|
78
|
+
return names;
|
|
79
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type SimpleTable from "../class/SimpleTable.js";
|
|
2
|
+
/** Returns whether a DuckDB type is a scalar numeric type. */
|
|
3
|
+
export declare function isNumericScalarType(type: string): boolean;
|
|
4
|
+
export type NumericFeatureInput = {
|
|
5
|
+
kind: "scalars";
|
|
6
|
+
columns: string[];
|
|
7
|
+
} | {
|
|
8
|
+
kind: "vector";
|
|
9
|
+
column: string;
|
|
10
|
+
};
|
|
11
|
+
export type PreparedNumericFeatures = {
|
|
12
|
+
/** Raw temporary-relation name. Quote it before embedding it in SQL. */
|
|
13
|
+
relation: string;
|
|
14
|
+
/** Raw private row-identity column name. */
|
|
15
|
+
rowIdColumn: string;
|
|
16
|
+
/** Raw private `DOUBLE[d]` feature column name. */
|
|
17
|
+
vectorColumn: string;
|
|
18
|
+
dimensions: number;
|
|
19
|
+
rowCount: number;
|
|
20
|
+
/** Source column names in their original order and spelling. */
|
|
21
|
+
sourceColumns: string[];
|
|
22
|
+
sourceTemporary: boolean;
|
|
23
|
+
/** Drops all scratch state owned by this preparation. Safe to call twice. */
|
|
24
|
+
cleanup: () => Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Prepares scalar columns or a vector column as a private `DOUBLE[d]` feature
|
|
28
|
+
* vector while retaining every source column in DuckDB. Converting large
|
|
29
|
+
* integers or exact decimals to DOUBLE can lose precision. The source columns
|
|
30
|
+
* remain unchanged, so callers can publish results from the returned snapshot.
|
|
31
|
+
*
|
|
32
|
+
* The private row identity is positional and distinguishes duplicate rows. A
|
|
33
|
+
* caller owns the returned relation and must invoke `cleanup()` in `finally`.
|
|
34
|
+
* Preparation failures clean up their own scratch state.
|
|
35
|
+
*/
|
|
36
|
+
export default function prepareNumericFeatures(table: SimpleTable, input: NumericFeatureInput, options: {
|
|
37
|
+
method: string;
|
|
38
|
+
rejectNulls?: boolean;
|
|
39
|
+
rejectNonFinite?: boolean;
|
|
40
|
+
}): Promise<PreparedNumericFeatures>;
|
|
41
|
+
//# sourceMappingURL=prepareNumericFeatures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareNumericFeatures.d.ts","sourceRoot":"","sources":["../../src/helpers/prepareNumericFeatures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAOvD,8DAA8D;AAC9D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC,MAAM,MAAM,uBAAuB,GAAG;IACpC,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,EAAE,OAAO,CAAC;IACzB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAA8B,sBAAsB,CAClD,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GACA,OAAO,CAAC,uBAAuB,CAAC,CA2MlC"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import foldIdentifier from "./foldIdentifier.js";
|
|
2
|
+
import quoteIdentifier from "./quoteIdentifier.js";
|
|
3
|
+
const NUMERIC_SCALAR_TYPE = /^(?:TINYINT|SMALLINT|INTEGER|BIGINT|HUGEINT|UTINYINT|USMALLINT|UINTEGER|UBIGINT|UHUGEINT|BIGNUM|FLOAT|REAL|DOUBLE|DECIMAL\(\d+,\d+\))$/;
|
|
4
|
+
/** Returns whether a DuckDB type is a scalar numeric type. */
|
|
5
|
+
export function isNumericScalarType(type) {
|
|
6
|
+
return NUMERIC_SCALAR_TYPE.test(type);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Prepares scalar columns or a vector column as a private `DOUBLE[d]` feature
|
|
10
|
+
* vector while retaining every source column in DuckDB. Converting large
|
|
11
|
+
* integers or exact decimals to DOUBLE can lose precision. The source columns
|
|
12
|
+
* remain unchanged, so callers can publish results from the returned snapshot.
|
|
13
|
+
*
|
|
14
|
+
* The private row identity is positional and distinguishes duplicate rows. A
|
|
15
|
+
* caller owns the returned relation and must invoke `cleanup()` in `finally`.
|
|
16
|
+
* Preparation failures clean up their own scratch state.
|
|
17
|
+
*/
|
|
18
|
+
export default async function prepareNumericFeatures(table, input, options) {
|
|
19
|
+
const rejectNulls = options.rejectNulls ?? true;
|
|
20
|
+
const rejectNonFinite = options.rejectNonFinite ?? true;
|
|
21
|
+
const types = await table.getTypes();
|
|
22
|
+
// Object.keys(types) sorts integer-like identifiers, which would reorder
|
|
23
|
+
// source columns when algorithms publish from this snapshot.
|
|
24
|
+
const sourceColumns = await table.getColumns();
|
|
25
|
+
const resolveColumn = (requested) => {
|
|
26
|
+
const resolved = sourceColumns.find((column) => foldIdentifier(column) === foldIdentifier(requested));
|
|
27
|
+
if (resolved === undefined) {
|
|
28
|
+
throw new Error(`${options.method} could not find column ${quoteIdentifier(requested)}. Available columns: ${sourceColumns.map(quoteIdentifier).join(", ")}.`);
|
|
29
|
+
}
|
|
30
|
+
return resolved;
|
|
31
|
+
};
|
|
32
|
+
let selectedColumns;
|
|
33
|
+
let vectorType;
|
|
34
|
+
if (input.kind === "scalars") {
|
|
35
|
+
if (input.columns.length === 0) {
|
|
36
|
+
throw new Error(`${options.method} requires at least one numeric scalar column.`);
|
|
37
|
+
}
|
|
38
|
+
const duplicate = findDuplicate(input.columns);
|
|
39
|
+
if (duplicate !== undefined) {
|
|
40
|
+
throw new Error(`${options.method} received duplicate input column ${quoteIdentifier(duplicate)}. Each numeric feature column must be listed once.`);
|
|
41
|
+
}
|
|
42
|
+
selectedColumns = input.columns.map(resolveColumn);
|
|
43
|
+
const nonNumeric = selectedColumns.filter((column) => !isNumericScalarType(types[column]));
|
|
44
|
+
if (nonNumeric.length > 0) {
|
|
45
|
+
throw new Error(`${options.method} requires numeric scalar columns. The following input columns are not numeric scalars: ${nonNumeric.map((column) => `${quoteIdentifier(column)} (${types[column]})`).join(", ")}. Convert them to numeric scalar types first.`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const column = resolveColumn(input.column);
|
|
50
|
+
selectedColumns = [column];
|
|
51
|
+
vectorType = parseNumericVectorType(types[column]);
|
|
52
|
+
if (vectorType === undefined) {
|
|
53
|
+
throw new Error(`${options.method} requires a one-dimensional numeric LIST or ARRAY column, but ${quoteIdentifier(column)} has type ${types[column]}.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const connection = table.connection;
|
|
57
|
+
const source = quoteIdentifier(table.name);
|
|
58
|
+
const suffix = crypto.randomUUID().replaceAll("-", "");
|
|
59
|
+
const relation = `__sda_features_${suffix}`;
|
|
60
|
+
const rowIdColumn = `__sda_row_${suffix}`;
|
|
61
|
+
const vectorColumn = `__sda_vector_${suffix}`;
|
|
62
|
+
const preparedRelation = quoteIdentifier(relation);
|
|
63
|
+
let cleaned = false;
|
|
64
|
+
const cleanup = async () => {
|
|
65
|
+
if (cleaned)
|
|
66
|
+
return;
|
|
67
|
+
await connection.run(`DROP TABLE IF EXISTS ${preparedRelation}`);
|
|
68
|
+
cleaned = true;
|
|
69
|
+
};
|
|
70
|
+
try {
|
|
71
|
+
const tableDetails = (await connection.runAndReadAll(`SELECT table_oid, temporary FROM duckdb_tables()
|
|
72
|
+
WHERE translate(table_name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = $1
|
|
73
|
+
AND schema_name = current_schema()
|
|
74
|
+
AND database_name IN (current_database(), 'temp')
|
|
75
|
+
ORDER BY temporary DESC LIMIT 1`, [foldIdentifier(table.name)])).getRowsJS()[0];
|
|
76
|
+
if (tableDetails === undefined) {
|
|
77
|
+
throw new Error(`${options.method} requires a materialized source table.`);
|
|
78
|
+
}
|
|
79
|
+
const sourceTemporary = Boolean(tableDetails[1]);
|
|
80
|
+
const rowCount = Number((await connection.runAndReadAll(`SELECT count(*) FROM ${source}`))
|
|
81
|
+
.getRowsJS()[0][0]);
|
|
82
|
+
let dimensions;
|
|
83
|
+
let vectorExpression;
|
|
84
|
+
if (input.kind === "scalars") {
|
|
85
|
+
dimensions = selectedColumns.length;
|
|
86
|
+
await rejectInvalidScalarRows(connection, source, selectedColumns, types, options.method, { rejectNulls, rejectNonFinite });
|
|
87
|
+
vectorExpression = `[${selectedColumns.map((column) => castToDouble(quoteIdentifier(column), types[column]))
|
|
88
|
+
.join(", ")}]::DOUBLE[${dimensions}]`;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const column = selectedColumns[0];
|
|
92
|
+
const quotedColumn = quoteIdentifier(column);
|
|
93
|
+
const emptyRows = Number((await connection.runAndReadAll(`SELECT count(*) FROM ${source}
|
|
94
|
+
WHERE ${quotedColumn} IS NOT NULL AND len(${quotedColumn}) = 0`)).getRowsJS()[0][0]);
|
|
95
|
+
if (emptyRows > 0) {
|
|
96
|
+
throw new Error(`${options.method} found ${emptyRows} row${emptyRows === 1 ? "" : "s"} with an empty vector in column ${quoteIdentifier(column)}. Vectors must have a nonzero dimension.`);
|
|
97
|
+
}
|
|
98
|
+
await rejectInvalidVectorRows(connection, source, column, vectorType.elementType, options.method, { rejectNulls, rejectNonFinite });
|
|
99
|
+
if (vectorType?.fixedDimensions !== undefined) {
|
|
100
|
+
dimensions = vectorType.fixedDimensions;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const dimensionRows = (await connection.runAndReadAll(`SELECT len(${quotedColumn}) AS dimensions
|
|
104
|
+
FROM ${source} WHERE ${quotedColumn} IS NOT NULL LIMIT 1`)).getRowsJS();
|
|
105
|
+
if (dimensionRows.length === 0) {
|
|
106
|
+
throw new Error(`${options.method} could not determine a vector dimension for ${quoteIdentifier(column)}. Provide at least one non-null, nonempty vector.`);
|
|
107
|
+
}
|
|
108
|
+
dimensions = Number(dimensionRows[0][0]);
|
|
109
|
+
}
|
|
110
|
+
const distinctDimensions = Number((await connection.runAndReadAll(`SELECT count(DISTINCT len(${quotedColumn})) FROM ${source}
|
|
111
|
+
WHERE ${quotedColumn} IS NOT NULL`)).getRowsJS()[0][0]);
|
|
112
|
+
if (distinctDimensions > 1) {
|
|
113
|
+
throw new Error(`${options.method} requires vectors with equal dimensions, but column ${quoteIdentifier(column)} contains ${distinctDimensions} different lengths.`);
|
|
114
|
+
}
|
|
115
|
+
vectorExpression = vectorType.elementType === "BIGNUM"
|
|
116
|
+
? `list_transform(${quotedColumn}, value -> ${castToDouble("value", "BIGNUM")})::DOUBLE[${dimensions}]`
|
|
117
|
+
: `${quotedColumn}::DOUBLE[${dimensions}]`;
|
|
118
|
+
}
|
|
119
|
+
await connection.run(`CREATE TEMP TABLE ${preparedRelation} AS
|
|
120
|
+
SELECT *, row_number() OVER () - 1 AS ${quoteIdentifier(rowIdColumn)}, ${vectorExpression} AS ${quoteIdentifier(vectorColumn)}
|
|
121
|
+
FROM ${source}`);
|
|
122
|
+
return {
|
|
123
|
+
relation,
|
|
124
|
+
rowIdColumn,
|
|
125
|
+
vectorColumn,
|
|
126
|
+
dimensions,
|
|
127
|
+
rowCount,
|
|
128
|
+
sourceColumns,
|
|
129
|
+
sourceTemporary,
|
|
130
|
+
cleanup,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
await cleanup();
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function parseNumericVectorType(type) {
|
|
139
|
+
const match = /^(.+)\[(\d*)\]$/.exec(type);
|
|
140
|
+
if (match === null || !isNumericScalarType(match[1]))
|
|
141
|
+
return undefined;
|
|
142
|
+
const elementType = match[1];
|
|
143
|
+
if (match[2] === "")
|
|
144
|
+
return { elementType };
|
|
145
|
+
const fixedDimensions = Number(match[2]);
|
|
146
|
+
return fixedDimensions > 0 ? { elementType, fixedDimensions } : undefined;
|
|
147
|
+
}
|
|
148
|
+
function findDuplicate(columns) {
|
|
149
|
+
const seen = new Set();
|
|
150
|
+
for (const column of columns) {
|
|
151
|
+
const folded = foldIdentifier(column);
|
|
152
|
+
if (seen.has(folded))
|
|
153
|
+
return column;
|
|
154
|
+
seen.add(folded);
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
async function rejectInvalidScalarRows(connection, source, columns, types, method, validation) {
|
|
159
|
+
const predicates = columns.map((column) => {
|
|
160
|
+
const value = quoteIdentifier(column);
|
|
161
|
+
const converted = castToDouble(value, types[column], true);
|
|
162
|
+
const checks = [];
|
|
163
|
+
if (validation.rejectNulls)
|
|
164
|
+
checks.push(`${value} IS NULL`);
|
|
165
|
+
if (validation.rejectNonFinite) {
|
|
166
|
+
checks.push(`(${value} IS NOT NULL AND (${converted} IS NULL OR NOT isfinite(${converted})))`);
|
|
167
|
+
}
|
|
168
|
+
return checks.length === 0 ? "FALSE" : `(${checks.join(" OR ")})`;
|
|
169
|
+
});
|
|
170
|
+
if (predicates.every((predicate) => predicate === "FALSE"))
|
|
171
|
+
return;
|
|
172
|
+
const aliases = columns.map((_, index) => `invalid_${index}`);
|
|
173
|
+
const query = `SELECT
|
|
174
|
+
count(*) FILTER (WHERE ${predicates.join(" OR ")}) AS invalid_rows,
|
|
175
|
+
${predicates.map((predicate, index) => `count(*) FILTER (WHERE ${predicate}) AS ${aliases[index]}`).join(", ")}
|
|
176
|
+
FROM ${source}`;
|
|
177
|
+
const row = (await connection.runAndReadAll(query)).getRowsJS()[0];
|
|
178
|
+
const invalidRows = Number(row[0]);
|
|
179
|
+
if (invalidRows === 0)
|
|
180
|
+
return;
|
|
181
|
+
const affected = columns.flatMap((column, index) => {
|
|
182
|
+
const count = Number(row[index + 1]);
|
|
183
|
+
return count === 0
|
|
184
|
+
? []
|
|
185
|
+
: [`${quoteIdentifier(column)} (${count} row${count === 1 ? "" : "s"})`];
|
|
186
|
+
});
|
|
187
|
+
throw new Error(`${method} requires finite, non-null numeric features. Found ${invalidRows} invalid row${invalidRows === 1 ? "" : "s"}. Affected columns: ${affected.join(", ")}.`);
|
|
188
|
+
}
|
|
189
|
+
async function rejectInvalidVectorRows(connection, source, column, elementType, method, validation) {
|
|
190
|
+
const vector = quoteIdentifier(column);
|
|
191
|
+
const checks = [];
|
|
192
|
+
if (validation.rejectNulls) {
|
|
193
|
+
checks.push(`${vector} IS NULL`);
|
|
194
|
+
checks.push(`(${vector} IS NOT NULL AND list_count(${vector}) != len(${vector}))`);
|
|
195
|
+
}
|
|
196
|
+
if (validation.rejectNonFinite) {
|
|
197
|
+
checks.push(`(${vector} IS NOT NULL AND COALESCE(NOT list_bool_and(list_transform(${vector}, value -> value IS NULL OR COALESCE(isfinite(${castToDouble("value", elementType, true)}), FALSE))), FALSE))`);
|
|
198
|
+
}
|
|
199
|
+
if (checks.length === 0)
|
|
200
|
+
return;
|
|
201
|
+
const invalidRows = Number((await connection.runAndReadAll(`SELECT count(*) FROM ${source} WHERE ${checks.join(" OR ")}`)).getRowsJS()[0][0]);
|
|
202
|
+
if (invalidRows === 0)
|
|
203
|
+
return;
|
|
204
|
+
throw new Error(`${method} requires finite, non-null vector values. Column ${quoteIdentifier(column)} has ${invalidRows} invalid row${invalidRows === 1 ? "" : "s"}.`);
|
|
205
|
+
}
|
|
206
|
+
/** BIGNUM's direct DOUBLE conversion can throw even inside DuckDB TRY_CAST. */
|
|
207
|
+
function castToDouble(value, type, tryCast = false) {
|
|
208
|
+
const convertible = type === "BIGNUM" ? `CAST(${value} AS VARCHAR)` : value;
|
|
209
|
+
return `${tryCast ? "TRY_CAST" : "CAST"}(${convertible} AS DOUBLE)`;
|
|
210
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default function prepareUmapLayoutOptions(options?: {
|
|
2
|
+
epochs?: number;
|
|
3
|
+
seed?: number;
|
|
4
|
+
minDistance?: number;
|
|
5
|
+
learningRate?: number;
|
|
6
|
+
negativeSamples?: number;
|
|
7
|
+
}): {
|
|
8
|
+
epochs: number;
|
|
9
|
+
seed: number;
|
|
10
|
+
learningRate: number;
|
|
11
|
+
negativeSamples: number;
|
|
12
|
+
curve: [number, number];
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=prepareUmapLayoutOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareUmapLayoutOptions.d.ts","sourceRoot":"","sources":["../../src/helpers/prepareUmapLayoutOptions.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAC9C,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CACrB;;;;;;EA2BP"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fitUmapCurve from "./fitUmapCurve.js";
|
|
2
|
+
// Resolve and validate settings before database work, fitting the curve once.
|
|
3
|
+
export default function prepareUmapLayoutOptions(options = {}) {
|
|
4
|
+
const { epochs = 200, seed = 42, minDistance = 0.1, learningRate = 1, negativeSamples = 5, } = options;
|
|
5
|
+
for (const [key, value] of Object.entries({ epochs, negativeSamples })) {
|
|
6
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
7
|
+
throw new Error(`${key} must be a positive safe integer.`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
if (!Number.isInteger(seed) || seed < 0 || seed > 0xffffffff) {
|
|
11
|
+
throw new Error("seed must be an integer between 0 and 4294967295.");
|
|
12
|
+
}
|
|
13
|
+
if (!Number.isFinite(learningRate) || learningRate <= 0) {
|
|
14
|
+
throw new Error("learningRate must be finite and positive.");
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
epochs,
|
|
18
|
+
seed,
|
|
19
|
+
learningRate,
|
|
20
|
+
negativeSamples,
|
|
21
|
+
curve: fitUmapCurve(minDistance),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -3,14 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The function can calculate the duration from a given start time to the current time, or between a specified start and end time. It provides options for logging the output directly to the console and adding custom prefixes or suffixes to the formatted string. Note that for simplicity, months are approximated as 30 days and years as 365 days.
|
|
5
5
|
*
|
|
6
|
-
* @param start - The starting point of the duration. This can be a `Date` object or a Unix timestamp (number of milliseconds since epoch).
|
|
7
|
-
* @param options - Optional settings to customize the duration formatting and output.
|
|
8
|
-
* @param options.log - If `true`, the formatted duration string will be logged to the console. Defaults to `false`.
|
|
9
|
-
* @param options.end - The ending point of the duration. This can be a `Date` object or a Unix timestamp. If omitted, the current time (`Date.now()`) will be used as the end point.
|
|
10
|
-
* @param options.prefix - A string to prepend to the formatted duration string (e.g., "Elapsed time: ").
|
|
11
|
-
* @param options.suffix - A string to append to the formatted duration string (e.g., " (Task completed)").
|
|
12
|
-
* @returns A human-readable string representing the duration.
|
|
13
|
-
*
|
|
14
6
|
* @example
|
|
15
7
|
* ```ts
|
|
16
8
|
* // A starting Date somewhere in your code.
|
|
@@ -20,6 +12,7 @@
|
|
|
20
12
|
* const duration = prettyDuration(startDate);
|
|
21
13
|
* console.log(duration); // Returns something like "22 days, 6 h, 3 min, 15 sec, 3 ms"
|
|
22
14
|
* ```
|
|
15
|
+
*
|
|
23
16
|
* @example
|
|
24
17
|
* ```ts
|
|
25
18
|
* // If you want to console.log it directly, set the `log` option to `true`.
|
|
@@ -28,6 +21,7 @@
|
|
|
28
21
|
* // ... some operations ...
|
|
29
22
|
* prettyDuration(startDateForLog, { log: true });
|
|
30
23
|
* ```
|
|
24
|
+
*
|
|
31
25
|
* @example
|
|
32
26
|
* ```ts
|
|
33
27
|
* // You can also use a prefix and/or suffix for the output string.
|
|
@@ -36,6 +30,7 @@
|
|
|
36
30
|
* prettyDuration(startDateWithPrefixSuffix, { log: true, prefix: "Elapsed time: ", suffix: " (Main function)" });
|
|
37
31
|
* // Returns and logs something like "Total duration: 3 min, 15 sec, 3 ms (Main function)"
|
|
38
32
|
* ```
|
|
33
|
+
*
|
|
39
34
|
* @example
|
|
40
35
|
* ```ts
|
|
41
36
|
* // If you want to format the duration between two specific dates, use the `end` option.
|
|
@@ -44,6 +39,17 @@
|
|
|
44
39
|
* const specificDuration = prettyDuration(start, { end });
|
|
45
40
|
* console.log(specificDuration); // Returns "22 days, 6 h, 3 min, 15 sec, 0 ms"
|
|
46
41
|
* ```
|
|
42
|
+
*
|
|
43
|
+
* @param start - The starting point of the duration. This can be a `Date` object or a Unix timestamp (number of milliseconds since epoch).
|
|
44
|
+
*
|
|
45
|
+
* @param options - Optional settings to customize the duration formatting and output.
|
|
46
|
+
* @param options.log - If `true`, the formatted duration string will be logged to the console. Defaults to `false`.
|
|
47
|
+
* @param options.end - The ending point of the duration. This can be a `Date` object or a Unix timestamp. If omitted, the current time (`Date.now()`) will be used as the end point.
|
|
48
|
+
* @param options.prefix - A string to prepend to the formatted duration string (e.g., "Elapsed time: ").
|
|
49
|
+
* @param options.suffix - A string to append to the formatted duration string (e.g., " (Task completed)").
|
|
50
|
+
*
|
|
51
|
+
* @returns A human-readable string representing the duration.
|
|
52
|
+
*
|
|
47
53
|
* @category Formatting
|
|
48
54
|
*/
|
|
49
55
|
export default function prettyDuration(start: Date | number, options?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prettyDuration.d.ts","sourceRoot":"","sources":["../../src/helpers/prettyDuration.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"prettyDuration.d.ts","sourceRoot":"","sources":["../../src/helpers/prettyDuration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,KAAK,EAAE,IAAI,GAAG,MAAM,EACpB,OAAO,GAAE;IACP,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACZ,GACL,MAAM,CAuGR"}
|