@nshiab/simple-data-analysis-core 2.0.4 → 2.0.6
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/README.md +118 -12
- package/esm/class/Simple.d.ts +8 -2
- package/esm/class/Simple.d.ts.map +1 -1
- package/esm/class/Simple.js +9 -3
- package/esm/class/SimpleDB.d.ts +72 -1
- package/esm/class/SimpleDB.d.ts.map +1 -1
- package/esm/class/SimpleDB.js +81 -1
- package/esm/class/SimpleTable.d.ts +434 -263
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +441 -316
- package/esm/helpers/LogValue.d.ts +8 -0
- package/esm/helpers/LogValue.d.ts.map +1 -0
- package/esm/helpers/LogValue.js +23 -0
- package/esm/helpers/cacheTableDependencies.d.ts +9 -0
- package/esm/helpers/cacheTableDependencies.d.ts.map +1 -1
- package/esm/helpers/cacheTableDependencies.js +131 -21
- package/esm/helpers/cleanSQL.d.ts +1 -1
- package/esm/helpers/cleanSQL.d.ts.map +1 -1
- package/esm/helpers/cleanSQL.js +268 -23
- package/esm/helpers/flushAllTables.d.ts.map +1 -1
- package/esm/helpers/flushAllTables.js +23 -28
- package/esm/helpers/foldIdentifier.d.ts +3 -0
- package/esm/helpers/foldIdentifier.d.ts.map +1 -0
- package/esm/helpers/foldIdentifier.js +4 -0
- package/esm/helpers/geometryFromJSON.d.ts +3 -0
- package/esm/helpers/geometryFromJSON.d.ts.map +1 -0
- package/esm/helpers/geometryFromJSON.js +4 -0
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.d.ts.map +1 -1
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/logData.d.ts.map +1 -1
- package/esm/helpers/logData.js +45 -44
- package/esm/helpers/makeLogConverter.d.ts +5 -0
- package/esm/helpers/makeLogConverter.d.ts.map +1 -0
- package/esm/helpers/makeLogConverter.js +64 -0
- package/esm/helpers/osmFiles.d.ts.map +1 -1
- package/esm/helpers/parseTypes.d.ts +1 -1
- package/esm/helpers/parseTypes.d.ts.map +1 -1
- package/esm/helpers/parseTypes.js +4 -0
- package/esm/helpers/pendingOps.d.ts +4 -2
- package/esm/helpers/pendingOps.d.ts.map +1 -1
- package/esm/helpers/prepareGeometry.d.ts +3 -0
- package/esm/helpers/prepareGeometry.d.ts.map +1 -0
- package/esm/helpers/prepareGeometry.js +99 -0
- package/esm/helpers/prepareJSON.d.ts +3 -0
- package/esm/helpers/prepareJSON.d.ts.map +1 -0
- package/esm/helpers/prepareJSON.js +50 -0
- package/esm/helpers/printTable.d.ts +5 -4
- package/esm/helpers/printTable.d.ts.map +1 -1
- package/esm/helpers/printTable.js +32 -36
- package/esm/helpers/queryDB.js +1 -1
- package/esm/helpers/queueAsyncBarrier.d.ts +4 -0
- package/esm/helpers/queueAsyncBarrier.d.ts.map +1 -1
- package/esm/helpers/queueAsyncBarrier.js +4 -0
- package/esm/helpers/queueOp.d.ts.map +1 -1
- package/esm/helpers/queueOp.js +5 -3
- package/esm/helpers/readMutationRows.d.ts +9 -0
- package/esm/helpers/readMutationRows.d.ts.map +1 -0
- package/esm/helpers/readMutationRows.js +94 -0
- package/esm/helpers/referencedTables.d.ts +9 -0
- package/esm/helpers/referencedTables.d.ts.map +1 -0
- package/esm/helpers/referencedTables.js +22 -0
- package/esm/helpers/runQuery.d.ts.map +1 -1
- package/esm/helpers/runQuery.js +11 -13
- package/esm/helpers/scanSQL.d.ts +7 -0
- package/esm/helpers/scanSQL.d.ts.map +1 -0
- package/esm/helpers/scanSQL.js +71 -0
- package/esm/helpers/tableRegistry.d.ts +2 -0
- package/esm/helpers/tableRegistry.d.ts.map +1 -1
- package/esm/helpers/tableRegistry.js +12 -4
- package/esm/helpers/updateColumnsWithJS.d.ts +52 -0
- package/esm/helpers/updateColumnsWithJS.d.ts.map +1 -0
- package/esm/helpers/updateColumnsWithJS.js +139 -0
- package/esm/methods/addCharacterCount.d.ts +3 -0
- package/esm/methods/addCharacterCount.d.ts.map +1 -0
- package/esm/methods/addCharacterCount.js +15 -0
- package/esm/methods/addColumn.d.ts +1 -1
- package/esm/methods/addColumn.d.ts.map +1 -1
- package/esm/methods/addGeoNoise.d.ts +7 -0
- package/esm/methods/addGeoNoise.d.ts.map +1 -0
- package/esm/methods/addGeoNoise.js +135 -0
- package/esm/methods/addNoise.d.ts +5 -0
- package/esm/methods/addNoise.d.ts.map +1 -0
- package/esm/methods/addNoise.js +53 -0
- package/esm/methods/addWordCount.d.ts +3 -0
- package/esm/methods/addWordCount.d.ts.map +1 -0
- package/esm/methods/addWordCount.js +15 -0
- package/esm/methods/bm25.d.ts.map +1 -1
- package/esm/methods/bm25.js +1 -2
- package/esm/methods/cache.d.ts.map +1 -1
- package/esm/methods/cache.js +4 -6
- package/esm/methods/columnProportions.d.ts +1 -0
- package/esm/methods/columnProportions.d.ts.map +1 -1
- package/esm/methods/columnProportions.js +7 -2
- package/esm/methods/convert.d.ts +2 -2
- package/esm/methods/convert.d.ts.map +1 -1
- package/esm/methods/convert.js +5 -0
- package/esm/methods/getBottom.d.ts +1 -1
- package/esm/methods/getBottom.d.ts.map +1 -1
- package/esm/methods/getBottom.js +2 -2
- package/esm/methods/getData.d.ts +1 -1
- package/esm/methods/getData.d.ts.map +1 -1
- package/esm/methods/getData.js +2 -2
- package/esm/methods/join.d.ts.map +1 -1
- package/esm/methods/join.js +8 -16
- package/esm/methods/joinGeo.d.ts.map +1 -1
- package/esm/methods/joinGeo.js +10 -19
- package/esm/methods/loadArray.d.ts +4 -2
- package/esm/methods/loadArray.d.ts.map +1 -1
- package/esm/methods/loadArray.js +182 -18
- package/esm/methods/loadData.js +3 -0
- package/esm/methods/loadYahooFinanceData.d.ts +10 -0
- package/esm/methods/loadYahooFinanceData.d.ts.map +1 -0
- package/esm/methods/loadYahooFinanceData.js +133 -0
- package/esm/methods/log.d.ts +7 -0
- package/esm/methods/log.d.ts.map +1 -0
- package/esm/methods/log.js +58 -0
- package/esm/methods/logBottom.d.ts +5 -0
- package/esm/methods/logBottom.d.ts.map +1 -0
- package/esm/methods/logBottom.js +9 -0
- package/esm/methods/removeTable.d.ts.map +1 -1
- package/esm/methods/removeTable.js +2 -0
- package/esm/methods/removeTables.d.ts.map +1 -1
- package/esm/methods/removeTables.js +7 -0
- package/esm/methods/renameTable.d.ts.map +1 -1
- package/esm/methods/renameTable.js +4 -0
- package/esm/methods/rowProportions.d.ts +1 -0
- package/esm/methods/rowProportions.d.ts.map +1 -1
- package/esm/methods/rowProportions.js +5 -1
- package/esm/methods/rowToText.js +2 -2
- package/esm/methods/selectTables.d.ts.map +1 -1
- package/esm/methods/selectTables.js +6 -0
- package/esm/methods/setTypes.d.ts +1 -1
- package/esm/methods/setTypes.d.ts.map +1 -1
- package/esm/methods/stream.d.ts.map +1 -1
- package/esm/methods/stream.js +2 -1
- package/esm/methods/updateWithJS.d.ts +1 -3
- package/esm/methods/updateWithJS.d.ts.map +1 -1
- package/esm/methods/updateWithJS.js +123 -37
- package/llm.md +600 -430
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/script/class/Simple.d.ts +8 -2
- package/script/class/Simple.d.ts.map +1 -1
- package/script/class/Simple.js +9 -3
- package/script/class/SimpleDB.d.ts +72 -1
- package/script/class/SimpleDB.d.ts.map +1 -1
- package/script/class/SimpleDB.js +81 -1
- package/script/class/SimpleTable.d.ts +434 -263
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +441 -316
- package/script/helpers/LogValue.d.ts +8 -0
- package/script/helpers/LogValue.d.ts.map +1 -0
- package/script/helpers/LogValue.js +26 -0
- package/script/helpers/cacheTableDependencies.d.ts +9 -0
- package/script/helpers/cacheTableDependencies.d.ts.map +1 -1
- package/script/helpers/cacheTableDependencies.js +170 -20
- package/script/helpers/cleanSQL.d.ts +1 -1
- package/script/helpers/cleanSQL.d.ts.map +1 -1
- package/script/helpers/cleanSQL.js +271 -23
- package/script/helpers/flushAllTables.d.ts.map +1 -1
- package/script/helpers/flushAllTables.js +24 -29
- package/script/helpers/foldIdentifier.d.ts +3 -0
- package/script/helpers/foldIdentifier.d.ts.map +1 -0
- package/script/helpers/foldIdentifier.js +7 -0
- package/script/helpers/geometryFromJSON.d.ts +3 -0
- package/script/helpers/geometryFromJSON.d.ts.map +1 -0
- package/script/helpers/geometryFromJSON.js +7 -0
- package/script/helpers/index.d.ts +1 -0
- package/script/helpers/index.d.ts.map +1 -1
- package/script/helpers/index.js +3 -1
- package/script/helpers/logData.d.ts.map +1 -1
- package/script/helpers/logData.js +45 -44
- package/script/helpers/makeLogConverter.d.ts +5 -0
- package/script/helpers/makeLogConverter.d.ts.map +1 -0
- package/script/helpers/makeLogConverter.js +70 -0
- package/script/helpers/osmFiles.d.ts.map +1 -1
- package/script/helpers/parseTypes.d.ts +1 -1
- package/script/helpers/parseTypes.d.ts.map +1 -1
- package/script/helpers/parseTypes.js +4 -0
- package/script/helpers/pendingOps.d.ts +4 -2
- package/script/helpers/pendingOps.d.ts.map +1 -1
- package/script/helpers/prepareGeometry.d.ts +3 -0
- package/script/helpers/prepareGeometry.d.ts.map +1 -0
- package/script/helpers/prepareGeometry.js +102 -0
- package/script/helpers/prepareJSON.d.ts +3 -0
- package/script/helpers/prepareJSON.d.ts.map +1 -0
- package/script/helpers/prepareJSON.js +53 -0
- package/script/helpers/printTable.d.ts +5 -4
- package/script/helpers/printTable.d.ts.map +1 -1
- package/script/helpers/printTable.js +32 -36
- package/script/helpers/queryDB.js +1 -1
- package/script/helpers/queueAsyncBarrier.d.ts +4 -0
- package/script/helpers/queueAsyncBarrier.d.ts.map +1 -1
- package/script/helpers/queueAsyncBarrier.js +4 -0
- package/script/helpers/queueOp.d.ts.map +1 -1
- package/script/helpers/queueOp.js +4 -2
- package/script/helpers/readMutationRows.d.ts +9 -0
- package/script/helpers/readMutationRows.d.ts.map +1 -0
- package/script/helpers/readMutationRows.js +97 -0
- package/script/helpers/referencedTables.d.ts +9 -0
- package/script/helpers/referencedTables.d.ts.map +1 -0
- package/script/helpers/referencedTables.js +28 -0
- package/script/helpers/runQuery.d.ts.map +1 -1
- package/script/helpers/runQuery.js +11 -13
- package/script/helpers/scanSQL.d.ts +7 -0
- package/script/helpers/scanSQL.d.ts.map +1 -0
- package/script/helpers/scanSQL.js +74 -0
- package/script/helpers/tableRegistry.d.ts +2 -0
- package/script/helpers/tableRegistry.d.ts.map +1 -1
- package/script/helpers/tableRegistry.js +16 -4
- package/script/helpers/updateColumnsWithJS.d.ts +52 -0
- package/script/helpers/updateColumnsWithJS.d.ts.map +1 -0
- package/script/helpers/updateColumnsWithJS.js +145 -0
- package/script/methods/addCharacterCount.d.ts +3 -0
- package/script/methods/addCharacterCount.d.ts.map +1 -0
- package/script/methods/addCharacterCount.js +21 -0
- package/script/methods/addColumn.d.ts +1 -1
- package/script/methods/addColumn.d.ts.map +1 -1
- package/script/methods/addGeoNoise.d.ts +7 -0
- package/script/methods/addGeoNoise.d.ts.map +1 -0
- package/script/methods/addGeoNoise.js +141 -0
- package/script/methods/addNoise.d.ts +5 -0
- package/script/methods/addNoise.d.ts.map +1 -0
- package/script/methods/addNoise.js +59 -0
- package/script/methods/addWordCount.d.ts +3 -0
- package/script/methods/addWordCount.d.ts.map +1 -0
- package/script/methods/addWordCount.js +21 -0
- package/script/methods/bm25.d.ts.map +1 -1
- package/script/methods/bm25.js +1 -2
- package/script/methods/cache.d.ts.map +1 -1
- package/script/methods/cache.js +3 -5
- package/script/methods/columnProportions.d.ts +1 -0
- package/script/methods/columnProportions.d.ts.map +1 -1
- package/script/methods/columnProportions.js +7 -2
- package/script/methods/convert.d.ts +2 -2
- package/script/methods/convert.d.ts.map +1 -1
- package/script/methods/convert.js +5 -0
- package/script/methods/getBottom.d.ts +1 -1
- package/script/methods/getBottom.d.ts.map +1 -1
- package/script/methods/getBottom.js +2 -2
- package/script/methods/getData.d.ts +1 -1
- package/script/methods/getData.d.ts.map +1 -1
- package/script/methods/getData.js +2 -2
- package/script/methods/join.d.ts.map +1 -1
- package/script/methods/join.js +8 -16
- package/script/methods/joinGeo.d.ts.map +1 -1
- package/script/methods/joinGeo.js +10 -19
- package/script/methods/loadArray.d.ts +4 -2
- package/script/methods/loadArray.d.ts.map +1 -1
- package/script/methods/loadArray.js +181 -17
- package/script/methods/loadData.js +3 -0
- package/script/methods/loadYahooFinanceData.d.ts +10 -0
- package/script/methods/loadYahooFinanceData.d.ts.map +1 -0
- package/script/methods/loadYahooFinanceData.js +139 -0
- package/script/methods/log.d.ts +7 -0
- package/script/methods/log.d.ts.map +1 -0
- package/script/methods/log.js +64 -0
- package/script/methods/logBottom.d.ts +5 -0
- package/script/methods/logBottom.d.ts.map +1 -0
- package/script/methods/logBottom.js +15 -0
- package/script/methods/removeTable.d.ts.map +1 -1
- package/script/methods/removeTable.js +2 -0
- package/script/methods/removeTables.d.ts.map +1 -1
- package/script/methods/removeTables.js +7 -0
- package/script/methods/renameTable.d.ts.map +1 -1
- package/script/methods/renameTable.js +4 -0
- package/script/methods/rowProportions.d.ts +1 -0
- package/script/methods/rowProportions.d.ts.map +1 -1
- package/script/methods/rowProportions.js +5 -1
- package/script/methods/rowToText.js +2 -2
- package/script/methods/selectTables.d.ts.map +1 -1
- package/script/methods/selectTables.js +6 -0
- package/script/methods/setTypes.d.ts +1 -1
- package/script/methods/setTypes.d.ts.map +1 -1
- package/script/methods/stream.d.ts.map +1 -1
- package/script/methods/stream.js +2 -1
- package/script/methods/updateWithJS.d.ts +1 -3
- package/script/methods/updateWithJS.d.ts.map +1 -1
- package/script/methods/updateWithJS.js +122 -36
|
@@ -15,6 +15,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
};
|
|
16
16
|
var _SimpleTable_name;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const logBottom_js_1 = __importDefault(require("../methods/logBottom.js"));
|
|
19
|
+
const log_js_1 = __importDefault(require("../methods/log.js"));
|
|
18
20
|
const quoteIdentifier_js_1 = __importDefault(require("../helpers/quoteIdentifier.js"));
|
|
19
21
|
const csvFormat_js_1 = __importDefault(require("../helpers/csvFormat.js"));
|
|
20
22
|
const getDescription_js_1 = __importDefault(require("../methods/getDescription.js"));
|
|
@@ -22,6 +24,8 @@ const removeMissing_js_1 = __importDefault(require("../methods/removeMissing.js"
|
|
|
22
24
|
const getColumns_js_1 = __importDefault(require("../methods/getColumns.js"));
|
|
23
25
|
const getRowCount_js_1 = __importDefault(require("../methods/getRowCount.js"));
|
|
24
26
|
const getCharacterCount_js_1 = __importDefault(require("../methods/getCharacterCount.js"));
|
|
27
|
+
const addCharacterCount_js_1 = __importDefault(require("../methods/addCharacterCount.js"));
|
|
28
|
+
const addWordCount_js_1 = __importDefault(require("../methods/addWordCount.js"));
|
|
25
29
|
const getTypes_js_1 = __importDefault(require("../methods/getTypes.js"));
|
|
26
30
|
const getHash_js_1 = __importDefault(require("../methods/getHash.js"));
|
|
27
31
|
const getValues_js_1 = __importDefault(require("../methods/getValues.js"));
|
|
@@ -123,6 +127,7 @@ const length_js_1 = __importDefault(require("../methods/length.js"));
|
|
|
123
127
|
const area_js_1 = __importDefault(require("../methods/area.js"));
|
|
124
128
|
const reproject_js_1 = __importDefault(require("../methods/reproject.js"));
|
|
125
129
|
const reducePrecision_js_1 = __importDefault(require("../methods/reducePrecision.js"));
|
|
130
|
+
const addGeoNoise_js_1 = __importDefault(require("../methods/addGeoNoise.js"));
|
|
126
131
|
const flipCoordinates_js_1 = __importDefault(require("../methods/flipCoordinates.js"));
|
|
127
132
|
const addGeoType_js_1 = __importDefault(require("../methods/addGeoType.js"));
|
|
128
133
|
const addGeoClosedStatus_js_1 = __importDefault(require("../methods/addGeoClosedStatus.js"));
|
|
@@ -137,6 +142,7 @@ const getSchema_js_1 = __importDefault(require("../methods/getSchema.js"));
|
|
|
137
142
|
const outliersIQR_js_1 = __importDefault(require("../methods/outliersIQR.js"));
|
|
138
143
|
const bins_js_1 = __importDefault(require("../methods/bins.js"));
|
|
139
144
|
const round_js_1 = __importDefault(require("../methods/round.js"));
|
|
145
|
+
const addNoise_js_1 = __importDefault(require("../methods/addNoise.js"));
|
|
140
146
|
const rowToText_js_1 = __importDefault(require("../methods/rowToText.js"));
|
|
141
147
|
const replaceNulls_js_1 = __importDefault(require("../methods/replaceNulls.js"));
|
|
142
148
|
const pad_js_1 = __importDefault(require("../methods/pad.js"));
|
|
@@ -158,6 +164,7 @@ const insertRows_js_1 = __importDefault(require("../methods/insertRows.js"));
|
|
|
158
164
|
const loadGeoData_js_1 = __importDefault(require("../methods/loadGeoData.js"));
|
|
159
165
|
const loadOpenStreetMap_js_1 = __importDefault(require("../methods/loadOpenStreetMap.js"));
|
|
160
166
|
const loadStatCanData_js_1 = __importDefault(require("../methods/loadStatCanData.js"));
|
|
167
|
+
const loadYahooFinanceData_js_1 = __importDefault(require("../methods/loadYahooFinanceData.js"));
|
|
161
168
|
const setTypes_js_1 = __importDefault(require("../methods/setTypes.js"));
|
|
162
169
|
const flushAllTables_js_1 = __importDefault(require("../helpers/flushAllTables.js"));
|
|
163
170
|
const queueOp_js_1 = __importDefault(require("../helpers/queueOp.js"));
|
|
@@ -223,7 +230,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
223
230
|
* @param simpleDB - The SimpleDB instance that this table belongs to.
|
|
224
231
|
* @param options - An optional object with configuration options:
|
|
225
232
|
* @param options.rowsToLog - The number of rows to log when displaying table data.
|
|
226
|
-
* @param options.charsToLog - The maximum
|
|
233
|
+
* @param options.charsToLog - The maximum characters to display for text and stringified nested cells, including truncation markers (default: 75). Independent of column width. Use Infinity for unlimited text.
|
|
227
234
|
* @param options.typesToLog - A boolean indicating whether to include data types when logging a table.
|
|
228
235
|
* @category Constructor
|
|
229
236
|
*/
|
|
@@ -299,6 +306,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
299
306
|
}
|
|
300
307
|
/**
|
|
301
308
|
* Renames the current table.
|
|
309
|
+
* The new name must not belong to another registered table, ignoring ASCII letter case.
|
|
302
310
|
*
|
|
303
311
|
* @param name - The new name for the table.
|
|
304
312
|
* @returns A promise that resolves to the renamed table.
|
|
@@ -320,9 +328,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
320
328
|
* Sets the data types for columns in a new table. If the table already exists, it will be replaced.
|
|
321
329
|
* To convert the types of an existing table, use the `.convert()` method instead.
|
|
322
330
|
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* @param types - An object specifying the column names and their target data types (JavaScript or SQL types).
|
|
331
|
+
* @param types - An object specifying the column names and their target data types (JavaScript or SQL types), including JSON, FLOAT[n] vectors, and GEOMETRY with a CRS.
|
|
326
332
|
* @returns The table, so methods can be chained.
|
|
327
333
|
* @category Table Management
|
|
328
334
|
*
|
|
@@ -335,26 +341,43 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
335
341
|
* raise: "float",
|
|
336
342
|
* }).log();
|
|
337
343
|
* ```
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```ts
|
|
347
|
+
* // Create an empty table with JSON, embedding, and geometry columns.
|
|
348
|
+
* await table.setTypes({
|
|
349
|
+
* details: "JSON",
|
|
350
|
+
* embedding: "FLOAT[3]",
|
|
351
|
+
* geom: "GEOMETRY('EPSG:4326')",
|
|
352
|
+
* }).log();
|
|
353
|
+
* ```
|
|
338
354
|
*/
|
|
339
355
|
setTypes(types) {
|
|
340
356
|
(0, setTypes_js_1.default)(this, types);
|
|
341
357
|
return this;
|
|
342
358
|
}
|
|
343
359
|
/**
|
|
344
|
-
* Loads an array of JavaScript objects into the table.
|
|
360
|
+
* Loads an array of JavaScript objects into the table. Types are inferred for
|
|
361
|
+
* numbers, bigints, strings, booleans, and Date values. Array and object cells
|
|
362
|
+
* require an explicit supported type in columnTypes. Types can also be
|
|
363
|
+
* specified for scalar columns instead of inferred from their values.
|
|
345
364
|
*
|
|
346
365
|
* JavaScript `Date` values are inferred as DuckDB `TIMESTAMP` values. Their
|
|
347
366
|
* instant is preserved, but JavaScript `Date` does not retain the timezone or
|
|
348
|
-
* offset originally used to construct it.
|
|
349
|
-
*
|
|
367
|
+
* offset originally used to construct it.
|
|
368
|
+
*
|
|
369
|
+
* Declare `JSON` for general nested data, `FLOAT[n]` for a fixed-size float
|
|
370
|
+
* vector, or `GEOMETRY('EPSG:4326')` for GeoJSON geometries in WGS84.
|
|
350
371
|
*
|
|
351
372
|
* @param rows - An array of objects, where each object represents a row and its properties represent columns.
|
|
373
|
+
* @param options - Options for loading the array, captured when called.
|
|
374
|
+
* @param options.columnTypes - Types for specific columns. Required for array and object cells; omitted scalar columns are inferred, and all-null columns default to VARCHAR. Values must be compatible with the selected type without losing information.
|
|
352
375
|
* @returns The table, so methods can be chained.
|
|
353
376
|
* @category Importing Data
|
|
354
377
|
*
|
|
355
378
|
* @example
|
|
356
379
|
* ```ts
|
|
357
|
-
* // Load
|
|
380
|
+
* // Load scalar columns without columnTypes; strings and numbers are inferred.
|
|
358
381
|
* const data = [
|
|
359
382
|
* { letter: "a", number: 1 },
|
|
360
383
|
* { letter: "b", number: 2 }
|
|
@@ -364,31 +387,68 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
364
387
|
*
|
|
365
388
|
* @example
|
|
366
389
|
* ```ts
|
|
367
|
-
* //
|
|
368
|
-
*
|
|
390
|
+
* // Choose a numeric type when all-null values provide nothing to infer.
|
|
391
|
+
* await table.loadArray(
|
|
392
|
+
* [{ name: "A", value: null }, { name: "B", value: null }],
|
|
393
|
+
* { columnTypes: { value: "DOUBLE" } },
|
|
394
|
+
* ).log();
|
|
395
|
+
* ```
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```ts
|
|
399
|
+
* // Store the Date as a UTC timestamp with JavaScript's millisecond precision.
|
|
400
|
+
* // The original -04:00 offset is not retained.
|
|
369
401
|
* await table.loadArray([{
|
|
370
402
|
* observedAt: new Date("2024-04-07T13:00:00-04:00"),
|
|
371
403
|
* }]).log();
|
|
372
404
|
* ```
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```ts
|
|
408
|
+
* // Declare JSON to load nested objects and variable-length arrays directly.
|
|
409
|
+
* await table.loadArray([{
|
|
410
|
+
* name: "Station",
|
|
411
|
+
* metadata: { active: true, tags: ["weather", "urban"] },
|
|
412
|
+
* measurements: [1, 2.5, null],
|
|
413
|
+
* }], { columnTypes: { metadata: "JSON", measurements: "JSON" } }).log();
|
|
414
|
+
* ```
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```ts
|
|
418
|
+
* // Declare FLOAT[3] to store each three-element array as a fixed-size vector.
|
|
419
|
+
* await table.loadArray([{ vector: [1, 2, 3] }], {
|
|
420
|
+
* columnTypes: { vector: "FLOAT[3]" },
|
|
421
|
+
* }).log();
|
|
422
|
+
* ```
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```ts
|
|
426
|
+
* // Declare a geometry type to store WGS84 GeoJSON as a spatial column.
|
|
427
|
+
* await table.loadArray([{
|
|
428
|
+
* name: "Montreal",
|
|
429
|
+
* geom: { type: "Point", coordinates: [-73.57, 45.50] },
|
|
430
|
+
* }], { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } }).log();
|
|
431
|
+
* ```
|
|
373
432
|
*/
|
|
374
|
-
loadArray(rows) {
|
|
375
|
-
(0, loadArray_js_1.default)(this, rows);
|
|
433
|
+
loadArray(rows, options = {}) {
|
|
434
|
+
(0, loadArray_js_1.default)(this, rows, options);
|
|
376
435
|
return this;
|
|
377
436
|
}
|
|
378
437
|
/**
|
|
379
438
|
* Loads data from one or more local or remote files into the table.
|
|
380
439
|
* Supported file formats include CSV, JSON, Parquet, and Excel.
|
|
381
|
-
*
|
|
440
|
+
*
|
|
441
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
382
442
|
*
|
|
383
443
|
* @param files - The path(s) or URL(s) of the file(s) containing the data to be loaded.
|
|
384
444
|
* @param options - An optional object with configuration options:
|
|
385
445
|
* @param options.fileType - The type of file to load ("csv", "dsv", "json", "parquet", "excel"). Defaults to being inferred from the file extension.
|
|
386
446
|
* @param options.autoDetect - A boolean indicating whether to automatically detect the data format. Defaults to `true`.
|
|
387
|
-
* @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before applying `limit`.
|
|
447
|
+
* @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before applying `limit`. Can reference source columns excluded from `columns`.
|
|
388
448
|
* @param options.limit - A number indicating the maximum number of matching rows to load, after applying `conditions` if provided. Defaults to all matching rows.
|
|
389
449
|
* @param options.includeFilename - A boolean indicating whether to include the filename as a new column in the loaded data. Defaults to `false`.
|
|
390
450
|
* @param options.unifyColumns - A boolean indicating whether to unify columns across multiple files when their structures differ. Missing columns will be filled with `NULL` values. Defaults to `false`.
|
|
391
|
-
* @param options.columnTypes - An object mapping column names to their expected data types. By default, types are inferred.
|
|
451
|
+
* @param options.columnTypes - An object mapping column names to their expected data types. By default, types are inferred. Geometry types are not supported; use loadGeoData() instead.
|
|
392
452
|
* @param options.columns - An array of column names to load. When provided, only the specified columns are loaded, reducing memory usage and improving load times. Not supported for Excel files — combining `columns` with Excel files throws an error. If an invalid column name is provided, DuckDB will throw its native error. An empty array behaves the same as omitting the option (loads all columns). Defaults to loading all columns.
|
|
393
453
|
* @param options.header - A boolean indicating whether the file has a header row. Applicable to CSV files. Defaults to `true`.
|
|
394
454
|
* @param options.allText - A boolean indicating whether all columns should be treated as text. Applicable to CSV files. Defaults to `false`.
|
|
@@ -465,8 +525,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
465
525
|
}
|
|
466
526
|
/**
|
|
467
527
|
* Downloads a complete Statistics Canada table and loads it into this table.
|
|
468
|
-
* The method queues the download and load; they run when an async observer
|
|
469
|
-
* method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
470
528
|
*
|
|
471
529
|
* Results are cached as Parquet files in `.sda-cache/statcan` by default.
|
|
472
530
|
* Cached data does not expire unless a TTL is provided.
|
|
@@ -504,15 +562,75 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
504
562
|
return this;
|
|
505
563
|
}
|
|
506
564
|
/**
|
|
507
|
-
*
|
|
565
|
+
* Downloads historical market data from Yahoo Finance and loads it into this
|
|
566
|
+
* table as `datetime`, `open`, `high`, `low`, `close`, `adjustedClose`, and
|
|
567
|
+
* `volume` columns. `datetime` contains Yahoo's timestamps as JavaScript
|
|
568
|
+
* `Date` values. Unavailable values are preserved as `null`.
|
|
569
|
+
*
|
|
570
|
+
* All range boundaries are evaluated in UTC. Use ISO date-time strings ending
|
|
571
|
+
* in `Z`. Yahoo trading sessions may occur on a different UTC date from their
|
|
572
|
+
* exchange-local date, so choose the range appropriate for the market and
|
|
573
|
+
* interval. Avoid numeric constructors such as `new Date(2025, 2, 15)`, which
|
|
574
|
+
* use the runtime's local timezone.
|
|
575
|
+
*
|
|
576
|
+
* This method uses an undocumented Yahoo Finance endpoint and is not
|
|
577
|
+
* affiliated with or endorsed by Yahoo. It is provided for educational,
|
|
578
|
+
* research, and journalistic purposes. Before using it, review Yahoo's terms
|
|
579
|
+
* and any applicable data-provider restrictions.
|
|
580
|
+
*
|
|
581
|
+
* @param symbol - The stock or index symbol, such as `"AAPL"` or `"^GSPTSE"`.
|
|
582
|
+
* @param startDate - The inclusive UTC start of the requested range.
|
|
583
|
+
* @param endDate - The inclusive UTC end of the requested range. The UTC day,
|
|
584
|
+
* hour, or minute containing this instant is included, according to
|
|
585
|
+
* `interval`.
|
|
586
|
+
* @param interval - The interval between observations: daily, hourly, or every
|
|
587
|
+
* minute.
|
|
588
|
+
* @returns The table, so methods can be chained.
|
|
589
|
+
* @throws {RangeError} If either date is invalid or `endDate` is before `startDate`.
|
|
590
|
+
* @throws {Error} If Yahoo rejects the request or returns no data.
|
|
591
|
+
* @see https://legal.yahoo.com/us/en/yahoo/terms/otos/index.html
|
|
592
|
+
* @see https://help.yahoo.com/kb/finance/SLN2310.html
|
|
593
|
+
* @category Importing Data
|
|
508
594
|
*
|
|
509
|
-
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```ts
|
|
597
|
+
* // Request daily observations using explicit UTC boundaries.
|
|
598
|
+
* await table
|
|
599
|
+
* .loadYahooFinanceData(
|
|
600
|
+
* "^GSPTSE",
|
|
601
|
+
* new Date("2025-03-01T00:00:00Z"),
|
|
602
|
+
* new Date("2025-03-15T00:00:00Z"),
|
|
603
|
+
* "1d",
|
|
604
|
+
* )
|
|
605
|
+
* .log();
|
|
606
|
+
* ```
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```ts
|
|
610
|
+
* // Include the UTC hours from 13:00 through 16:00.
|
|
611
|
+
* await table
|
|
612
|
+
* .loadYahooFinanceData(
|
|
613
|
+
* "AAPL",
|
|
614
|
+
* new Date("2025-03-14T13:00:00Z"),
|
|
615
|
+
* new Date("2025-03-14T16:00:00Z"),
|
|
616
|
+
* "1h",
|
|
617
|
+
* )
|
|
618
|
+
* .log();
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
loadYahooFinanceData(symbol, startDate, endDate, interval) {
|
|
622
|
+
(0, loadYahooFinanceData_js_1.default)(this, symbol, startDate, endDate, interval);
|
|
623
|
+
return this;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Loads geospatial data from an external file or URL into the table.
|
|
627
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
510
628
|
*
|
|
511
629
|
* @param file - The path or URL of the external file containing the geospatial data.
|
|
512
630
|
* @param options - An optional object with configuration options:
|
|
513
631
|
* @param options.toEPSG4326 - If `true`, the method will attempt to reproject the data to EPSG:4326 (WGS84).
|
|
514
632
|
* @param options.columns - The columns to load. Include the geometry column that should remain in the resulting table, usually `"geom"`. By default, all columns are loaded.
|
|
515
|
-
* @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before materialization and reprojection.
|
|
633
|
+
* @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before materialization and reprojection. Can reference source columns excluded from `columns`. Geometry conditions use the source coordinate system.
|
|
516
634
|
* @returns The table, so methods can be chained.
|
|
517
635
|
* @category Geospatial
|
|
518
636
|
*
|
|
@@ -566,7 +684,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
566
684
|
return this;
|
|
567
685
|
}
|
|
568
686
|
/**
|
|
569
|
-
* Loads OpenStreetMap data into the table from a local `.osm` or `.osm.pbf` file, a remote file URL, or an Overpass bounding-box query. Pass a path or URL string to load an existing file, or pass a bounding box with `filters` to download matching features.
|
|
687
|
+
* Loads OpenStreetMap data into the table from a local `.osm` or `.osm.pbf` file, a remote file URL, or an Overpass bounding-box query. Pass a path or URL string to load an existing file, or pass a bounding box with `filters` to download matching features.
|
|
570
688
|
*
|
|
571
689
|
* DuckDB's [Osmium community extension](https://duckdb.org/community_extensions/extensions/osmium) materializes the complete result and reconstructs `geom` as EPSG:4326. By default, that canonical result is cached as GeoParquet in `.sda-cache/osm`. Distinct paths, local file fingerprints, normalized URLs, endpoints, queries, and bounding boxes retain independent entries. The cache has no expiration unless `ttl` is set and can be cleared by removing `.sda-cache/osm`. Immutable URLs can safely use the default indefinite cache; mutable URLs should set a TTL.
|
|
572
690
|
*
|
|
@@ -653,8 +771,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
653
771
|
* DuckDB FTS indexes do not update automatically when the table changes; use
|
|
654
772
|
* `overwrite: true` to rebuild the index after modifying the table.
|
|
655
773
|
*
|
|
656
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
657
|
-
*
|
|
658
774
|
* @param idColumn - The column containing the document identifiers.
|
|
659
775
|
* @param textColumn - The column containing the text to search.
|
|
660
776
|
* @param options - An optional object with configuration options:
|
|
@@ -713,8 +829,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
713
829
|
* If a VSS index already exists on the table, this method will skip creation and log a message (when verbose is enabled), unless the `overwrite` option is set to `true`.
|
|
714
830
|
* The index definition is recorded in {@link indexes}.
|
|
715
831
|
*
|
|
716
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
717
|
-
*
|
|
718
832
|
* @param column - The name of the column containing vector embeddings (must be FLOAT array type).
|
|
719
833
|
* @param options - An optional object with configuration options:
|
|
720
834
|
* @param options.overwrite - If `true`, drops and recreates the index even if it already exists. Defaults to `false`.
|
|
@@ -775,8 +889,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
775
889
|
* changes; use `overwriteIndex: true` to rebuild the index after modifying
|
|
776
890
|
* the table.
|
|
777
891
|
*
|
|
778
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
779
|
-
*
|
|
780
892
|
* @param text - The search query text to match against the text column.
|
|
781
893
|
* @param idColumn - The name of the column containing unique identifiers for each row.
|
|
782
894
|
* @param textColumn - The name of the column containing the text to search.
|
|
@@ -878,8 +990,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
878
990
|
/**
|
|
879
991
|
* Inserts rows, provided as an array of JavaScript objects, into the table.
|
|
880
992
|
*
|
|
881
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
882
|
-
*
|
|
883
993
|
* @param rows - An array of objects, where each object represents a row to be inserted and its properties correspond to column names.
|
|
884
994
|
* @returns The table, so methods can be chained.
|
|
885
995
|
* @category Importing Data
|
|
@@ -899,7 +1009,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
899
1009
|
return this;
|
|
900
1010
|
}
|
|
901
1011
|
/**
|
|
902
|
-
* Inserts all rows from one or more other tables into this table. If tables do not have the same columns, an error will be thrown unless the `unifyColumns` option is set to `true`.
|
|
1012
|
+
* Inserts all rows from one or more other tables into this table. If tables do not have the same columns, an error will be thrown unless the `unifyColumns` option is set to `true`.
|
|
903
1013
|
*
|
|
904
1014
|
* @param tables - The name(s) of the table(s) or SimpleTable instance(s) from which rows will be inserted.
|
|
905
1015
|
* @param options - An optional object with configuration options:
|
|
@@ -932,8 +1042,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
932
1042
|
/**
|
|
933
1043
|
* Fetches sample data from the simple-data-analysis-core GitHub repository.
|
|
934
1044
|
*
|
|
935
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
936
|
-
*
|
|
937
1045
|
* @param sample - The name of the sample to load.
|
|
938
1046
|
*
|
|
939
1047
|
* Tabular data:
|
|
@@ -959,13 +1067,12 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
959
1067
|
}
|
|
960
1068
|
/**
|
|
961
1069
|
* Returns a new table with the same structure and data as this table. The data can be optionally filtered, limited to a specific number of rows, and offset.
|
|
1070
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
962
1071
|
*
|
|
963
1072
|
* If `conditions`, `limit`, and `offset` are all used, they are applied in this order: `conditions` (WHERE clause) first, then `offset`, and finally `limit` (LIMIT).
|
|
964
1073
|
*
|
|
965
1074
|
* Note that cloning large tables can be a slow operation.
|
|
966
1075
|
*
|
|
967
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
968
|
-
*
|
|
969
1076
|
* @param nameOrOptions - Either a string specifying the name of the new table, or an optional object with configuration options. If not provided, a default name (e.g., "table1", "table2") will be generated.
|
|
970
1077
|
* @param nameOrOptions.name - The name of the new table to be created in the database. If not provided, a default name (e.g., "table1", "table2") will be generated.
|
|
971
1078
|
* @param nameOrOptions.conditions - A SQL `WHERE` clause condition to filter the data during cloning. Defaults to no condition (clones all rows).
|
|
@@ -1034,8 +1141,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1034
1141
|
/**
|
|
1035
1142
|
* Clones an existing column in this table, creating a new column with identical values.
|
|
1036
1143
|
*
|
|
1037
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1038
|
-
*
|
|
1039
1144
|
* @param column - The name of the original column to clone.
|
|
1040
1145
|
* @param newColumn - The name of the new column to be created.
|
|
1041
1146
|
* @returns The table, so methods can be chained.
|
|
@@ -1057,8 +1162,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1057
1162
|
*
|
|
1058
1163
|
* **Important:** The offset is applied based on the current row order in the table. For meaningful results, ensure your data is sorted appropriately (e.g., by date/time for time-series analysis) before calling this method.
|
|
1059
1164
|
*
|
|
1060
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1061
|
-
*
|
|
1062
1165
|
* @param column - The name of the original column.
|
|
1063
1166
|
* @param newColumn - The name of the new column to be created with offset values.
|
|
1064
1167
|
* @param options - An optional object with configuration options:
|
|
@@ -1104,8 +1207,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1104
1207
|
/**
|
|
1105
1208
|
* Fills `NULL` values in specified columns. By default, each `NULL` is replaced with the last non-`NULL` value from the preceding row. When `interpolate` is `true`, `NULL` values are replaced using linear interpolation (or extrapolation at the ends). Pass `interpolateBy` with a real numeric or date column name to use it as the X-axis, so that interpolated values are proportional to the actual distances between X-axis values rather than treating every row as equidistant. When `interpolateBy` is set, `interpolate` is automatically assumed `true`.
|
|
1106
1209
|
*
|
|
1107
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1108
|
-
*
|
|
1109
1210
|
* @param columns - The column(s) for which to fill `NULL` values.
|
|
1110
1211
|
* @param options - An optional object with configuration options:
|
|
1111
1212
|
* @param options.by - A column name or an array of column names to partition by. The fill is applied independently within each group.
|
|
@@ -1164,7 +1265,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1164
1265
|
* Sorts the rows of the table based on specified column(s) and order(s).
|
|
1165
1266
|
* If no columns are specified, all columns are sorted from left to right in ascending order.
|
|
1166
1267
|
*
|
|
1167
|
-
*
|
|
1268
|
+
* Order-preserving transformations after a sort retain that order. Operations such as joins, grouping, aggregation, and sampling do not guarantee input order; chain `sort()` after them when deterministic output order matters.
|
|
1168
1269
|
*
|
|
1169
1270
|
* @param order - An object mapping column names to their sorting order: `"asc"` for ascending or `"desc"` for descending. If `null`, all columns are sorted ascendingly.
|
|
1170
1271
|
* @param options - An optional object with configuration options:
|
|
@@ -1201,7 +1302,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1201
1302
|
return this;
|
|
1202
1303
|
}
|
|
1203
1304
|
/**
|
|
1204
|
-
* Selects specific columns in the table, removing all others.
|
|
1305
|
+
* Selects specific columns in the table, removing all others.
|
|
1205
1306
|
*
|
|
1206
1307
|
* @param columns - The name or an array of names of the columns to be selected.
|
|
1207
1308
|
* @returns The table, so methods can be chained.
|
|
@@ -1226,8 +1327,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1226
1327
|
/**
|
|
1227
1328
|
* Skips the first `n` rows of the table, effectively removing them.
|
|
1228
1329
|
*
|
|
1229
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1230
|
-
*
|
|
1231
1330
|
* @param count - The number of rows to skip from the beginning of the table.
|
|
1232
1331
|
* @returns The table, so methods can be chained.
|
|
1233
1332
|
* @category Selecting or Filtering Data
|
|
@@ -1263,8 +1362,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1263
1362
|
/**
|
|
1264
1363
|
* Selects random rows from the table, removing all others. You can optionally specify a seed to ensure repeatable sampling.
|
|
1265
1364
|
*
|
|
1266
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1267
|
-
*
|
|
1268
1365
|
* @param count - The number of rows to select (e.g., `100`) or a percentage string (e.g., `"10%"`) specifying the sampling size.
|
|
1269
1366
|
* @param options - An optional object with configuration options:
|
|
1270
1367
|
* @param options.seed - A number specifying the seed for repeatable sampling. Using the same seed will always yield the same random rows. Defaults to a random seed.
|
|
@@ -1296,8 +1393,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1296
1393
|
/**
|
|
1297
1394
|
* Selects a specified number of rows from this table. An offset can be applied to skip initial rows, and the results can be output to a new table.
|
|
1298
1395
|
*
|
|
1299
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1300
|
-
*
|
|
1301
1396
|
* @param count - The number of rows to select.
|
|
1302
1397
|
* @param options - An optional object with configuration options:
|
|
1303
1398
|
* @param options.offset - The number of rows to skip from the beginning of the table before selecting. Defaults to `0`.
|
|
@@ -1336,8 +1431,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1336
1431
|
* Removes duplicate rows from this table, keeping only unique rows.
|
|
1337
1432
|
* Note that the resulting data order might differ from the original.
|
|
1338
1433
|
*
|
|
1339
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1340
|
-
*
|
|
1341
1434
|
* @param options - An optional object with configuration options:
|
|
1342
1435
|
* @param options.on - A column name or an array of column names to consider when identifying duplicates. If specified, duplicates are determined based only on the values in these columns. If omitted, all columns are considered.
|
|
1343
1436
|
* @returns The table, so methods can be chained.
|
|
@@ -1368,7 +1461,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1368
1461
|
/**
|
|
1369
1462
|
* Removes rows with missing values from this table.
|
|
1370
1463
|
* By default, missing values include SQL `NULL`, as well as string representations like `"NULL"`, `"null"`, `"NaN"`, `"undefined"`, and empty strings `""`.
|
|
1371
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1372
1464
|
*
|
|
1373
1465
|
* @param options - An optional object with configuration options:
|
|
1374
1466
|
* @param options.columns - A string or an array of strings specifying the columns to consider for missing values. If omitted, all columns are considered.
|
|
@@ -1406,7 +1498,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1406
1498
|
return this;
|
|
1407
1499
|
}
|
|
1408
1500
|
/**
|
|
1409
|
-
* Trims specified characters from the beginning, end, or both sides of string values in the given columns.
|
|
1501
|
+
* Trims specified characters from the beginning, end, or both sides of string values in the given columns.
|
|
1410
1502
|
*
|
|
1411
1503
|
* @param columns - The column name or an array of column names to trim.
|
|
1412
1504
|
* @param options - An optional object with configuration options:
|
|
@@ -1439,8 +1531,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1439
1531
|
}
|
|
1440
1532
|
/**
|
|
1441
1533
|
* Filters rows from this table based on SQL conditions. Note that it's often faster to use the `removeRows` method for simple removals.
|
|
1442
|
-
*
|
|
1443
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1534
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
1444
1535
|
*
|
|
1445
1536
|
* @param conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"column1 > 10 AND column2 = 'value'"`).
|
|
1446
1537
|
* @returns The table, so methods can be chained.
|
|
@@ -1477,8 +1568,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1477
1568
|
/**
|
|
1478
1569
|
* Keeps rows in this table that have specific values in specified columns, removing all other rows.
|
|
1479
1570
|
*
|
|
1480
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1481
|
-
*
|
|
1482
1571
|
* @param columnsAndValues - An object where keys are column names and values are the specific values (or an array of values) to keep in those columns. Use `null` to keep rows where a column is `NULL`.
|
|
1483
1572
|
* @returns The table, so methods can be chained.
|
|
1484
1573
|
* @category Selecting or Filtering Data
|
|
@@ -1508,8 +1597,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1508
1597
|
/**
|
|
1509
1598
|
* Removes rows from this table that have specific values in specified columns.
|
|
1510
1599
|
*
|
|
1511
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1512
|
-
*
|
|
1513
1600
|
* @param columnsAndValues - An object where keys are column names and values are the specific values (or an array of values) to remove from those columns. Use `null` to remove rows where a column is `NULL`; otherwise, `NULL` rows are retained.
|
|
1514
1601
|
* @returns The table, so methods can be chained.
|
|
1515
1602
|
* @category Selecting or Filtering Data
|
|
@@ -1538,9 +1625,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1538
1625
|
}
|
|
1539
1626
|
/**
|
|
1540
1627
|
* Removes rows from this table based on SQL conditions. This method is similar to `filter()`, but removes rows instead of keeping them.
|
|
1541
|
-
*
|
|
1542
|
-
*
|
|
1543
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1628
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
1544
1629
|
*
|
|
1545
1630
|
* @param conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"fruit = 'apple'"`).
|
|
1546
1631
|
* @returns The table, so methods can be chained.
|
|
@@ -1578,8 +1663,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1578
1663
|
* Renames one or more columns in the table. Throws if a source column does
|
|
1579
1664
|
* not exist, so a typo fails loudly instead of being silently ignored.
|
|
1580
1665
|
*
|
|
1581
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1582
|
-
*
|
|
1583
1666
|
* @param names - An object mapping old column names to their new column names (e.g., `{ "oldName": "newName", "anotherOld": "anotherNew" }`).
|
|
1584
1667
|
* @param options - Configuration options.
|
|
1585
1668
|
* @param options.strict - Whether to verify the source columns exist before renaming. Defaults to `true`. Set to `false` to skip the check and its schema lookup when you know the columns exist and are renaming across many tables where the extra round-trip adds up.
|
|
@@ -1611,8 +1694,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1611
1694
|
/**
|
|
1612
1695
|
* Cleans column names by removing non-alphanumeric characters and formatting them to camel case.
|
|
1613
1696
|
*
|
|
1614
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1615
|
-
*
|
|
1616
1697
|
* @returns The table, so methods can be chained.
|
|
1617
1698
|
* @category Column Operations
|
|
1618
1699
|
*
|
|
@@ -1665,8 +1746,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1665
1746
|
* | Sales | 2022 | 75 |
|
|
1666
1747
|
* | Sales | 2023 | 98 |
|
|
1667
1748
|
*
|
|
1668
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1669
|
-
*
|
|
1670
1749
|
* @param columns - An array of strings representing the names of the columns to be stacked (unpivoted).
|
|
1671
1750
|
* @param namesTo - The name of the new column that will contain the original column names (e.g., "Year").
|
|
1672
1751
|
* @param valuesTo - The name of the new column that will contain the values from the stacked columns (e.g., "Employees").
|
|
@@ -1708,8 +1787,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1708
1787
|
*
|
|
1709
1788
|
* When multiple rows share the same `namesFrom`/grouping combination, their `valuesFrom` values are combined with the `options.stat` function (`"sum"` by default).
|
|
1710
1789
|
*
|
|
1711
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1712
|
-
*
|
|
1713
1790
|
* @param namesFrom - The name of the column containing the values that will be transformed into new column headers (e.g., "Year").
|
|
1714
1791
|
* @param valuesFrom - The name of the column containing the values to be spread across the new columns (e.g., "Employees").
|
|
1715
1792
|
* @param options - An optional object with configuration options:
|
|
@@ -1734,9 +1811,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1734
1811
|
*
|
|
1735
1812
|
* When converting strings to numbers, commas (often used as thousand separators) will be automatically removed before conversion.
|
|
1736
1813
|
*
|
|
1737
|
-
*
|
|
1738
|
-
*
|
|
1739
|
-
* @param types - An object mapping column names to their target data types for conversion.
|
|
1814
|
+
* @param types - An object mapping column names to their target data types for conversion, including JSON, FLOAT[n] vectors, and GEOMETRY with a CRS.
|
|
1740
1815
|
* @param options - An optional object with configuration options:
|
|
1741
1816
|
* @param options.strict - If `false`, values that cannot be converted will be replaced by `NULL` instead of throwing an error. Defaults to `true`.
|
|
1742
1817
|
* @param options.datetimeFormat - A string specifying the format for date and time conversions. Uses `strftime` and `strptime` functions from DuckDB. For format specifiers, see [DuckDB's documentation](https://duckdb.org/docs/sql/functions/dateformat).
|
|
@@ -1783,6 +1858,18 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1783
1858
|
* // Convert 'amount' to float, replacing unconvertible values with NULL
|
|
1784
1859
|
* await table.convert({ amount: "float" }, { strict: false }).log();
|
|
1785
1860
|
* ```
|
|
1861
|
+
*
|
|
1862
|
+
* @example
|
|
1863
|
+
* ```ts
|
|
1864
|
+
* // Parse JSON, a fixed-size float vector, and WKT geometry from text.
|
|
1865
|
+
* await table.loadArray([{
|
|
1866
|
+
* details: '{"count":3}',
|
|
1867
|
+
* embedding: "[0.25,0.5,0.75]",
|
|
1868
|
+
* geom: "POINT (-73 45)",
|
|
1869
|
+
* }])
|
|
1870
|
+
* .convert({ details: "JSON", embedding: "FLOAT[3]", geom: "GEOMETRY('EPSG:4326')" })
|
|
1871
|
+
* .log();
|
|
1872
|
+
* ```
|
|
1786
1873
|
*/
|
|
1787
1874
|
convert(types, options = {}) {
|
|
1788
1875
|
(0, convert_js_1.default)(this, types, options);
|
|
@@ -1805,7 +1892,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1805
1892
|
return this;
|
|
1806
1893
|
}
|
|
1807
1894
|
/**
|
|
1808
|
-
* Removes one or more columns from this table.
|
|
1895
|
+
* Removes one or more columns from this table.
|
|
1809
1896
|
*
|
|
1810
1897
|
* @param columns - The name or an array of names of the columns to be removed.
|
|
1811
1898
|
* @returns The table, so methods can be chained.
|
|
@@ -1828,10 +1915,11 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1828
1915
|
return this;
|
|
1829
1916
|
}
|
|
1830
1917
|
/**
|
|
1831
|
-
* Adds a new column to the table based on a specified data type (JavaScript or SQL types) and a SQL definition.
|
|
1918
|
+
* Adds a new column to the table based on a specified data type (JavaScript or SQL types) and a SQL definition.
|
|
1919
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, expressions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
1832
1920
|
*
|
|
1833
1921
|
* @param newColumn - The name of the new column to be added.
|
|
1834
|
-
* @param type - The data type for the new column. Can be a JavaScript type (e.g., `"number"`, `"string"`) or a SQL type (e.g., `"integer"`, `"varchar"`).
|
|
1922
|
+
* @param type - The data type for the new column. Can be a JavaScript type (e.g., `"number"`, `"string"`) or a SQL type (e.g., `"integer"`, `"varchar"`, `"JSON"`, `"FLOAT[3]"`, `"GEOMETRY('EPSG:4326')"`).
|
|
1835
1923
|
* @param definition - A SQL expression defining how the values for the new column should be computed (e.g., `"column1 + column2"`, `"ST_Centroid(geom_column)"`).
|
|
1836
1924
|
* @returns The table, so methods can be chained.
|
|
1837
1925
|
* @category Column Operations
|
|
@@ -1847,6 +1935,25 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1847
1935
|
* // Add a new geometry column 'centroid' using the centroid of an existing 'country' geometry column
|
|
1848
1936
|
* await table.addColumn("centroid", "geometry('EPSG:4326')", `ST_Centroid("country")`).log();
|
|
1849
1937
|
* ```
|
|
1938
|
+
*
|
|
1939
|
+
* @example
|
|
1940
|
+
* ```ts
|
|
1941
|
+
* // Read a number from a JSON object into a new column using dot notation.
|
|
1942
|
+
* await table.loadArray([{ details: { count: 3 } }], {
|
|
1943
|
+
* columnTypes: { details: "JSON" },
|
|
1944
|
+
* })
|
|
1945
|
+
* .addColumn("count", "integer", "details.count")
|
|
1946
|
+
* .log();
|
|
1947
|
+
* ```
|
|
1948
|
+
*
|
|
1949
|
+
* @example
|
|
1950
|
+
* ```ts
|
|
1951
|
+
* // Create JSON and fixed-size vector columns with DuckDB expressions.
|
|
1952
|
+
* await table.loadArray([{ count: 3 }])
|
|
1953
|
+
* .addColumn("details", "JSON", "json_object('count', count)")
|
|
1954
|
+
* .addColumn("embedding", "FLOAT[3]", "[0.25, 0.5, 0.75]")
|
|
1955
|
+
* .log();
|
|
1956
|
+
* ```
|
|
1850
1957
|
*/
|
|
1851
1958
|
addColumn(newColumn, type, definition) {
|
|
1852
1959
|
(0, addColumn_js_1.default)(this, newColumn, type, definition);
|
|
@@ -1866,9 +1973,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1866
1973
|
* values produce `NULL` extracted values. Parts extracted from
|
|
1867
1974
|
* `TIMESTAMP WITH TIME ZONE` values use UTC.
|
|
1868
1975
|
*
|
|
1869
|
-
* This method queues the operation; it runs when an async observer method
|
|
1870
|
-
* (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1871
|
-
*
|
|
1872
1976
|
* @param column - The temporal column from which to extract components.
|
|
1873
1977
|
* @param parts - A part to extract using its name as the new column, or an object mapping each custom new-column name to the part it should contain.
|
|
1874
1978
|
* @returns The table, so methods can be chained.
|
|
@@ -1896,8 +2000,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1896
2000
|
/**
|
|
1897
2001
|
* Adds a new column to the table containing the row number, starting at 0 (like an index).
|
|
1898
2002
|
*
|
|
1899
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1900
|
-
*
|
|
1901
2003
|
* @param newColumn - The name of the new column that will store the row number.
|
|
1902
2004
|
* @param options - An optional object with configuration options:
|
|
1903
2005
|
* @param options.by - A column name or an array of column names to partition by. The row number restarts at 0 within each group.
|
|
@@ -1924,8 +2026,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1924
2026
|
* Performs a cross join operation with another table. A cross join returns the Cartesian product of the rows from both tables, meaning all possible pairs of rows will be in the resulting table.
|
|
1925
2027
|
* This means that if the left table has `n` rows and the right table has `m` rows, the result will have `n * m` rows.
|
|
1926
2028
|
*
|
|
1927
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1928
|
-
*
|
|
1929
2029
|
* @param rightTable - The SimpleTable instance to cross join with.
|
|
1930
2030
|
* @param options - An optional object with configuration options:
|
|
1931
2031
|
* @param options.outputTable - If `true`, the results will be stored in a new table with a generated name. If a string, it will be used as the name for the new table. If `false` or omitted, the current table will be overwritten. Defaults to `false`.
|
|
@@ -1957,7 +2057,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
1957
2057
|
* Merges the data of this table (considered the left table) with another table (the right table) based on a common column or multiple columns.
|
|
1958
2058
|
* Note that the order of rows in the returned data is not guaranteed to be the same as in the original tables.
|
|
1959
2059
|
* This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
|
|
1960
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called. The join uses the other table's state as of this call: operations queued on it afterwards run after the join.
|
|
1961
2060
|
*
|
|
1962
2061
|
* @param rightTable - The SimpleTable instance to be joined with this table.
|
|
1963
2062
|
* @param options - An optional object with configuration options:
|
|
@@ -2005,8 +2104,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2005
2104
|
*
|
|
2006
2105
|
* This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
|
|
2007
2106
|
*
|
|
2008
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called. The join uses the other table's state as of this call: operations queued on it afterwards run after the join.
|
|
2009
|
-
*
|
|
2010
2107
|
* @param rightTable - The SimpleTable instance to be joined with this table.
|
|
2011
2108
|
* @param leftColumn - The name of the column in this (left) table containing the text to compare.
|
|
2012
2109
|
* @param rightColumn - The name of the column in the right table containing the text to compare.
|
|
@@ -2073,8 +2170,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2073
2170
|
* Similarity is computed using the [rapidfuzz](https://query.farm/duckdb_extension_rapidfuzz) DuckDB community extension,
|
|
2074
2171
|
* which is installed and loaded automatically.
|
|
2075
2172
|
*
|
|
2076
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2077
|
-
*
|
|
2078
2173
|
* @param column - The name of the column containing the strings to normalize.
|
|
2079
2174
|
* @param newColumn - The name of the column to write the normalized values to. Use the same name as `column` to normalize in-place.
|
|
2080
2175
|
* @param threshold - The minimum similarity score (0–100) for two strings to be considered duplicates. For `method: "ratio"`, a length-based pre-filter is automatically applied based on the threshold to improve performance without losing accuracy.
|
|
@@ -2128,8 +2223,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2128
2223
|
/**
|
|
2129
2224
|
* Replaces specified strings in the selected columns.
|
|
2130
2225
|
*
|
|
2131
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2132
|
-
*
|
|
2133
2226
|
* @param columns - The column name, an array of column names, or `"all"` to apply the replacement to every column in the table.
|
|
2134
2227
|
* @param replacements - An object mapping old strings to new strings (e.g., `{ "oldValue": "newValue" }`).
|
|
2135
2228
|
* @param options - An optional object with configuration options:
|
|
@@ -2173,7 +2266,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2173
2266
|
return this;
|
|
2174
2267
|
}
|
|
2175
2268
|
/**
|
|
2176
|
-
* Converts string values in the specified columns to lowercase.
|
|
2269
|
+
* Converts string values in the specified columns to lowercase.
|
|
2177
2270
|
*
|
|
2178
2271
|
* @param columns - The column name or an array of column names to be converted to lowercase.
|
|
2179
2272
|
* @returns The table, so methods can be chained.
|
|
@@ -2196,7 +2289,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2196
2289
|
return this;
|
|
2197
2290
|
}
|
|
2198
2291
|
/**
|
|
2199
|
-
* Converts string values in the specified columns to uppercase.
|
|
2292
|
+
* Converts string values in the specified columns to uppercase.
|
|
2200
2293
|
*
|
|
2201
2294
|
* @param columns - The column name or an array of column names to be converted to uppercase.
|
|
2202
2295
|
* @returns The table, so methods can be chained.
|
|
@@ -2219,7 +2312,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2219
2312
|
return this;
|
|
2220
2313
|
}
|
|
2221
2314
|
/**
|
|
2222
|
-
* Capitalizes the first letter of each string in the specified columns and converts the rest of the string to lowercase.
|
|
2315
|
+
* Capitalizes the first letter of each string in the specified columns and converts the rest of the string to lowercase.
|
|
2223
2316
|
*
|
|
2224
2317
|
* @param columns - The column name or an array of column names to be capitalized.
|
|
2225
2318
|
* @returns The table, so methods can be chained.
|
|
@@ -2244,8 +2337,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2244
2337
|
/**
|
|
2245
2338
|
* Truncates string values in a specified column to a maximum number of characters.
|
|
2246
2339
|
*
|
|
2247
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2248
|
-
*
|
|
2249
2340
|
* @param column - The column name containing strings to be truncated.
|
|
2250
2341
|
* @param length - The maximum number of characters to keep.
|
|
2251
2342
|
* @returns The table, so methods can be chained.
|
|
@@ -2274,8 +2365,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2274
2365
|
* column is of a different type. `null` values remain `null`. If any string
|
|
2275
2366
|
* already exceeds the target length, an error is thrown (no silent truncation).
|
|
2276
2367
|
*
|
|
2277
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2278
|
-
*
|
|
2279
2368
|
* @param columns - The column name(s) containing strings to be padded.
|
|
2280
2369
|
* @param length - The target length of the padded strings.
|
|
2281
2370
|
* @param options - An optional object with configuration options:
|
|
@@ -2315,8 +2404,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2315
2404
|
* Splits strings in a specified column by a separator and extracts a substring at a given index, storing the result in a new or existing column.
|
|
2316
2405
|
* If the index is out of bounds, an empty string will be returned for that row.
|
|
2317
2406
|
*
|
|
2318
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2319
|
-
*
|
|
2320
2407
|
* @param column - The name of the column containing the strings to be split.
|
|
2321
2408
|
* @param separator - The substring to use as a delimiter for splitting the strings.
|
|
2322
2409
|
* @param index - The zero-based index of the substring to extract after splitting. For example, `0` for the first part, `1` for the second, etc.
|
|
@@ -2349,8 +2436,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2349
2436
|
* If a row has fewer parts than the number of new columns, a warning will be logged and the extra columns will contain empty strings (unless `strict` is set to `false`).
|
|
2350
2437
|
* If a row has more parts than the number of new columns, an error will be thrown unless `strict` is set to `false`.
|
|
2351
2438
|
*
|
|
2352
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2353
|
-
*
|
|
2354
2439
|
* @param column - The name of the column containing the strings to be split.
|
|
2355
2440
|
* @param separator - The substring to use as a delimiter for splitting the strings.
|
|
2356
2441
|
* @param newColumns - An array of column names for the extracted parts.
|
|
@@ -2386,8 +2471,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2386
2471
|
/**
|
|
2387
2472
|
* Extracts a specific number of characters from the beginning (left side) of string values in the specified column.
|
|
2388
2473
|
*
|
|
2389
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2390
|
-
*
|
|
2391
2474
|
* @param column - The name of the column containing the strings to be modified.
|
|
2392
2475
|
* @param count - The number of characters to extract from the left side of each string.
|
|
2393
2476
|
* @returns The table, so methods can be chained.
|
|
@@ -2407,8 +2490,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2407
2490
|
/**
|
|
2408
2491
|
* Extracts a specific number of characters from the end (right side) of string values in the specified column.
|
|
2409
2492
|
*
|
|
2410
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2411
|
-
*
|
|
2412
2493
|
* @param column - The name of the column containing the strings to be modified.
|
|
2413
2494
|
* @param count - The number of characters to extract from the right side of each string.
|
|
2414
2495
|
* @returns The table, so methods can be chained.
|
|
@@ -2428,8 +2509,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2428
2509
|
/**
|
|
2429
2510
|
* Replaces `NULL` values in the specified columns with a given value.
|
|
2430
2511
|
*
|
|
2431
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2432
|
-
*
|
|
2433
2512
|
* @param columns - The column name, an array of column names, or `"all"` to apply the replacement to every column in the table.
|
|
2434
2513
|
* @param value - The value to replace `NULL` occurrences with.
|
|
2435
2514
|
* @returns The table, so methods can be chained.
|
|
@@ -2466,8 +2545,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2466
2545
|
/**
|
|
2467
2546
|
* Concatenates values from specified columns into a new column.
|
|
2468
2547
|
*
|
|
2469
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2470
|
-
*
|
|
2471
2548
|
* @param columns - An array of column names whose values will be concatenated.
|
|
2472
2549
|
* @param newColumn - The name of the new column to store the concatenated values.
|
|
2473
2550
|
* @param options - An optional object with configuration options:
|
|
@@ -2502,8 +2579,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2502
2579
|
*
|
|
2503
2580
|
* If a column value is `NULL`, it will be replaced by `'Unknown'` in the concatenated result.
|
|
2504
2581
|
*
|
|
2505
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2506
|
-
*
|
|
2507
2582
|
* @param columns - An array of column names whose values will be concatenated with labels.
|
|
2508
2583
|
* @param newColumn - The name of the new column to create with the concatenated values.
|
|
2509
2584
|
* @returns The table, so methods can be chained.
|
|
@@ -2551,8 +2626,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2551
2626
|
*
|
|
2552
2627
|
* Each value in the specified column is split using the provided separator, and a new row is created for each resulting substring. All other column values are duplicated across the newly created rows.
|
|
2553
2628
|
*
|
|
2554
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2555
|
-
*
|
|
2556
2629
|
* @param column - The name of the column containing string values to be split and unnested.
|
|
2557
2630
|
* @param separator - The delimiter string used to split the column values.
|
|
2558
2631
|
* @returns The table, so methods can be chained.
|
|
@@ -2585,8 +2658,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2585
2658
|
*
|
|
2586
2659
|
* If a row has a value of 3 in the specified column, it will be repeated 3 times. If the value is 0 or negative, the row will be removed.
|
|
2587
2660
|
*
|
|
2588
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2589
|
-
*
|
|
2590
2661
|
* @param column - The name of the column containing the number of times each row should be repeated.
|
|
2591
2662
|
* @param options - An optional object with configuration options:
|
|
2592
2663
|
* @param options.index - The name of a new column to store the index of the repeated row (starting at 0).
|
|
@@ -2618,8 +2689,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2618
2689
|
*
|
|
2619
2690
|
* This is the inverse operation of `unnest()`. Multiple rows are combined into fewer rows by grouping on specified category columns and concatenating the target column values with a separator.
|
|
2620
2691
|
*
|
|
2621
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2622
|
-
*
|
|
2623
2692
|
* @param column - The name of the column whose values will be aggregated and concatenated.
|
|
2624
2693
|
* @param separator - The delimiter string used to join the column values.
|
|
2625
2694
|
* @param by - The column name or an array of column names to group by.
|
|
@@ -2652,8 +2721,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2652
2721
|
/**
|
|
2653
2722
|
* Rounds numeric values in specified columns.
|
|
2654
2723
|
*
|
|
2655
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2656
|
-
*
|
|
2657
2724
|
* @param columns - The column name or an array of column names containing numeric values to be rounded.
|
|
2658
2725
|
* @param options - An optional integer specifying the number of decimal places, or an object with configuration options:
|
|
2659
2726
|
* @param options.decimals - The number of decimal places to round to. Defaults to `0` (rounds to the nearest integer).
|
|
@@ -2696,9 +2763,37 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2696
2763
|
return this;
|
|
2697
2764
|
}
|
|
2698
2765
|
/**
|
|
2699
|
-
*
|
|
2766
|
+
* Adds independently generated uniform random noise to numeric values in one or more columns.
|
|
2767
|
+
* Each changed value receives an offset between `-max` and `max`. Selected integer and decimal columns become `DOUBLE` columns so fractional noise is retained. This method adds random jitter; it does not provide anonymization or differential privacy guarantees.
|
|
2768
|
+
*
|
|
2769
|
+
* @param columns - The numeric column name or array of numeric column names to which noise will be added. When multiple columns are provided, each value receives an independent random offset.
|
|
2770
|
+
* @param max - The maximum absolute offset, expressed in each column's units. Must be a finite number greater than or equal to `0`.
|
|
2771
|
+
* @param options - An optional object with configuration options:
|
|
2772
|
+
* @param options.onlyDuplicates - If `true`, adds noise only to values that occur more than once in their column. Each selected column is evaluated independently, and every occurrence of a duplicated value is changed. Defaults to `false`.
|
|
2773
|
+
* @returns The table, so methods can be chained.
|
|
2774
|
+
* @category Updating Data
|
|
2775
|
+
*
|
|
2776
|
+
* @example
|
|
2777
|
+
* ```ts
|
|
2778
|
+
* // Add an offset between -0.01 and 0.01 to every value
|
|
2779
|
+
* await table.addNoise("measurement", 0.01).log();
|
|
2780
|
+
* ```
|
|
2700
2781
|
*
|
|
2701
|
-
*
|
|
2782
|
+
* @example
|
|
2783
|
+
* ```ts
|
|
2784
|
+
* // Add noise independently to duplicated x values and duplicated y values
|
|
2785
|
+
* await table.addNoise(["x", "y"], 0.1, {
|
|
2786
|
+
* onlyDuplicates: true,
|
|
2787
|
+
* }).log();
|
|
2788
|
+
* ```
|
|
2789
|
+
*/
|
|
2790
|
+
addNoise(columns, max, options = {}) {
|
|
2791
|
+
(0, addNoise_js_1.default)(this, columns, max, options);
|
|
2792
|
+
return this;
|
|
2793
|
+
}
|
|
2794
|
+
/**
|
|
2795
|
+
* Updates values in a specified column using a SQL expression.
|
|
2796
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, expressions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
2702
2797
|
*
|
|
2703
2798
|
* @param column - The name of the column to be updated.
|
|
2704
2799
|
* @param definition - The SQL expression used to set the new values in the column (e.g., `"column1 * 2"`, `"UPPER(column_name)"`).
|
|
@@ -2722,6 +2817,16 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2722
2817
|
* // Set 'status' to 'active' where 'isActive' is true
|
|
2723
2818
|
* await table.updateColumn("status", `CASE WHEN isActive THEN 'active' ELSE 'inactive' END`).log();
|
|
2724
2819
|
* ```
|
|
2820
|
+
*
|
|
2821
|
+
* @example
|
|
2822
|
+
* ```ts
|
|
2823
|
+
* // Update an existing column with a value from a JSON object using dot notation.
|
|
2824
|
+
* await table.loadArray([{ count: 0, details: { count: 3 } }], {
|
|
2825
|
+
* columnTypes: { details: "JSON" },
|
|
2826
|
+
* })
|
|
2827
|
+
* .updateColumn("count", "details.count")
|
|
2828
|
+
* .log();
|
|
2829
|
+
* ```
|
|
2725
2830
|
*/
|
|
2726
2831
|
updateColumn(column, definition) {
|
|
2727
2832
|
(0, updateColumn_js_1.default)(this, column, definition);
|
|
@@ -2730,8 +2835,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2730
2835
|
/**
|
|
2731
2836
|
* Assigns ranks to rows in a new column based on the values of a specified column.
|
|
2732
2837
|
*
|
|
2733
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2734
|
-
*
|
|
2735
2838
|
* @param column - The column containing the values to be used for ranking.
|
|
2736
2839
|
* @param newColumn - The name of the new column where the ranks will be stored.
|
|
2737
2840
|
* @param options - An optional object with configuration options:
|
|
@@ -2772,8 +2875,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2772
2875
|
/**
|
|
2773
2876
|
* Assigns quantiles to rows in a new column based on specified column values.
|
|
2774
2877
|
*
|
|
2775
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2776
|
-
*
|
|
2777
2878
|
* @param column - The column containing values from which quantiles will be assigned.
|
|
2778
2879
|
* @param count - The number of quantiles to divide the data into (e.g., `4` for quartiles, `10` for deciles).
|
|
2779
2880
|
* @param newColumn - The name of the new column where the assigned quantiles will be stored.
|
|
@@ -2807,8 +2908,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2807
2908
|
/**
|
|
2808
2909
|
* Assigns bins for specified column values based on an interval size.
|
|
2809
2910
|
*
|
|
2810
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2811
|
-
*
|
|
2812
2911
|
* @param column - The column containing values from which bins will be computed.
|
|
2813
2912
|
* @param interval - The interval size for binning the values.
|
|
2814
2913
|
* @param newColumn - The name of the new column where the bins will be stored.
|
|
@@ -2878,11 +2977,16 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2878
2977
|
* | 2022 | 354 | 278 | 56 | 0.51 | 0.4 | 0.08 |
|
|
2879
2978
|
* | 2023 | 856 | 321 | 221 | 0.61 | 0.23 | 0.16 |
|
|
2880
2979
|
*
|
|
2881
|
-
*
|
|
2980
|
+
* @example
|
|
2981
|
+
* ```ts
|
|
2982
|
+
* // Compute percentages that sum to 100 on each row before rounding
|
|
2983
|
+
* await table.rowProportions(["Men", "Women", "NonBinary"], { base: 100, decimals: 1 }).log();
|
|
2984
|
+
* ```
|
|
2882
2985
|
*
|
|
2883
2986
|
* @param columns - An array of column names for which proportions will be computed on each row.
|
|
2884
2987
|
* @param options - An optional object with configuration options:
|
|
2885
2988
|
* @param options.suffix - A string suffix to append to the names of the new columns storing the computed proportions. Defaults to `"Perc"`.
|
|
2989
|
+
* @param options.base - A finite positive value that the proportions in each row sum to before rounding. Defaults to `1`.
|
|
2886
2990
|
* @param options.decimals - The number of decimal places to round the computed proportions. Defaults to `undefined` (no rounding).
|
|
2887
2991
|
* @returns The table, so methods can be chained.
|
|
2888
2992
|
* @category Analyzing Data
|
|
@@ -2902,9 +3006,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2902
3006
|
* option can therefore increase the table's row count. If null values leave
|
|
2903
3007
|
* a row without the requested rank, the new columns contain null.
|
|
2904
3008
|
*
|
|
2905
|
-
* This method queues the operation; it runs when an async observer method
|
|
2906
|
-
* (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2907
|
-
*
|
|
2908
3009
|
* @param columns - The numeric columns to rank within each row.
|
|
2909
3010
|
* @param options - The output columns and ranking configuration. At least one of `nameColumn` or `valueColumn` is required.
|
|
2910
3011
|
* @param options.nameColumn - The name of a new column containing the selected source column's name.
|
|
@@ -2941,12 +3042,11 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2941
3042
|
/**
|
|
2942
3043
|
* Computes proportions vertically over a column's values, relative to the sum of all values in that column or group.
|
|
2943
3044
|
*
|
|
2944
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2945
|
-
*
|
|
2946
3045
|
* @param column - The column containing values for which proportions will be computed. The proportions are calculated based on the sum of values in the specified column.
|
|
2947
3046
|
* @param newColumn - The name of the new column where the proportions will be stored.
|
|
2948
3047
|
* @param options - An optional object with configuration options:
|
|
2949
3048
|
* @param options.by - The column name or an array of column names to partition by. Proportions are calculated independently within each group.
|
|
3049
|
+
* @param options.base - A finite positive value that the proportions in the column or each group sum to before rounding. Defaults to `1`.
|
|
2950
3050
|
* @param options.decimals - The number of decimal places to round the computed proportions. Defaults to `undefined` (no rounding).
|
|
2951
3051
|
* @returns The table, so methods can be chained.
|
|
2952
3052
|
* @category Analyzing Data
|
|
@@ -2965,6 +3065,12 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2965
3065
|
*
|
|
2966
3066
|
* @example
|
|
2967
3067
|
* ```ts
|
|
3068
|
+
* // Compute percentages that sum to 100 before rounding
|
|
3069
|
+
* await table.columnProportions("sales", "sales_percentage", { base: 100, decimals: 1 }).log();
|
|
3070
|
+
* ```
|
|
3071
|
+
*
|
|
3072
|
+
* @example
|
|
3073
|
+
* ```ts
|
|
2968
3074
|
* // Compute proportions for 'sales' by 'region' and 'product_type'
|
|
2969
3075
|
* await table.columnProportions("sales", "sales_proportion", { by: ["region", "product_type"] }).log();
|
|
2970
3076
|
* ```
|
|
@@ -2977,8 +3083,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
2977
3083
|
* Creates a summary table from selected columns, optionally grouped by other columns.
|
|
2978
3084
|
* This method allows you to aggregate data, calculate statistics (e.g., count, mean, sum), and group results by categorical columns.
|
|
2979
3085
|
*
|
|
2980
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2981
|
-
*
|
|
2982
3086
|
* @param options - An object with configuration options for summarization:
|
|
2983
3087
|
* @param options.columns - The column name or an array of column names to summarize. If omitted, only the row count is returned.
|
|
2984
3088
|
* @param options.by - The column name or an array of column names to group by.
|
|
@@ -3077,9 +3181,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3077
3181
|
* string is also used as its row label; pass an object to customize that
|
|
3078
3182
|
* label. If `options.stats` is omitted, every supported stat is added.
|
|
3079
3183
|
*
|
|
3080
|
-
* This method queues the operation; it runs when an async observer method
|
|
3081
|
-
* (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3082
|
-
*
|
|
3083
3184
|
* @param columns - The numeric column name, an array of numeric column names, or `"all"` to summarize every numeric column.
|
|
3084
3185
|
* @param labelColumn - The existing string column in which stat row labels will be written.
|
|
3085
3186
|
* @param options - An optional object with configuration options:
|
|
@@ -3121,8 +3222,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3121
3222
|
/**
|
|
3122
3223
|
* Computes the cumulative sum of values in a column. For this method to work properly, ensure your data is sorted first.
|
|
3123
3224
|
*
|
|
3124
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3125
|
-
*
|
|
3126
3225
|
* @param column - The name of the column storing the values to be accumulated.
|
|
3127
3226
|
* @param newColumn - The name of the new column in which the computed cumulative values will be stored.
|
|
3128
3227
|
* @param options - An optional object with configuration options:
|
|
@@ -3159,8 +3258,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3159
3258
|
* For rows without enough preceding or following rows to form a complete window, `NULL` will be returned.
|
|
3160
3259
|
* For this method to work properly, ensure your data is sorted by the relevant column(s) first.
|
|
3161
3260
|
*
|
|
3162
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3163
|
-
*
|
|
3164
3261
|
* @param column - The name of the column storing the values to be aggregated.
|
|
3165
3262
|
* @param newColumn - The name of the new column in which the computed rolling values will be stored.
|
|
3166
3263
|
* @param stat - The aggregation function to apply: `"min"`, `"max"`, `"mean"`, `"median"`, or `"sum"`.
|
|
@@ -3199,8 +3296,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3199
3296
|
* Calculates correlations between columns. If no `x` and `y` columns are specified, the method computes the correlations for all numeric column combinations.
|
|
3200
3297
|
* Note that correlation is symmetrical: the correlation of `x` with `y` is the same as `y` with `x`.
|
|
3201
3298
|
*
|
|
3202
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3203
|
-
*
|
|
3204
3299
|
* @param options - An optional object with configuration options:
|
|
3205
3300
|
* @param options.x - The name of the column for the x-values. If omitted, correlations will be computed for all numeric columns.
|
|
3206
3301
|
* @param options.y - The name of the column for the y-values. It can be provided only when `options.x` is also set. If both are omitted, correlations will be computed for all numeric column pairs.
|
|
@@ -3248,8 +3343,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3248
3343
|
* If no `x` and `y` columns are specified, the method computes linear regression analysis for all numeric column permutations.
|
|
3249
3344
|
* Note that linear regression analysis is asymmetrical: the linear regression of `x` over `y` is not the same as `y` over `x`.
|
|
3250
3345
|
*
|
|
3251
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3252
|
-
*
|
|
3253
3346
|
* @param options - An optional object with configuration options:
|
|
3254
3347
|
* @param options.x - The name of the column for the independent variable (x-values). If omitted, linear regressions will be computed for all numeric columns as x.
|
|
3255
3348
|
* @param options.y - The name of the column for the dependent variable (y-values). It can be provided only when `options.x` is also set. If both are omitted, linear regressions will be computed for all numeric column permutations.
|
|
@@ -3295,8 +3388,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3295
3388
|
/**
|
|
3296
3389
|
* Identifies outliers in a specified column using the Interquartile Range (IQR) method.
|
|
3297
3390
|
*
|
|
3298
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3299
|
-
*
|
|
3300
3391
|
* @param column - The name of the column in which outliers will be identified.
|
|
3301
3392
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for outlier, `FALSE` otherwise) will be stored.
|
|
3302
3393
|
* @param options - An optional object with configuration options:
|
|
@@ -3323,8 +3414,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3323
3414
|
/**
|
|
3324
3415
|
* Computes the Z-score for values in a specified column.
|
|
3325
3416
|
*
|
|
3326
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3327
|
-
*
|
|
3328
3417
|
* @param column - The name of the column for which Z-scores will be calculated.
|
|
3329
3418
|
* @param newColumn - The name of the new column where the computed Z-scores will be stored.
|
|
3330
3419
|
* @param options - An optional object with configuration options:
|
|
@@ -3358,8 +3447,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3358
3447
|
/**
|
|
3359
3448
|
* Normalizes the values in a column using min-max normalization.
|
|
3360
3449
|
*
|
|
3361
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3362
|
-
*
|
|
3363
3450
|
* @param column - The name of the column in which values will be normalized.
|
|
3364
3451
|
* @param newColumn - The name of the new column where normalized values will be stored.
|
|
3365
3452
|
* @param options - An optional object with configuration options:
|
|
@@ -3404,8 +3491,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3404
3491
|
*
|
|
3405
3492
|
* Exact temporal references are compared at their full DuckDB precision. JavaScript `Date` objects only have millisecond precision and always represent an instant. Construct them with an explicit timezone, such as `new Date("2001-01-01T00:00:00Z")`; date-time strings without `Z` or an offset use the user's local timezone.
|
|
3406
3493
|
*
|
|
3407
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3408
|
-
*
|
|
3409
3494
|
* @param column - The numeric column containing the values to index.
|
|
3410
3495
|
* @param newColumn - The name of the new column where indexed values will be stored.
|
|
3411
3496
|
* @param reference - A statistic calculated from `column`, a column and exact non-null `equals` value selecting a row, or a column and `at` set to `min` or `max` selecting its unique extreme row. The selected row's `column` value becomes the reference.
|
|
@@ -3463,50 +3548,84 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3463
3548
|
/**
|
|
3464
3549
|
* Updates data in the table using a JavaScript function. The function receives the existing rows as an array of objects and must return the modified rows as an array of objects.
|
|
3465
3550
|
* This method offers high flexibility for data manipulation but can be slow for large tables as it involves transferring data between DuckDB and JavaScript.
|
|
3466
|
-
*
|
|
3551
|
+
* Before writing a JavaScript callback, check for an existing SDA method that
|
|
3552
|
+
* performs the same operation; it will usually be faster and more efficient.
|
|
3467
3553
|
*
|
|
3468
|
-
*
|
|
3554
|
+
* If the table has geometry columns, the callback can read and modify their
|
|
3555
|
+
* GeoJSON geometry objects directly. Extra properties added to these objects
|
|
3556
|
+
* are ignored; create new columns on the returned rows to store additional
|
|
3557
|
+
* attributes. All geometry columns must use EPSG:4326; use reproject() first
|
|
3558
|
+
* if needed.
|
|
3469
3559
|
*
|
|
3470
3560
|
* @param dataModifier - A synchronous or asynchronous function that takes the existing rows (as an array of objects) and returns the modified rows (as an array of objects).
|
|
3471
3561
|
* @param options - An optional object with configuration options:
|
|
3472
|
-
* @param options.batchSize - If provided, rows are processed in batches of this size instead of all at once, so large tables don't have to be materialized entirely in memory. The modifier function is called once per batch.
|
|
3562
|
+
* @param options.batchSize - If provided, rows are processed in batches of this size instead of all at once, so large tables don't have to be materialized entirely in memory. This limits input rows per batch, but does not eliminate conversion work or bound geometry size or callback output expansion. The modifier function is called once per batch. Tables with a column named `rowid` or `__sda_rowid` (case-insensitive) are rejected before the modifier runs; rename the column or omit batchSize.
|
|
3563
|
+
* @param options.columnTypes - Explicit types for newly added columns, following loadArray's columnTypes contract. Declare geometry as GEOMETRY('EPSG:4326'); geometry is never inferred from object shape. Existing columns cannot be redeclared.
|
|
3473
3564
|
* @returns The table, so methods can be chained.
|
|
3474
3565
|
* @category Updating Data
|
|
3475
3566
|
*
|
|
3476
3567
|
* @example
|
|
3477
3568
|
* ```ts
|
|
3478
|
-
* //
|
|
3479
|
-
*
|
|
3480
|
-
*
|
|
3481
|
-
*
|
|
3482
|
-
*
|
|
3483
|
-
* .updateWithJS((rows) => {
|
|
3484
|
-
* return rows.map((row) => ({
|
|
3485
|
-
* ...row,
|
|
3486
|
-
* wordCount: typeof row.text === "string"
|
|
3487
|
-
* ? [...segmenter.segment(row.text)].filter((part) => part.isWordLike)
|
|
3488
|
-
* .length
|
|
3489
|
-
* : null,
|
|
3490
|
-
* }));
|
|
3491
|
-
* })
|
|
3569
|
+
* // Double the value in each row with a JavaScript callback.
|
|
3570
|
+
* await table.loadArray([{ value: 1 }, { value: 2 }])
|
|
3571
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3572
|
+
* value: Number(row.value) * 2,
|
|
3573
|
+
* })))
|
|
3492
3574
|
* .log();
|
|
3493
3575
|
* ```
|
|
3494
3576
|
*
|
|
3495
3577
|
* @example
|
|
3496
3578
|
* ```ts
|
|
3497
|
-
* //
|
|
3498
|
-
*
|
|
3499
|
-
* .updateWithJS(
|
|
3500
|
-
*
|
|
3501
|
-
*
|
|
3502
|
-
* headers: { "content-type": "application/json" },
|
|
3503
|
-
* body: JSON.stringify(rows.map((row) => row.review)),
|
|
3504
|
-
* });
|
|
3505
|
-
* const scores = await response.json() as number[];
|
|
3506
|
-
* return rows.map((row, index) => ({ ...row, score: scores[index] }));
|
|
3507
|
-
* }, { batchSize: 100 })
|
|
3579
|
+
* // Process two rows per callback to limit how many rows are handled at once.
|
|
3580
|
+
* await table.loadArray([{ value: 1 }, { value: 2 }, { value: 3 }])
|
|
3581
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3582
|
+
* value: Number(row.value) * 2,
|
|
3583
|
+
* })), { batchSize: 2 })
|
|
3508
3584
|
* .log();
|
|
3509
3585
|
* ```
|
|
3586
|
+
*
|
|
3587
|
+
* @example
|
|
3588
|
+
* ```ts
|
|
3589
|
+
* // Add a JSON object column to keep related attributes together.
|
|
3590
|
+
* await table.loadArray([{ name: "Station" }])
|
|
3591
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3592
|
+
* ...row, details: { active: true, category: "weather" },
|
|
3593
|
+
* })), { columnTypes: { details: "JSON" } })
|
|
3594
|
+
* .log();
|
|
3595
|
+
* ```
|
|
3596
|
+
*
|
|
3597
|
+
* @example
|
|
3598
|
+
* ```ts
|
|
3599
|
+
* // Add a three-element float vector, such as an embedding.
|
|
3600
|
+
* await table.loadArray([{ name: "Station" }])
|
|
3601
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3602
|
+
* ...row, embedding: [0.25, 0.5, 0.75],
|
|
3603
|
+
* })), { columnTypes: { embedding: "FLOAT[3]" } })
|
|
3604
|
+
* .log();
|
|
3605
|
+
* ```
|
|
3606
|
+
*
|
|
3607
|
+
* @example
|
|
3608
|
+
* ```ts
|
|
3609
|
+
* // Move each point slightly east by editing its longitude.
|
|
3610
|
+
* await sdb.newTable().loadArray([{
|
|
3611
|
+
* geom: { type: "Point", coordinates: [-73, 45] },
|
|
3612
|
+
* }], { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } })
|
|
3613
|
+
* .updateWithJS((rows) => rows.map((row) => {
|
|
3614
|
+
* // This example loads only Points. Narrow the type for coordinate access.
|
|
3615
|
+
* const geom = row.geom as { type: "Point"; coordinates: number[] } | null;
|
|
3616
|
+
* if (geom !== null) geom.coordinates[0] += 0.01;
|
|
3617
|
+
* return row;
|
|
3618
|
+
* })).log();
|
|
3619
|
+
* ```
|
|
3620
|
+
*
|
|
3621
|
+
* @example
|
|
3622
|
+
* ```ts
|
|
3623
|
+
* // Create a geometry column from longitude and latitude values.
|
|
3624
|
+
* await sdb.newTable().loadArray([{ longitude: -73, latitude: 45 }])
|
|
3625
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3626
|
+
* ...row, geom: { type: "Point", coordinates: [row.longitude, row.latitude] },
|
|
3627
|
+
* })), { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } }).log();
|
|
3628
|
+
* ```
|
|
3510
3629
|
*/
|
|
3511
3630
|
updateWithJS(dataModifier, options = {}) {
|
|
3512
3631
|
(0, updateWithJS_js_1.default)(this, dataModifier, options);
|
|
@@ -3587,8 +3706,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3587
3706
|
* Produces identical output to `journalism-format`'s `normalizeString()` function
|
|
3588
3707
|
* for all common cases including accented Latin characters.
|
|
3589
3708
|
*
|
|
3590
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3591
|
-
*
|
|
3592
3709
|
* @param column The column containing the text to normalize
|
|
3593
3710
|
* @param newColumn The column to store the normalized results
|
|
3594
3711
|
* @param options Configuration options
|
|
@@ -3634,8 +3751,48 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3634
3751
|
const result = (await (0, getColumns_js_1.default)(this)).length;
|
|
3635
3752
|
return result;
|
|
3636
3753
|
}
|
|
3754
|
+
/**
|
|
3755
|
+
* Adds a new column containing the number of characters in each string in the specified column.
|
|
3756
|
+
* Counts are based on Unicode code points, not grapheme clusters. A user-perceived character composed of multiple code points, such as some emoji or decomposed accented letters, counts as multiple characters.
|
|
3757
|
+
* `NULL` input values produce `NULL` counts.
|
|
3758
|
+
*
|
|
3759
|
+
* @param column - The name of the column containing the strings to count.
|
|
3760
|
+
* @param newColumn - The name of the new column where the character counts will be stored.
|
|
3761
|
+
* @returns The table, so methods can be chained.
|
|
3762
|
+
* @category Text Processing
|
|
3763
|
+
*
|
|
3764
|
+
* @example
|
|
3765
|
+
* ```ts
|
|
3766
|
+
* // Add a character count for each value in the 'name' column
|
|
3767
|
+
* await table.addCharacterCount("name", "nameCharacterCount").log();
|
|
3768
|
+
* ```
|
|
3769
|
+
*/
|
|
3770
|
+
addCharacterCount(column, newColumn) {
|
|
3771
|
+
(0, addCharacterCount_js_1.default)(this, column, newColumn);
|
|
3772
|
+
return this;
|
|
3773
|
+
}
|
|
3774
|
+
/**
|
|
3775
|
+
* Adds a new column containing the word count for each string in the specified column.
|
|
3776
|
+
* A word is any contiguous sequence of non-whitespace characters. Spaces, tabs, and line breaks separate words. Punctuation is not removed, so a standalone punctuation sequence counts as a word. Text without whitespace counts as one word, regardless of language. Empty or whitespace-only strings produce `0`, and `NULL` input values produce `NULL` counts.
|
|
3777
|
+
*
|
|
3778
|
+
* @param column - The name of the column containing the strings to count.
|
|
3779
|
+
* @param newColumn - The name of the new column where the word counts will be stored.
|
|
3780
|
+
* @returns The table, so methods can be chained.
|
|
3781
|
+
* @category Text Processing
|
|
3782
|
+
*
|
|
3783
|
+
* @example
|
|
3784
|
+
* ```ts
|
|
3785
|
+
* // Add a word count for each value in the 'article' column
|
|
3786
|
+
* await table.addWordCount("article", "wordCount").log();
|
|
3787
|
+
* ```
|
|
3788
|
+
*/
|
|
3789
|
+
addWordCount(column, newColumn) {
|
|
3790
|
+
(0, addWordCount_js_1.default)(this, column, newColumn);
|
|
3791
|
+
return this;
|
|
3792
|
+
}
|
|
3637
3793
|
/**
|
|
3638
3794
|
* Returns the total number of characters in a column storing strings.
|
|
3795
|
+
* Counts are based on Unicode code points, not grapheme clusters. A user-perceived character composed of multiple code points, such as some emoji or decomposed accented letters, counts as multiple characters.
|
|
3639
3796
|
*
|
|
3640
3797
|
* @param column - The name of the string column to count characters from.
|
|
3641
3798
|
* @returns A promise that resolves to the total number of characters across all rows in the specified column.
|
|
@@ -3653,6 +3810,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3653
3810
|
}
|
|
3654
3811
|
/**
|
|
3655
3812
|
* Returns the number of rows in the table.
|
|
3813
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
3656
3814
|
*
|
|
3657
3815
|
* @param options - An optional object with configuration options:
|
|
3658
3816
|
* @param options.conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"category = 'Book'"`).
|
|
@@ -3993,7 +4151,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
3993
4151
|
}
|
|
3994
4152
|
/**
|
|
3995
4153
|
* Returns the first row of the table, optionally filtered by SQL conditions.
|
|
3996
|
-
*
|
|
4154
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
3997
4155
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
3998
4156
|
*
|
|
3999
4157
|
* @param options - An optional object with configuration options:
|
|
@@ -4020,7 +4178,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4020
4178
|
}
|
|
4021
4179
|
/**
|
|
4022
4180
|
* Returns the last row of the table, optionally filtered by SQL conditions.
|
|
4023
|
-
*
|
|
4181
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4024
4182
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4025
4183
|
*
|
|
4026
4184
|
* @param options - An optional object with configuration options:
|
|
@@ -4047,7 +4205,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4047
4205
|
}
|
|
4048
4206
|
/**
|
|
4049
4207
|
* Returns the top `n` rows of the table, optionally filtered by SQL conditions.
|
|
4050
|
-
*
|
|
4208
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4051
4209
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4052
4210
|
*
|
|
4053
4211
|
* @param count - The number of rows to return from the top of the table.
|
|
@@ -4076,7 +4234,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4076
4234
|
/**
|
|
4077
4235
|
* Returns the bottom `n` rows of the table, optionally filtered by SQL conditions.
|
|
4078
4236
|
* By default, the last row will be returned first. To preserve the original order, use the `originalOrder` option.
|
|
4079
|
-
*
|
|
4237
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4080
4238
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4081
4239
|
*
|
|
4082
4240
|
* @param count - The number of rows to return from the bottom of the table.
|
|
@@ -4112,7 +4270,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4112
4270
|
}
|
|
4113
4271
|
/**
|
|
4114
4272
|
* Returns a single row that matches the specified conditions. If no row matches or if more than one row matches, an error is thrown by default.
|
|
4115
|
-
*
|
|
4273
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4116
4274
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4117
4275
|
*
|
|
4118
4276
|
* @param conditions - The conditions to match, specified as a SQL `WHERE` clause.
|
|
@@ -4157,13 +4315,26 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4157
4315
|
}
|
|
4158
4316
|
/**
|
|
4159
4317
|
* Returns the data from the table as an array of objects, optionally filtered by SQL conditions.
|
|
4160
|
-
*
|
|
4318
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4161
4319
|
*
|
|
4162
4320
|
* Top-level DuckDB `DATE` and `TIMESTAMP` columns are returned as JavaScript
|
|
4163
4321
|
* `Date` objects interpreted in UTC. `TIMESTAMP WITH TIME ZONE` values are
|
|
4164
4322
|
* returned as UTC strings, preserving DuckDB's microsecond precision;
|
|
4165
4323
|
* JavaScript `Date` supports only milliseconds.
|
|
4166
4324
|
*
|
|
4325
|
+
* Top-level `BIGINT`, `UBIGINT`, `HUGEINT`, and `UHUGEINT` columns are
|
|
4326
|
+
* returned as JavaScript numbers. Values outside `Number.MIN_SAFE_INTEGER`
|
|
4327
|
+
* through `Number.MAX_SAFE_INTEGER` throw instead of losing precision.
|
|
4328
|
+
* Use `convert({ columnName: "string" })` before `getData()` to retrieve
|
|
4329
|
+
* their exact digits as strings.
|
|
4330
|
+
*
|
|
4331
|
+
* SQL arrays and lists, including float vectors, return their actual elements
|
|
4332
|
+
* as JavaScript arrays. Null cells and null elements remain null.
|
|
4333
|
+
*
|
|
4334
|
+
* Nested SQL lists and structs become JavaScript arrays and objects. Within
|
|
4335
|
+
* them, `BIGINT`, `UBIGINT`, `HUGEINT`, `UHUGEINT`, and `DECIMAL` values remain
|
|
4336
|
+
* strings to preserve precision, even for small integers.
|
|
4337
|
+
*
|
|
4167
4338
|
* @param options - An optional object with configuration options:
|
|
4168
4339
|
* @param options.columns - An array of column names to include in the result. If omitted, all columns will be included.
|
|
4169
4340
|
* @param options.conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"category = 'Book'"`).
|
|
@@ -4197,6 +4368,18 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4197
4368
|
* // Return at most two rows.
|
|
4198
4369
|
* const preview = await table.getData({ limit: 2 });
|
|
4199
4370
|
* ```
|
|
4371
|
+
*
|
|
4372
|
+
* @example
|
|
4373
|
+
* ```ts
|
|
4374
|
+
* // Read nested integers without losing digits. SQL creates the nested types.
|
|
4375
|
+
* await sdb.customQuery(`CREATE TABLE nested_example AS SELECT
|
|
4376
|
+
* [42::BIGINT, 9007199254740993::BIGINT] AS ids,
|
|
4377
|
+
* {'count': 2::INTEGER, 'amount': 123.450::DECIMAL(6,3)} AS details`);
|
|
4378
|
+
* const nested = sdb.newTable("nested_example");
|
|
4379
|
+
* const rows = await nested.getData();
|
|
4380
|
+
* // [{ ids: ["42", "9007199254740993"], details: { count: 2, amount: "123.450" } }]
|
|
4381
|
+
* await nested.log();
|
|
4382
|
+
* ```
|
|
4200
4383
|
*/
|
|
4201
4384
|
async getData(options = {}) {
|
|
4202
4385
|
return await (0, getData_js_1.default)(this, options);
|
|
@@ -4205,6 +4388,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4205
4388
|
* Streams the table rows one by one as an async iterator, without
|
|
4206
4389
|
* materializing the whole table in memory. Values are converted to
|
|
4207
4390
|
* JavaScript types the same way as `getData()`.
|
|
4391
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4208
4392
|
*
|
|
4209
4393
|
* The underlying DuckDB result is streamed chunk by chunk, so tables
|
|
4210
4394
|
* larger than the available memory can be iterated. Avoid running other
|
|
@@ -4237,7 +4421,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4237
4421
|
}
|
|
4238
4422
|
/**
|
|
4239
4423
|
* Returns the data from the table as a CSV string, optionally filtered by SQL conditions.
|
|
4240
|
-
*
|
|
4424
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4241
4425
|
* Temporal values are first converted as they are in `getData()`, then
|
|
4242
4426
|
* serialized using UTC date and timestamp text.
|
|
4243
4427
|
*
|
|
@@ -4276,8 +4460,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4276
4460
|
/**
|
|
4277
4461
|
* Creates point geometries from latitude (y) and longitude (x) columns.
|
|
4278
4462
|
*
|
|
4279
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4280
|
-
*
|
|
4281
4463
|
* @param latColumn - The name of the column storing the latitude (y-coordinate) values.
|
|
4282
4464
|
* @param lonColumn - The name of the column storing the longitude (x-coordinate) values.
|
|
4283
4465
|
* @param newColumn - The name of the new column where the point geometries will be stored.
|
|
@@ -4307,8 +4489,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4307
4489
|
/**
|
|
4308
4490
|
* Adds a column with boolean values indicating the validity of geometries.
|
|
4309
4491
|
*
|
|
4310
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4311
|
-
*
|
|
4312
4492
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for valid, `FALSE` for invalid) will be stored.
|
|
4313
4493
|
* @param options - An optional object with configuration options:
|
|
4314
4494
|
* @param options.column - The name of the column storing the geometries to be checked. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4335,8 +4515,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4335
4515
|
/**
|
|
4336
4516
|
* Adds a column with the number of vertices (points) in each geometry.
|
|
4337
4517
|
*
|
|
4338
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4339
|
-
*
|
|
4340
4518
|
* @param newColumn - The name of the new column where the vertex counts will be stored.
|
|
4341
4519
|
* @param options - An optional object with configuration options:
|
|
4342
4520
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4363,8 +4541,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4363
4541
|
/**
|
|
4364
4542
|
* Attempts to make invalid geometries valid without removing any vertices.
|
|
4365
4543
|
*
|
|
4366
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4367
|
-
*
|
|
4368
4544
|
* @param column - The name of the column storing the geometries to be fixed. If omitted, the method will automatically attempt to find a geometry column.
|
|
4369
4545
|
* @returns The table, so methods can be chained.
|
|
4370
4546
|
* @category Geospatial
|
|
@@ -4388,8 +4564,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4388
4564
|
/**
|
|
4389
4565
|
* Adds a column with boolean values indicating whether geometries are closed (e.g., polygons) or open (e.g., linestrings).
|
|
4390
4566
|
*
|
|
4391
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4392
|
-
*
|
|
4393
4567
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for closed, `FALSE` for open) will be stored.
|
|
4394
4568
|
* @param options - An optional object with configuration options:
|
|
4395
4569
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4415,8 +4589,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4415
4589
|
/**
|
|
4416
4590
|
* Adds a column with the geometry type (e.g., `"POINT"`, `"LINESTRING"`, `"POLYGON"`) for each geometry.
|
|
4417
4591
|
*
|
|
4418
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4419
|
-
*
|
|
4420
4592
|
* @param newColumn - The name of the new column where the geometry types will be stored.
|
|
4421
4593
|
* @param options - An optional object with configuration options:
|
|
4422
4594
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4443,8 +4615,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4443
4615
|
* Flips the coordinate order of geometries in a specified column (e.g., from `[longitude (x), latitude (y)]` to `[latitude (y), longitude (x)]` or vice-versa).
|
|
4444
4616
|
* **Warning:** This method should be used with caution as it directly manipulates coordinate order and can affect the accuracy of geospatial operations if not used correctly.
|
|
4445
4617
|
*
|
|
4446
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4447
|
-
*
|
|
4448
4618
|
* @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
4449
4619
|
* @returns The table, so methods can be chained.
|
|
4450
4620
|
* @category Geospatial
|
|
@@ -4466,9 +4636,42 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4466
4636
|
return this;
|
|
4467
4637
|
}
|
|
4468
4638
|
/**
|
|
4469
|
-
*
|
|
4639
|
+
* Moves EPSG:4326 point geometries to random locations within a maximum great-circle distance of their original positions.
|
|
4640
|
+
*
|
|
4641
|
+
* Points are sampled uniformly within the requested distance using the spherical direct geodesic (destination-point) formula and the same spherical Earth model as DuckDB's `ST_Distance_Sphere()`. This accounts for longitude scale changing with latitude. This method adds random jitter; it does not provide anonymization or differential privacy guarantees.
|
|
4642
|
+
*
|
|
4643
|
+
* This method supports only `POINT` geometries in `EPSG:4326`. Null and empty geometries are preserved.
|
|
4470
4644
|
*
|
|
4471
|
-
*
|
|
4645
|
+
* @param maxDistance - The maximum great-circle displacement in the selected unit. Must be a finite number greater than or equal to `0` and no greater than half Earth's circumference.
|
|
4646
|
+
* @param options - An optional object with configuration options:
|
|
4647
|
+
* @param options.column - The name of the EPSG:4326 point geometry column. If omitted, the method will automatically attempt to find a geometry column.
|
|
4648
|
+
* @param options.unit - The unit of `maxDistance`: `"m"` for metres or `"km"` for kilometres. Defaults to `"m"`.
|
|
4649
|
+
* @param options.onlyDuplicates - If `true`, moves only points whose complete original geometry occurs more than once in the selected geometry column. Every point in a duplicated group is moved. Defaults to `false`.
|
|
4650
|
+
* @returns The table, so methods can be chained.
|
|
4651
|
+
* @category Geospatial
|
|
4652
|
+
*
|
|
4653
|
+
* @example
|
|
4654
|
+
* ```ts
|
|
4655
|
+
* // Move every point by no more than 500 metres
|
|
4656
|
+
* await table.addGeoNoise(500).log();
|
|
4657
|
+
* ```
|
|
4658
|
+
*
|
|
4659
|
+
* @example
|
|
4660
|
+
* ```ts
|
|
4661
|
+
* // Separate duplicated points by up to 0.1 kilometres
|
|
4662
|
+
* await table.addGeoNoise(0.1, {
|
|
4663
|
+
* column: "geom",
|
|
4664
|
+
* unit: "km",
|
|
4665
|
+
* onlyDuplicates: true,
|
|
4666
|
+
* }).log();
|
|
4667
|
+
* ```
|
|
4668
|
+
*/
|
|
4669
|
+
addGeoNoise(maxDistance, options = {}) {
|
|
4670
|
+
(0, addGeoNoise_js_1.default)(this, maxDistance, options);
|
|
4671
|
+
return this;
|
|
4672
|
+
}
|
|
4673
|
+
/**
|
|
4674
|
+
* Reduces the precision of geometries in a specified column to a given number of decimal places.
|
|
4472
4675
|
*
|
|
4473
4676
|
* @param decimals - The number of decimal places to keep in the coordinates of the geometries.
|
|
4474
4677
|
* @param options - An optional object with configuration options:
|
|
@@ -4495,8 +4698,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4495
4698
|
/**
|
|
4496
4699
|
* Reprojects the geometries in a specified column to another Spatial Reference System (SRS).
|
|
4497
4700
|
*
|
|
4498
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4499
|
-
*
|
|
4500
4701
|
* @param crs - The target SRS (e.g., `"EPSG:3347"`, or `"EPSG:4326"` for EPSG:4326 (WGS84)).
|
|
4501
4702
|
* @param options - An optional object with configuration options:
|
|
4502
4703
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4523,8 +4724,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4523
4724
|
* Computes the area of geometries in square meters (`"m2"`) or optionally square kilometers (`"km2"`).
|
|
4524
4725
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4525
4726
|
*
|
|
4526
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4527
|
-
*
|
|
4528
4727
|
* @param newColumn - The name of the new column where the computed areas will be stored.
|
|
4529
4728
|
* @param options - An optional object with configuration options:
|
|
4530
4729
|
* @param options.unit - The unit for the computed area: `"m2"` (square meters) or `"km2"` (square kilometers). Defaults to `"m2"`.
|
|
@@ -4565,8 +4764,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4565
4764
|
* Computes the length of line geometries in meters (`"m"`) or optionally kilometers (`"km"`).
|
|
4566
4765
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4567
4766
|
*
|
|
4568
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4569
|
-
*
|
|
4570
4767
|
* @param newColumn - The name of the new column where the computed lengths will be stored.
|
|
4571
4768
|
* @param options - An optional object with configuration options:
|
|
4572
4769
|
* @param options.unit - The unit for the computed length: `"m"` (meters) or `"km"` (kilometers). Defaults to `"m"`.
|
|
@@ -4607,8 +4804,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4607
4804
|
* Computes the perimeter of polygon geometries in meters (`"m"`) or optionally kilometers (`"km"`).
|
|
4608
4805
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4609
4806
|
*
|
|
4610
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4611
|
-
*
|
|
4612
4807
|
* @param newColumn - The name of the new column where the computed perimeters will be stored.
|
|
4613
4808
|
* @param options - An optional object with configuration options:
|
|
4614
4809
|
* @param options.unit - The unit for the computed perimeter: `"m"` (meters) or `"km"` (kilometers). Defaults to `"m"`.
|
|
@@ -4649,8 +4844,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4649
4844
|
* Computes a buffer (a polygon representing a specified distance around a geometry) for geometries in a specified column.
|
|
4650
4845
|
* The distance is in the Spatial Reference System (SRS) unit of the input geometries.
|
|
4651
4846
|
*
|
|
4652
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4653
|
-
*
|
|
4654
4847
|
* @param newColumn - The name of the new column where the buffered geometries will be stored.
|
|
4655
4848
|
* @param distance - The distance for the buffer. This value is in the units of the geometry's SRS.
|
|
4656
4849
|
* @param options - An optional object with configuration options:
|
|
@@ -4678,7 +4871,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4678
4871
|
* Merges the data of this table (considered the left table) with another table (the right table) based on a spatial relationship.
|
|
4679
4872
|
* Note that the order of rows in the returned data is not guaranteed to be the same as in the original tables.
|
|
4680
4873
|
* This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
|
|
4681
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called. The join uses the other table's state as of this call: operations queued on it afterwards run after the join.
|
|
4682
4874
|
*
|
|
4683
4875
|
* @param rightTable - The SimpleTable instance to be joined with this table.
|
|
4684
4876
|
* @param method - The spatial join method to use: `"intersect"` (geometries overlap), `"inside"` (geometries of the left table are entirely within geometries of the right table), or `"withinDistance"` (geometries of the left table are within a specified distance of geometries in the right table).
|
|
@@ -4750,8 +4942,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4750
4942
|
/**
|
|
4751
4943
|
* Computes the intersection of two sets of geometries, creating new geometries where they overlap.
|
|
4752
4944
|
*
|
|
4753
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4754
|
-
*
|
|
4755
4945
|
* @param column1 - The name of the first column storing geometries.
|
|
4756
4946
|
* @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
|
|
4757
4947
|
* @param newColumn - The name of the new column where the computed intersection geometries will be stored.
|
|
@@ -4771,8 +4961,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4771
4961
|
/**
|
|
4772
4962
|
* Computes the geometric difference between two geometries, returning the portion of the first geometry that does not intersect the second.
|
|
4773
4963
|
*
|
|
4774
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4775
|
-
*
|
|
4776
4964
|
* @param column1 - The name of the column storing the geometries from which the second geometries will be subtracted.
|
|
4777
4965
|
* @param column2 - The name of the column storing the geometries to subtract. Both columns must have the same projection.
|
|
4778
4966
|
* @param newColumn - The name of the new column where the geometric differences will be stored.
|
|
@@ -4792,8 +4980,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4792
4980
|
/**
|
|
4793
4981
|
* Fills holes in polygon geometries.
|
|
4794
4982
|
*
|
|
4795
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4796
|
-
*
|
|
4797
4983
|
* @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
4798
4984
|
* @returns The table, so methods can be chained.
|
|
4799
4985
|
* @category Geospatial
|
|
@@ -4817,8 +5003,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4817
5003
|
/**
|
|
4818
5004
|
* Returns `TRUE` if two geometries intersect (overlap in any way), and `FALSE` otherwise.
|
|
4819
5005
|
*
|
|
4820
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4821
|
-
*
|
|
4822
5006
|
* @param column1 - The name of the first column storing geometries.
|
|
4823
5007
|
* @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
|
|
4824
5008
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for intersection, `FALSE` otherwise) will be stored.
|
|
@@ -4838,8 +5022,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4838
5022
|
/**
|
|
4839
5023
|
* Returns `TRUE` if every point of a geometry in `column` is covered by a geometry in `containerColumn`, including their boundaries, and `FALSE` otherwise.
|
|
4840
5024
|
*
|
|
4841
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4842
|
-
*
|
|
4843
5025
|
* @param column - The name of the column storing the geometries to be tested for containment.
|
|
4844
5026
|
* @param containerColumn - The name of the column storing the geometries to be tested as containers. Both columns must have the same projection.
|
|
4845
5027
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` when covered, `FALSE` otherwise) will be stored.
|
|
@@ -4859,8 +5041,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4859
5041
|
/**
|
|
4860
5042
|
* Computes the union of two geometries, creating a new geometry that represents the merged area of both.
|
|
4861
5043
|
*
|
|
4862
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4863
|
-
*
|
|
4864
5044
|
* @param column1 - The name of the first column storing geometries.
|
|
4865
5045
|
* @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
|
|
4866
5046
|
* @param newColumn - The name of the new column where the computed union geometries will be stored.
|
|
@@ -4881,8 +5061,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4881
5061
|
* Extracts the latitude (y) and longitude (x) coordinates from point geometries.
|
|
4882
5062
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4883
5063
|
*
|
|
4884
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4885
|
-
*
|
|
4886
5064
|
* @param column - The name of the column storing the point geometries.
|
|
4887
5065
|
* @param latColumn - The name of the new column where the extracted latitude (y-coordinate) values will be stored.
|
|
4888
5066
|
* @param lonColumn - The name of the new column where the extracted longitude (x-coordinate) values will be stored.
|
|
@@ -4902,8 +5080,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4902
5080
|
/**
|
|
4903
5081
|
* Simplifies geometries while preserving their overall coverage. A higher tolerance results in more significant simplification.
|
|
4904
5082
|
*
|
|
4905
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4906
|
-
*
|
|
4907
5083
|
* @param tolerance - A numeric value representing the simplification tolerance. A higher value leads to greater simplification.
|
|
4908
5084
|
* @param options - An optional object with configuration options:
|
|
4909
5085
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4931,8 +5107,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4931
5107
|
* Computes the centroid of geometries.
|
|
4932
5108
|
* The values are returned in the SRS unit of the input geometries.
|
|
4933
5109
|
*
|
|
4934
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4935
|
-
*
|
|
4936
5110
|
* @param newColumn - The name of the new column where the computed centroid geometries will be stored.
|
|
4937
5111
|
* @param options - An optional object with configuration options:
|
|
4938
5112
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4958,8 +5132,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4958
5132
|
/**
|
|
4959
5133
|
* Generates a random point within the geometries of a specified column.
|
|
4960
5134
|
*
|
|
4961
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4962
|
-
*
|
|
4963
5135
|
* @param newColumn - The name of the new column where the random points will be stored.
|
|
4964
5136
|
* @param tries - The number of points to generate within the bounding box of each geometry to find one that is within the geometry itself.
|
|
4965
5137
|
* @param options - An optional object with configuration options:
|
|
@@ -4994,8 +5166,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
4994
5166
|
* You can optionally specify `"spheroid"` or `"haversine"` methods to get results in meters or kilometers.
|
|
4995
5167
|
* If using `"spheroid"` or `"haversine"`, the input geometries must be in EPSG:4326 (WGS84).
|
|
4996
5168
|
*
|
|
4997
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4998
|
-
*
|
|
4999
5169
|
* @param column1 - The name of the first column storing geometries.
|
|
5000
5170
|
* @param column2 - The name of the second column storing geometries.
|
|
5001
5171
|
* @param newColumn - The name of the new column where the computed distances will be stored.
|
|
@@ -5040,8 +5210,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5040
5210
|
/**
|
|
5041
5211
|
* Unnests geometries recursively, transforming multi-part geometries (e.g., MultiPolygon) into individual single-part geometries (e.g., Polygon).
|
|
5042
5212
|
*
|
|
5043
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5044
|
-
*
|
|
5045
5213
|
* @param column - The name of the column storing the geometries to be unnested. If omitted, the method will automatically attempt to find a geometry column.
|
|
5046
5214
|
* @returns The table, so methods can be chained.
|
|
5047
5215
|
* @category Geospatial
|
|
@@ -5065,8 +5233,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5065
5233
|
/**
|
|
5066
5234
|
* Adds the bounding box coordinates of geometries in a specified column as four new columns: `minLon`, `minLat`, `maxLon`, and `maxLat`.
|
|
5067
5235
|
*
|
|
5068
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5069
|
-
*
|
|
5070
5236
|
* @param options - An optional object with configuration options:
|
|
5071
5237
|
* @param options.column - The name of the column storing the geometries for which the bounding box will be computed. If omitted, the method will automatically attempt to find a geometry column.
|
|
5072
5238
|
* @param options.decimals - The number of decimal places to round the bounding box coordinates. Defaults to `undefined` (no rounding).
|
|
@@ -5094,8 +5260,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5094
5260
|
/**
|
|
5095
5261
|
* Aggregates geometries in a specified column based on a chosen aggregation method.
|
|
5096
5262
|
*
|
|
5097
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5098
|
-
*
|
|
5099
5263
|
* @param method - The aggregation method to apply: `"union"` (combines all geometries into a single multi-geometry) or `"intersection"` (computes the intersection of all geometries).
|
|
5100
5264
|
* @param options - An optional object with configuration options:
|
|
5101
5265
|
* @param options.column - The name of the column storing the geometries to be aggregated. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -5128,8 +5292,6 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5128
5292
|
/**
|
|
5129
5293
|
* Transforms closed linestring geometries into polygon geometries.
|
|
5130
5294
|
*
|
|
5131
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5132
|
-
*
|
|
5133
5295
|
* @param column - The name of the column storing the linestring geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
5134
5296
|
* @returns The table, so methods can be chained.
|
|
5135
5297
|
* @category Geospatial
|
|
@@ -5176,7 +5338,9 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5176
5338
|
return await (0, getBoundingBox_js_1.default)(this, column);
|
|
5177
5339
|
}
|
|
5178
5340
|
/**
|
|
5179
|
-
* Returns the table's geospatial data as a GeoJSON
|
|
5341
|
+
* Returns the table's geospatial data as a GeoJSON FeatureCollection.
|
|
5342
|
+
* Each row becomes a Feature: the selected geometry column becomes its geometry,
|
|
5343
|
+
* and the remaining columns become its properties.
|
|
5180
5344
|
* If the table has multiple geometry columns, you must specify which one to use.
|
|
5181
5345
|
*
|
|
5182
5346
|
* @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -5214,12 +5378,13 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5214
5378
|
}
|
|
5215
5379
|
/**
|
|
5216
5380
|
* Writes the table's data to a file in various formats (CSV, JSON, Parquet, DuckDB, SQLite).
|
|
5381
|
+
* Tables with geometry columns must use `writeGeoData()` instead.
|
|
5217
5382
|
* If the specified path does not exist, it will be created.
|
|
5218
5383
|
*
|
|
5219
5384
|
* @param file - The absolute path to the output file (e.g., `"./output.csv"`, `"./output.json"`).
|
|
5220
5385
|
* @param options - An optional object with configuration options:
|
|
5221
5386
|
* @param options.compression - A boolean indicating whether to compress the output file. If `true`, CSV and JSON files will be compressed with GZIP, while Parquet files will use ZSTD. Defaults to `false`.
|
|
5222
|
-
* @param options.dataAsArrays - For JSON files only. If `true`, JSON files are written as a single object with arrays for each column (e.g., `{ "col1": [v1, v2], "col2": [v3, v4] }`) instead of an array of objects. This can reduce file size for web projects. You can use the `arraysToData` function from the [journalism library](https://jsr.io/@nshiab/journalism/doc/~/arraysToData) to convert it back.
|
|
5387
|
+
* @param options.dataAsArrays - For JSON files only. If `true`, JSON files are written as a single object with arrays for each column (e.g., `{ "col1": [v1, v2], "col2": [v3, v4] }`) instead of an array of objects. This can reduce file size for web projects. You can use the `arraysToData` function from the [journalism-format library](https://jsr.io/@nshiab/journalism-format/doc/~/arraysToData) to convert it back.
|
|
5223
5388
|
* @param options.formatDates - For CSV and JSON files only. If `true`, date and timestamp columns will be formatted as ISO 8601 strings (e.g., `"2025-01-01T01:00:00.000Z"`). Defaults to `false`.
|
|
5224
5389
|
* @returns A promise that resolves to the table, so methods can be chained.
|
|
5225
5390
|
* @category File Operations
|
|
@@ -5320,28 +5485,28 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5320
5485
|
* Caches the results of computations in `./.sda-cache`.
|
|
5321
5486
|
* You should add `./.sda-cache` to your `.gitignore` file.
|
|
5322
5487
|
*
|
|
5323
|
-
* Cache entries are stored as DuckDB database files. Full-text search (FTS)
|
|
5324
|
-
* indexes are persisted in the cache file and restored directly on a cache
|
|
5325
|
-
* hit. Vector similarity search (VSS/HNSW) indexes are not persisted in the
|
|
5326
|
-
* cache file; their definitions are stored as metadata and used to rebuild
|
|
5327
|
-
* the indexes on every cache hit. If loading the entry or restoring its
|
|
5328
|
-
* indexes fails, the computation runs again and replaces the cache entry.
|
|
5329
|
-
*
|
|
5330
5488
|
* `cache()` automatically tracks whether earlier SDA operations changed the
|
|
5331
5489
|
* table. It also records every other already registered `SimpleTable` read
|
|
5332
5490
|
* through `SimpleTable` methods while `compute` runs and invalidates the
|
|
5333
5491
|
* cached step when any of their generations change. Tables created inside
|
|
5334
5492
|
* `compute` are part of the computation itself and are not dependencies.
|
|
5335
5493
|
*
|
|
5494
|
+
* Inside `compute`, you may modify the table being cached and create or
|
|
5495
|
+
* modify temporary tables, provided you remove them before the callback
|
|
5496
|
+
* finishes. Other tables that already existed may be read but not modified,
|
|
5497
|
+
* renamed, or removed. `customQuery()` bypasses enforcement of these rules.
|
|
5498
|
+
*
|
|
5336
5499
|
* `SimpleDB.customQuery()` bypasses this tracking. Reading or changing a
|
|
5337
5500
|
* table with `customQuery()` can therefore return stale cached data. Include
|
|
5338
5501
|
* a value that identifies the custom query's dependencies in `options.inputs`
|
|
5339
5502
|
* (such as a table content hash), or use tracked `SimpleTable` methods.
|
|
5340
5503
|
*
|
|
5341
|
-
*
|
|
5342
|
-
*
|
|
5343
|
-
*
|
|
5344
|
-
*
|
|
5504
|
+
* Cache entries are stored as DuckDB database files. Full-text search (FTS)
|
|
5505
|
+
* indexes are persisted in the cache file and restored directly on a cache
|
|
5506
|
+
* hit. Vector similarity search (VSS/HNSW) indexes are not persisted in the
|
|
5507
|
+
* cache file; their definitions are stored as metadata and used to rebuild
|
|
5508
|
+
* the indexes on every cache hit. If loading the entry or restoring its
|
|
5509
|
+
* indexes fails, the computation runs again and replaces the cache entry.
|
|
5345
5510
|
*
|
|
5346
5511
|
* @param compute - A function wrapping the computations to be cached. It receives the table on which `cache()` was called. This function will be executed on the first run or if the cached data is invalid/expired.
|
|
5347
5512
|
* @param options - An optional object with configuration options:
|
|
@@ -5426,7 +5591,16 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5426
5591
|
/**
|
|
5427
5592
|
* Logs a specified number of rows from the table to the console. By default, the first 10 rows are logged.
|
|
5428
5593
|
* You can optionally log the column types and filter the data based on conditions.
|
|
5429
|
-
*
|
|
5594
|
+
* SQL dates and timestamps retain their native precision for display, including
|
|
5595
|
+
* temporal infinities. Lists and objects are stringified using the same nested
|
|
5596
|
+
* representations as `getData()`, then truncated according to `charsToLog`.
|
|
5597
|
+
* Unsafe top-level large integers throw, just as with `getData()`.
|
|
5598
|
+
* Type annotations describe the SQL type and the JavaScript extraction type
|
|
5599
|
+
* before display formatting; nulls do not determine the column's annotation.
|
|
5600
|
+
* Colors reflect the SQL value's meaning, so exact decimal strings use numeric
|
|
5601
|
+
* coloring. Column width is independent of the content truncation budget.
|
|
5602
|
+
*
|
|
5603
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
5430
5604
|
*
|
|
5431
5605
|
* @param options - Either the number of rows to log (a specific number or `"all"`) or an object with configuration options:
|
|
5432
5606
|
* @param options.count - The number of rows to log. Defaults to 10 or the value set in the SimpleDB instance. Use `"all"` to log all rows.
|
|
@@ -5466,57 +5640,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5466
5640
|
* ```
|
|
5467
5641
|
*/
|
|
5468
5642
|
async log(options = {}) {
|
|
5469
|
-
|
|
5470
|
-
await this.sdb.start();
|
|
5471
|
-
this.db = this.sdb.db;
|
|
5472
|
-
this.connection = this.sdb.connection;
|
|
5473
|
-
}
|
|
5474
|
-
if (this.connection === undefined) {
|
|
5475
|
-
throw new Error("this.connection is undefined");
|
|
5476
|
-
}
|
|
5477
|
-
let count;
|
|
5478
|
-
if (typeof options === "number") {
|
|
5479
|
-
count = options;
|
|
5480
|
-
}
|
|
5481
|
-
else if (options === "all") {
|
|
5482
|
-
count = await this.getRowCount();
|
|
5483
|
-
}
|
|
5484
|
-
else if (typeof options === "object") {
|
|
5485
|
-
if (options.count === "all") {
|
|
5486
|
-
count = await this.getRowCount();
|
|
5487
|
-
}
|
|
5488
|
-
else if (typeof options.count === "number") {
|
|
5489
|
-
count = options.count;
|
|
5490
|
-
}
|
|
5491
|
-
else {
|
|
5492
|
-
count = this.rowsToLog;
|
|
5493
|
-
}
|
|
5494
|
-
}
|
|
5495
|
-
else {
|
|
5496
|
-
count = this.rowsToLog;
|
|
5497
|
-
}
|
|
5498
|
-
const types = typeof options === "object"
|
|
5499
|
-
? options.types ?? this.typesToLog
|
|
5500
|
-
: this.typesToLog;
|
|
5501
|
-
const conditions = typeof options === "object"
|
|
5502
|
-
? options.conditions ?? undefined
|
|
5503
|
-
: undefined;
|
|
5504
|
-
if (this.connection === undefined ||
|
|
5505
|
-
!(await this.sdb.hasTable(this.name))) {
|
|
5506
|
-
console.log(`\nTable ${this.name}: no data`);
|
|
5507
|
-
}
|
|
5508
|
-
else {
|
|
5509
|
-
console.log(`\nTable ${this.name}:`);
|
|
5510
|
-
conditions && console.log(`Conditions: ${conditions}`);
|
|
5511
|
-
const data = await this.getTop(count, { conditions });
|
|
5512
|
-
(0, logData_js_1.default)(types ? await this.getTypes() : null, data, this.charsToLog);
|
|
5513
|
-
const rowCount = conditions
|
|
5514
|
-
? parseInt((await this.sdb.customQuery(`select count(*) as count from ${(0, quoteIdentifier_js_1.default)(this.name)} where ${conditions}`, { returnData: true }))[0].count)
|
|
5515
|
-
: await this.getRowCount();
|
|
5516
|
-
console.log(`${(0, formatNumber_js_1.default)(rowCount)} rows in total ${`(count: ${count}${typeof this.charsToLog === "number"
|
|
5517
|
-
? `, charsToLog: ${this.charsToLog}`
|
|
5518
|
-
: ""})`}`);
|
|
5519
|
-
}
|
|
5643
|
+
await (0, log_js_1.default)(this, options);
|
|
5520
5644
|
return this;
|
|
5521
5645
|
}
|
|
5522
5646
|
/**
|
|
@@ -5718,6 +5842,10 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5718
5842
|
/**
|
|
5719
5843
|
* Logs the bottom `n` rows of the table to the console. By default, the last row will be returned first. To preserve the original order, use the `originalOrder` option.
|
|
5720
5844
|
*
|
|
5845
|
+
* Uses the same precision-preserving temporal display, nested stringification,
|
|
5846
|
+
* numeric coloring, and `charsToLog` truncation as `log()`. Unsafe top-level
|
|
5847
|
+
* large integers throw, just as with `getData()`.
|
|
5848
|
+
*
|
|
5721
5849
|
* @param count - The number of rows to log from the bottom of the table. Defaults to the table's `rowsToLog` option if not specified.
|
|
5722
5850
|
* @param options - An optional object with logging preferences.
|
|
5723
5851
|
* @param options.originalOrder - If true, the rows are displayed in their original order (top to bottom). Defaults to false.
|
|
@@ -5743,10 +5871,7 @@ class SimpleTable extends Simple_js_1.default {
|
|
|
5743
5871
|
* ```
|
|
5744
5872
|
*/
|
|
5745
5873
|
async logBottom(count, options = {}) {
|
|
5746
|
-
|
|
5747
|
-
console.log(`\nTable ${this.name} (${rows} bottom rows):`);
|
|
5748
|
-
const data = await this.getBottom(rows, options);
|
|
5749
|
-
(0, logData_js_1.default)(null, data, this.charsToLog);
|
|
5874
|
+
await (0, logBottom_js_1.default)(this, count, options);
|
|
5750
5875
|
return this;
|
|
5751
5876
|
}
|
|
5752
5877
|
/**
|