@nshiab/simple-data-analysis-core 2.0.5 → 2.0.7
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 +271 -288
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +269 -340
- 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/addColumn.d.ts +1 -1
- package/esm/methods/addColumn.d.ts.map +1 -1
- package/esm/methods/bins.d.ts +1 -1
- package/esm/methods/bins.d.ts.map +1 -1
- package/esm/methods/bins.js +45 -29
- 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/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 +1 -1
- package/esm/methods/loadArray.d.ts.map +1 -1
- package/esm/methods/loadArray.js +74 -19
- package/esm/methods/loadData.js +3 -0
- package/esm/methods/log.d.ts +7 -0
- package/esm/methods/log.d.ts.map +1 -0
- package/esm/methods/log.js +63 -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/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 +365 -461
- 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 +271 -288
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +269 -340
- 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/addColumn.d.ts +1 -1
- package/script/methods/addColumn.d.ts.map +1 -1
- package/script/methods/bins.d.ts +1 -1
- package/script/methods/bins.d.ts.map +1 -1
- package/script/methods/bins.js +45 -29
- 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/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 +1 -1
- package/script/methods/loadArray.d.ts.map +1 -1
- package/script/methods/loadArray.js +74 -19
- package/script/methods/loadData.js +3 -0
- package/script/methods/log.d.ts +7 -0
- package/script/methods/log.d.ts.map +1 -0
- package/script/methods/log.js +69 -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/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
package/esm/class/SimpleTable.js
CHANGED
|
@@ -10,6 +10,8 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
12
|
var _SimpleTable_name;
|
|
13
|
+
import logBottom from "../methods/logBottom.js";
|
|
14
|
+
import log from "../methods/log.js";
|
|
13
15
|
import quoteIdentifier from "../helpers/quoteIdentifier.js";
|
|
14
16
|
import csvFormat from "../helpers/csvFormat.js";
|
|
15
17
|
import getDescription from "../methods/getDescription.js";
|
|
@@ -223,7 +225,7 @@ class SimpleTable extends Simple {
|
|
|
223
225
|
* @param simpleDB - The SimpleDB instance that this table belongs to.
|
|
224
226
|
* @param options - An optional object with configuration options:
|
|
225
227
|
* @param options.rowsToLog - The number of rows to log when displaying table data.
|
|
226
|
-
* @param options.charsToLog - The maximum
|
|
228
|
+
* @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
229
|
* @param options.typesToLog - A boolean indicating whether to include data types when logging a table.
|
|
228
230
|
* @category Constructor
|
|
229
231
|
*/
|
|
@@ -299,6 +301,7 @@ class SimpleTable extends Simple {
|
|
|
299
301
|
}
|
|
300
302
|
/**
|
|
301
303
|
* Renames the current table.
|
|
304
|
+
* The new name must not belong to another registered table, ignoring ASCII letter case.
|
|
302
305
|
*
|
|
303
306
|
* @param name - The new name for the table.
|
|
304
307
|
* @returns A promise that resolves to the renamed table.
|
|
@@ -320,9 +323,7 @@ class SimpleTable extends Simple {
|
|
|
320
323
|
* Sets the data types for columns in a new table. If the table already exists, it will be replaced.
|
|
321
324
|
* To convert the types of an existing table, use the `.convert()` method instead.
|
|
322
325
|
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* @param types - An object specifying the column names and their target data types (JavaScript or SQL types).
|
|
326
|
+
* @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
327
|
* @returns The table, so methods can be chained.
|
|
327
328
|
* @category Table Management
|
|
328
329
|
*
|
|
@@ -335,28 +336,43 @@ class SimpleTable extends Simple {
|
|
|
335
336
|
* raise: "float",
|
|
336
337
|
* }).log();
|
|
337
338
|
* ```
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* // Create an empty table with JSON, embedding, and geometry columns.
|
|
343
|
+
* await table.setTypes({
|
|
344
|
+
* details: "JSON",
|
|
345
|
+
* embedding: "FLOAT[3]",
|
|
346
|
+
* geom: "GEOMETRY('EPSG:4326')",
|
|
347
|
+
* }).log();
|
|
348
|
+
* ```
|
|
338
349
|
*/
|
|
339
350
|
setTypes(types) {
|
|
340
351
|
setTypes(this, types);
|
|
341
352
|
return this;
|
|
342
353
|
}
|
|
343
354
|
/**
|
|
344
|
-
* Loads an array of JavaScript objects into the table. Types
|
|
355
|
+
* Loads an array of JavaScript objects into the table. Types are inferred for
|
|
356
|
+
* numbers, bigints, strings, booleans, and Date values. Array and object cells
|
|
357
|
+
* require an explicit supported type in columnTypes. Types can also be
|
|
358
|
+
* specified for scalar columns instead of inferred from their values.
|
|
345
359
|
*
|
|
346
360
|
* JavaScript `Date` values are inferred as DuckDB `TIMESTAMP` values. Their
|
|
347
361
|
* instant is preserved, but JavaScript `Date` does not retain the timezone or
|
|
348
|
-
* offset originally used to construct it.
|
|
349
|
-
*
|
|
362
|
+
* offset originally used to construct it.
|
|
363
|
+
*
|
|
364
|
+
* Declare `JSON` for general nested data, `FLOAT[n]` for a fixed-size float
|
|
365
|
+
* vector, or `GEOMETRY('EPSG:4326')` for GeoJSON geometries in WGS84.
|
|
350
366
|
*
|
|
351
367
|
* @param rows - An array of objects, where each object represents a row and its properties represent columns.
|
|
352
368
|
* @param options - Options for loading the array, captured when called.
|
|
353
|
-
* @param options.columnTypes - Types for specific columns; omitted columns are inferred. Values must be compatible with the selected type without losing information.
|
|
369
|
+
* @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.
|
|
354
370
|
* @returns The table, so methods can be chained.
|
|
355
371
|
* @category Importing Data
|
|
356
372
|
*
|
|
357
373
|
* @example
|
|
358
374
|
* ```ts
|
|
359
|
-
* // Load
|
|
375
|
+
* // Load scalar columns without columnTypes; strings and numbers are inferred.
|
|
360
376
|
* const data = [
|
|
361
377
|
* { letter: "a", number: 1 },
|
|
362
378
|
* { letter: "b", number: 2 }
|
|
@@ -366,7 +382,7 @@ class SimpleTable extends Simple {
|
|
|
366
382
|
*
|
|
367
383
|
* @example
|
|
368
384
|
* ```ts
|
|
369
|
-
* //
|
|
385
|
+
* // Choose a numeric type when all-null values provide nothing to infer.
|
|
370
386
|
* await table.loadArray(
|
|
371
387
|
* [{ name: "A", value: null }, { name: "B", value: null }],
|
|
372
388
|
* { columnTypes: { value: "DOUBLE" } },
|
|
@@ -375,12 +391,39 @@ class SimpleTable extends Simple {
|
|
|
375
391
|
*
|
|
376
392
|
* @example
|
|
377
393
|
* ```ts
|
|
378
|
-
* //
|
|
379
|
-
* //
|
|
394
|
+
* // Store the Date as a UTC timestamp with JavaScript's millisecond precision.
|
|
395
|
+
* // The original -04:00 offset is not retained.
|
|
380
396
|
* await table.loadArray([{
|
|
381
397
|
* observedAt: new Date("2024-04-07T13:00:00-04:00"),
|
|
382
398
|
* }]).log();
|
|
383
399
|
* ```
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* ```ts
|
|
403
|
+
* // Declare JSON to load nested objects and variable-length arrays directly.
|
|
404
|
+
* await table.loadArray([{
|
|
405
|
+
* name: "Station",
|
|
406
|
+
* metadata: { active: true, tags: ["weather", "urban"] },
|
|
407
|
+
* measurements: [1, 2.5, null],
|
|
408
|
+
* }], { columnTypes: { metadata: "JSON", measurements: "JSON" } }).log();
|
|
409
|
+
* ```
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```ts
|
|
413
|
+
* // Declare FLOAT[3] to store each three-element array as a fixed-size vector.
|
|
414
|
+
* await table.loadArray([{ vector: [1, 2, 3] }], {
|
|
415
|
+
* columnTypes: { vector: "FLOAT[3]" },
|
|
416
|
+
* }).log();
|
|
417
|
+
* ```
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```ts
|
|
421
|
+
* // Declare a geometry type to store WGS84 GeoJSON as a spatial column.
|
|
422
|
+
* await table.loadArray([{
|
|
423
|
+
* name: "Montreal",
|
|
424
|
+
* geom: { type: "Point", coordinates: [-73.57, 45.50] },
|
|
425
|
+
* }], { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } }).log();
|
|
426
|
+
* ```
|
|
384
427
|
*/
|
|
385
428
|
loadArray(rows, options = {}) {
|
|
386
429
|
loadArray(this, rows, options);
|
|
@@ -389,17 +432,18 @@ class SimpleTable extends Simple {
|
|
|
389
432
|
/**
|
|
390
433
|
* Loads data from one or more local or remote files into the table.
|
|
391
434
|
* Supported file formats include CSV, JSON, Parquet, and Excel.
|
|
392
|
-
*
|
|
435
|
+
*
|
|
436
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
393
437
|
*
|
|
394
438
|
* @param files - The path(s) or URL(s) of the file(s) containing the data to be loaded.
|
|
395
439
|
* @param options - An optional object with configuration options:
|
|
396
440
|
* @param options.fileType - The type of file to load ("csv", "dsv", "json", "parquet", "excel"). Defaults to being inferred from the file extension.
|
|
397
441
|
* @param options.autoDetect - A boolean indicating whether to automatically detect the data format. Defaults to `true`.
|
|
398
|
-
* @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before applying `limit`.
|
|
442
|
+
* @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`.
|
|
399
443
|
* @param options.limit - A number indicating the maximum number of matching rows to load, after applying `conditions` if provided. Defaults to all matching rows.
|
|
400
444
|
* @param options.includeFilename - A boolean indicating whether to include the filename as a new column in the loaded data. Defaults to `false`.
|
|
401
445
|
* @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`.
|
|
402
|
-
* @param options.columnTypes - An object mapping column names to their expected data types. By default, types are inferred.
|
|
446
|
+
* @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.
|
|
403
447
|
* @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.
|
|
404
448
|
* @param options.header - A boolean indicating whether the file has a header row. Applicable to CSV files. Defaults to `true`.
|
|
405
449
|
* @param options.allText - A boolean indicating whether all columns should be treated as text. Applicable to CSV files. Defaults to `false`.
|
|
@@ -476,8 +520,6 @@ class SimpleTable extends Simple {
|
|
|
476
520
|
}
|
|
477
521
|
/**
|
|
478
522
|
* Downloads a complete Statistics Canada table and loads it into this table.
|
|
479
|
-
* The method queues the download and load; they run when an async observer
|
|
480
|
-
* method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
481
523
|
*
|
|
482
524
|
* Results are cached as Parquet files in `.sda-cache/statcan` by default.
|
|
483
525
|
* Cached data does not expire unless a TTL is provided.
|
|
@@ -531,9 +573,6 @@ class SimpleTable extends Simple {
|
|
|
531
573
|
* research, and journalistic purposes. Before using it, review Yahoo's terms
|
|
532
574
|
* and any applicable data-provider restrictions.
|
|
533
575
|
*
|
|
534
|
-
* The method queues the download and load; they run when an async observer
|
|
535
|
-
* method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
536
|
-
*
|
|
537
576
|
* @param symbol - The stock or index symbol, such as `"AAPL"` or `"^GSPTSE"`.
|
|
538
577
|
* @param startDate - The inclusive UTC start of the requested range.
|
|
539
578
|
* @param endDate - The inclusive UTC end of the requested range. The UTC day,
|
|
@@ -580,14 +619,13 @@ class SimpleTable extends Simple {
|
|
|
580
619
|
}
|
|
581
620
|
/**
|
|
582
621
|
* Loads geospatial data from an external file or URL into the table.
|
|
583
|
-
*
|
|
584
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
622
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
585
623
|
*
|
|
586
624
|
* @param file - The path or URL of the external file containing the geospatial data.
|
|
587
625
|
* @param options - An optional object with configuration options:
|
|
588
626
|
* @param options.toEPSG4326 - If `true`, the method will attempt to reproject the data to EPSG:4326 (WGS84).
|
|
589
627
|
* @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.
|
|
590
|
-
* @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before materialization and reprojection.
|
|
628
|
+
* @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.
|
|
591
629
|
* @returns The table, so methods can be chained.
|
|
592
630
|
* @category Geospatial
|
|
593
631
|
*
|
|
@@ -641,7 +679,7 @@ class SimpleTable extends Simple {
|
|
|
641
679
|
return this;
|
|
642
680
|
}
|
|
643
681
|
/**
|
|
644
|
-
* 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.
|
|
682
|
+
* 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.
|
|
645
683
|
*
|
|
646
684
|
* 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.
|
|
647
685
|
*
|
|
@@ -728,8 +766,6 @@ class SimpleTable extends Simple {
|
|
|
728
766
|
* DuckDB FTS indexes do not update automatically when the table changes; use
|
|
729
767
|
* `overwrite: true` to rebuild the index after modifying the table.
|
|
730
768
|
*
|
|
731
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
732
|
-
*
|
|
733
769
|
* @param idColumn - The column containing the document identifiers.
|
|
734
770
|
* @param textColumn - The column containing the text to search.
|
|
735
771
|
* @param options - An optional object with configuration options:
|
|
@@ -788,8 +824,6 @@ class SimpleTable extends Simple {
|
|
|
788
824
|
* 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`.
|
|
789
825
|
* The index definition is recorded in {@link indexes}.
|
|
790
826
|
*
|
|
791
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
792
|
-
*
|
|
793
827
|
* @param column - The name of the column containing vector embeddings (must be FLOAT array type).
|
|
794
828
|
* @param options - An optional object with configuration options:
|
|
795
829
|
* @param options.overwrite - If `true`, drops and recreates the index even if it already exists. Defaults to `false`.
|
|
@@ -850,8 +884,6 @@ class SimpleTable extends Simple {
|
|
|
850
884
|
* changes; use `overwriteIndex: true` to rebuild the index after modifying
|
|
851
885
|
* the table.
|
|
852
886
|
*
|
|
853
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
854
|
-
*
|
|
855
887
|
* @param text - The search query text to match against the text column.
|
|
856
888
|
* @param idColumn - The name of the column containing unique identifiers for each row.
|
|
857
889
|
* @param textColumn - The name of the column containing the text to search.
|
|
@@ -953,8 +985,6 @@ class SimpleTable extends Simple {
|
|
|
953
985
|
/**
|
|
954
986
|
* Inserts rows, provided as an array of JavaScript objects, into the table.
|
|
955
987
|
*
|
|
956
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
957
|
-
*
|
|
958
988
|
* @param rows - An array of objects, where each object represents a row to be inserted and its properties correspond to column names.
|
|
959
989
|
* @returns The table, so methods can be chained.
|
|
960
990
|
* @category Importing Data
|
|
@@ -974,7 +1004,7 @@ class SimpleTable extends Simple {
|
|
|
974
1004
|
return this;
|
|
975
1005
|
}
|
|
976
1006
|
/**
|
|
977
|
-
* 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`.
|
|
1007
|
+
* 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`.
|
|
978
1008
|
*
|
|
979
1009
|
* @param tables - The name(s) of the table(s) or SimpleTable instance(s) from which rows will be inserted.
|
|
980
1010
|
* @param options - An optional object with configuration options:
|
|
@@ -1007,8 +1037,6 @@ class SimpleTable extends Simple {
|
|
|
1007
1037
|
/**
|
|
1008
1038
|
* Fetches sample data from the simple-data-analysis-core GitHub repository.
|
|
1009
1039
|
*
|
|
1010
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1011
|
-
*
|
|
1012
1040
|
* @param sample - The name of the sample to load.
|
|
1013
1041
|
*
|
|
1014
1042
|
* Tabular data:
|
|
@@ -1034,13 +1062,12 @@ class SimpleTable extends Simple {
|
|
|
1034
1062
|
}
|
|
1035
1063
|
/**
|
|
1036
1064
|
* 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.
|
|
1065
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
1037
1066
|
*
|
|
1038
1067
|
* If `conditions`, `limit`, and `offset` are all used, they are applied in this order: `conditions` (WHERE clause) first, then `offset`, and finally `limit` (LIMIT).
|
|
1039
1068
|
*
|
|
1040
1069
|
* Note that cloning large tables can be a slow operation.
|
|
1041
1070
|
*
|
|
1042
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1043
|
-
*
|
|
1044
1071
|
* @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.
|
|
1045
1072
|
* @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.
|
|
1046
1073
|
* @param nameOrOptions.conditions - A SQL `WHERE` clause condition to filter the data during cloning. Defaults to no condition (clones all rows).
|
|
@@ -1109,8 +1136,6 @@ class SimpleTable extends Simple {
|
|
|
1109
1136
|
/**
|
|
1110
1137
|
* Clones an existing column in this table, creating a new column with identical values.
|
|
1111
1138
|
*
|
|
1112
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1113
|
-
*
|
|
1114
1139
|
* @param column - The name of the original column to clone.
|
|
1115
1140
|
* @param newColumn - The name of the new column to be created.
|
|
1116
1141
|
* @returns The table, so methods can be chained.
|
|
@@ -1132,8 +1157,6 @@ class SimpleTable extends Simple {
|
|
|
1132
1157
|
*
|
|
1133
1158
|
* **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.
|
|
1134
1159
|
*
|
|
1135
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1136
|
-
*
|
|
1137
1160
|
* @param column - The name of the original column.
|
|
1138
1161
|
* @param newColumn - The name of the new column to be created with offset values.
|
|
1139
1162
|
* @param options - An optional object with configuration options:
|
|
@@ -1179,8 +1202,6 @@ class SimpleTable extends Simple {
|
|
|
1179
1202
|
/**
|
|
1180
1203
|
* 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`.
|
|
1181
1204
|
*
|
|
1182
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1183
|
-
*
|
|
1184
1205
|
* @param columns - The column(s) for which to fill `NULL` values.
|
|
1185
1206
|
* @param options - An optional object with configuration options:
|
|
1186
1207
|
* @param options.by - A column name or an array of column names to partition by. The fill is applied independently within each group.
|
|
@@ -1239,7 +1260,7 @@ class SimpleTable extends Simple {
|
|
|
1239
1260
|
* Sorts the rows of the table based on specified column(s) and order(s).
|
|
1240
1261
|
* If no columns are specified, all columns are sorted from left to right in ascending order.
|
|
1241
1262
|
*
|
|
1242
|
-
*
|
|
1263
|
+
* 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.
|
|
1243
1264
|
*
|
|
1244
1265
|
* @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.
|
|
1245
1266
|
* @param options - An optional object with configuration options:
|
|
@@ -1276,7 +1297,7 @@ class SimpleTable extends Simple {
|
|
|
1276
1297
|
return this;
|
|
1277
1298
|
}
|
|
1278
1299
|
/**
|
|
1279
|
-
* Selects specific columns in the table, removing all others.
|
|
1300
|
+
* Selects specific columns in the table, removing all others.
|
|
1280
1301
|
*
|
|
1281
1302
|
* @param columns - The name or an array of names of the columns to be selected.
|
|
1282
1303
|
* @returns The table, so methods can be chained.
|
|
@@ -1301,8 +1322,6 @@ class SimpleTable extends Simple {
|
|
|
1301
1322
|
/**
|
|
1302
1323
|
* Skips the first `n` rows of the table, effectively removing them.
|
|
1303
1324
|
*
|
|
1304
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1305
|
-
*
|
|
1306
1325
|
* @param count - The number of rows to skip from the beginning of the table.
|
|
1307
1326
|
* @returns The table, so methods can be chained.
|
|
1308
1327
|
* @category Selecting or Filtering Data
|
|
@@ -1338,8 +1357,6 @@ class SimpleTable extends Simple {
|
|
|
1338
1357
|
/**
|
|
1339
1358
|
* Selects random rows from the table, removing all others. You can optionally specify a seed to ensure repeatable sampling.
|
|
1340
1359
|
*
|
|
1341
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1342
|
-
*
|
|
1343
1360
|
* @param count - The number of rows to select (e.g., `100`) or a percentage string (e.g., `"10%"`) specifying the sampling size.
|
|
1344
1361
|
* @param options - An optional object with configuration options:
|
|
1345
1362
|
* @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.
|
|
@@ -1371,8 +1388,6 @@ class SimpleTable extends Simple {
|
|
|
1371
1388
|
/**
|
|
1372
1389
|
* 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.
|
|
1373
1390
|
*
|
|
1374
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1375
|
-
*
|
|
1376
1391
|
* @param count - The number of rows to select.
|
|
1377
1392
|
* @param options - An optional object with configuration options:
|
|
1378
1393
|
* @param options.offset - The number of rows to skip from the beginning of the table before selecting. Defaults to `0`.
|
|
@@ -1411,8 +1426,6 @@ class SimpleTable extends Simple {
|
|
|
1411
1426
|
* Removes duplicate rows from this table, keeping only unique rows.
|
|
1412
1427
|
* Note that the resulting data order might differ from the original.
|
|
1413
1428
|
*
|
|
1414
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1415
|
-
*
|
|
1416
1429
|
* @param options - An optional object with configuration options:
|
|
1417
1430
|
* @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.
|
|
1418
1431
|
* @returns The table, so methods can be chained.
|
|
@@ -1443,7 +1456,6 @@ class SimpleTable extends Simple {
|
|
|
1443
1456
|
/**
|
|
1444
1457
|
* Removes rows with missing values from this table.
|
|
1445
1458
|
* By default, missing values include SQL `NULL`, as well as string representations like `"NULL"`, `"null"`, `"NaN"`, `"undefined"`, and empty strings `""`.
|
|
1446
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1447
1459
|
*
|
|
1448
1460
|
* @param options - An optional object with configuration options:
|
|
1449
1461
|
* @param options.columns - A string or an array of strings specifying the columns to consider for missing values. If omitted, all columns are considered.
|
|
@@ -1481,7 +1493,7 @@ class SimpleTable extends Simple {
|
|
|
1481
1493
|
return this;
|
|
1482
1494
|
}
|
|
1483
1495
|
/**
|
|
1484
|
-
* Trims specified characters from the beginning, end, or both sides of string values in the given columns.
|
|
1496
|
+
* Trims specified characters from the beginning, end, or both sides of string values in the given columns.
|
|
1485
1497
|
*
|
|
1486
1498
|
* @param columns - The column name or an array of column names to trim.
|
|
1487
1499
|
* @param options - An optional object with configuration options:
|
|
@@ -1514,8 +1526,7 @@ class SimpleTable extends Simple {
|
|
|
1514
1526
|
}
|
|
1515
1527
|
/**
|
|
1516
1528
|
* Filters rows from this table based on SQL conditions. Note that it's often faster to use the `removeRows` method for simple removals.
|
|
1517
|
-
*
|
|
1518
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1529
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
1519
1530
|
*
|
|
1520
1531
|
* @param conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"column1 > 10 AND column2 = 'value'"`).
|
|
1521
1532
|
* @returns The table, so methods can be chained.
|
|
@@ -1552,8 +1563,6 @@ class SimpleTable extends Simple {
|
|
|
1552
1563
|
/**
|
|
1553
1564
|
* Keeps rows in this table that have specific values in specified columns, removing all other rows.
|
|
1554
1565
|
*
|
|
1555
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1556
|
-
*
|
|
1557
1566
|
* @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`.
|
|
1558
1567
|
* @returns The table, so methods can be chained.
|
|
1559
1568
|
* @category Selecting or Filtering Data
|
|
@@ -1583,8 +1592,6 @@ class SimpleTable extends Simple {
|
|
|
1583
1592
|
/**
|
|
1584
1593
|
* Removes rows from this table that have specific values in specified columns.
|
|
1585
1594
|
*
|
|
1586
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1587
|
-
*
|
|
1588
1595
|
* @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.
|
|
1589
1596
|
* @returns The table, so methods can be chained.
|
|
1590
1597
|
* @category Selecting or Filtering Data
|
|
@@ -1613,9 +1620,7 @@ class SimpleTable extends Simple {
|
|
|
1613
1620
|
}
|
|
1614
1621
|
/**
|
|
1615
1622
|
* Removes rows from this table based on SQL conditions. This method is similar to `filter()`, but removes rows instead of keeping them.
|
|
1616
|
-
*
|
|
1617
|
-
*
|
|
1618
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1623
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
1619
1624
|
*
|
|
1620
1625
|
* @param conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"fruit = 'apple'"`).
|
|
1621
1626
|
* @returns The table, so methods can be chained.
|
|
@@ -1653,8 +1658,6 @@ class SimpleTable extends Simple {
|
|
|
1653
1658
|
* Renames one or more columns in the table. Throws if a source column does
|
|
1654
1659
|
* not exist, so a typo fails loudly instead of being silently ignored.
|
|
1655
1660
|
*
|
|
1656
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1657
|
-
*
|
|
1658
1661
|
* @param names - An object mapping old column names to their new column names (e.g., `{ "oldName": "newName", "anotherOld": "anotherNew" }`).
|
|
1659
1662
|
* @param options - Configuration options.
|
|
1660
1663
|
* @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.
|
|
@@ -1686,8 +1689,6 @@ class SimpleTable extends Simple {
|
|
|
1686
1689
|
/**
|
|
1687
1690
|
* Cleans column names by removing non-alphanumeric characters and formatting them to camel case.
|
|
1688
1691
|
*
|
|
1689
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1690
|
-
*
|
|
1691
1692
|
* @returns The table, so methods can be chained.
|
|
1692
1693
|
* @category Column Operations
|
|
1693
1694
|
*
|
|
@@ -1740,8 +1741,6 @@ class SimpleTable extends Simple {
|
|
|
1740
1741
|
* | Sales | 2022 | 75 |
|
|
1741
1742
|
* | Sales | 2023 | 98 |
|
|
1742
1743
|
*
|
|
1743
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1744
|
-
*
|
|
1745
1744
|
* @param columns - An array of strings representing the names of the columns to be stacked (unpivoted).
|
|
1746
1745
|
* @param namesTo - The name of the new column that will contain the original column names (e.g., "Year").
|
|
1747
1746
|
* @param valuesTo - The name of the new column that will contain the values from the stacked columns (e.g., "Employees").
|
|
@@ -1783,8 +1782,6 @@ class SimpleTable extends Simple {
|
|
|
1783
1782
|
*
|
|
1784
1783
|
* When multiple rows share the same `namesFrom`/grouping combination, their `valuesFrom` values are combined with the `options.stat` function (`"sum"` by default).
|
|
1785
1784
|
*
|
|
1786
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1787
|
-
*
|
|
1788
1785
|
* @param namesFrom - The name of the column containing the values that will be transformed into new column headers (e.g., "Year").
|
|
1789
1786
|
* @param valuesFrom - The name of the column containing the values to be spread across the new columns (e.g., "Employees").
|
|
1790
1787
|
* @param options - An optional object with configuration options:
|
|
@@ -1809,9 +1806,7 @@ class SimpleTable extends Simple {
|
|
|
1809
1806
|
*
|
|
1810
1807
|
* When converting strings to numbers, commas (often used as thousand separators) will be automatically removed before conversion.
|
|
1811
1808
|
*
|
|
1812
|
-
*
|
|
1813
|
-
*
|
|
1814
|
-
* @param types - An object mapping column names to their target data types for conversion.
|
|
1809
|
+
* @param types - An object mapping column names to their target data types for conversion, including JSON, FLOAT[n] vectors, and GEOMETRY with a CRS.
|
|
1815
1810
|
* @param options - An optional object with configuration options:
|
|
1816
1811
|
* @param options.strict - If `false`, values that cannot be converted will be replaced by `NULL` instead of throwing an error. Defaults to `true`.
|
|
1817
1812
|
* @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).
|
|
@@ -1858,6 +1853,18 @@ class SimpleTable extends Simple {
|
|
|
1858
1853
|
* // Convert 'amount' to float, replacing unconvertible values with NULL
|
|
1859
1854
|
* await table.convert({ amount: "float" }, { strict: false }).log();
|
|
1860
1855
|
* ```
|
|
1856
|
+
*
|
|
1857
|
+
* @example
|
|
1858
|
+
* ```ts
|
|
1859
|
+
* // Parse JSON, a fixed-size float vector, and WKT geometry from text.
|
|
1860
|
+
* await table.loadArray([{
|
|
1861
|
+
* details: '{"count":3}',
|
|
1862
|
+
* embedding: "[0.25,0.5,0.75]",
|
|
1863
|
+
* geom: "POINT (-73 45)",
|
|
1864
|
+
* }])
|
|
1865
|
+
* .convert({ details: "JSON", embedding: "FLOAT[3]", geom: "GEOMETRY('EPSG:4326')" })
|
|
1866
|
+
* .log();
|
|
1867
|
+
* ```
|
|
1861
1868
|
*/
|
|
1862
1869
|
convert(types, options = {}) {
|
|
1863
1870
|
convert(this, types, options);
|
|
@@ -1880,7 +1887,7 @@ class SimpleTable extends Simple {
|
|
|
1880
1887
|
return this;
|
|
1881
1888
|
}
|
|
1882
1889
|
/**
|
|
1883
|
-
* Removes one or more columns from this table.
|
|
1890
|
+
* Removes one or more columns from this table.
|
|
1884
1891
|
*
|
|
1885
1892
|
* @param columns - The name or an array of names of the columns to be removed.
|
|
1886
1893
|
* @returns The table, so methods can be chained.
|
|
@@ -1903,10 +1910,11 @@ class SimpleTable extends Simple {
|
|
|
1903
1910
|
return this;
|
|
1904
1911
|
}
|
|
1905
1912
|
/**
|
|
1906
|
-
* Adds a new column to the table based on a specified data type (JavaScript or SQL types) and a SQL definition.
|
|
1913
|
+
* Adds a new column to the table based on a specified data type (JavaScript or SQL types) and a SQL definition.
|
|
1914
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, expressions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
1907
1915
|
*
|
|
1908
1916
|
* @param newColumn - The name of the new column to be added.
|
|
1909
|
-
* @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"`).
|
|
1917
|
+
* @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')"`).
|
|
1910
1918
|
* @param definition - A SQL expression defining how the values for the new column should be computed (e.g., `"column1 + column2"`, `"ST_Centroid(geom_column)"`).
|
|
1911
1919
|
* @returns The table, so methods can be chained.
|
|
1912
1920
|
* @category Column Operations
|
|
@@ -1922,6 +1930,25 @@ class SimpleTable extends Simple {
|
|
|
1922
1930
|
* // Add a new geometry column 'centroid' using the centroid of an existing 'country' geometry column
|
|
1923
1931
|
* await table.addColumn("centroid", "geometry('EPSG:4326')", `ST_Centroid("country")`).log();
|
|
1924
1932
|
* ```
|
|
1933
|
+
*
|
|
1934
|
+
* @example
|
|
1935
|
+
* ```ts
|
|
1936
|
+
* // Read a number from a JSON object into a new column using dot notation.
|
|
1937
|
+
* await table.loadArray([{ details: { count: 3 } }], {
|
|
1938
|
+
* columnTypes: { details: "JSON" },
|
|
1939
|
+
* })
|
|
1940
|
+
* .addColumn("count", "integer", "details.count")
|
|
1941
|
+
* .log();
|
|
1942
|
+
* ```
|
|
1943
|
+
*
|
|
1944
|
+
* @example
|
|
1945
|
+
* ```ts
|
|
1946
|
+
* // Create JSON and fixed-size vector columns with DuckDB expressions.
|
|
1947
|
+
* await table.loadArray([{ count: 3 }])
|
|
1948
|
+
* .addColumn("details", "JSON", "json_object('count', count)")
|
|
1949
|
+
* .addColumn("embedding", "FLOAT[3]", "[0.25, 0.5, 0.75]")
|
|
1950
|
+
* .log();
|
|
1951
|
+
* ```
|
|
1925
1952
|
*/
|
|
1926
1953
|
addColumn(newColumn, type, definition) {
|
|
1927
1954
|
addColumn(this, newColumn, type, definition);
|
|
@@ -1941,9 +1968,6 @@ class SimpleTable extends Simple {
|
|
|
1941
1968
|
* values produce `NULL` extracted values. Parts extracted from
|
|
1942
1969
|
* `TIMESTAMP WITH TIME ZONE` values use UTC.
|
|
1943
1970
|
*
|
|
1944
|
-
* This method queues the operation; it runs when an async observer method
|
|
1945
|
-
* (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1946
|
-
*
|
|
1947
1971
|
* @param column - The temporal column from which to extract components.
|
|
1948
1972
|
* @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.
|
|
1949
1973
|
* @returns The table, so methods can be chained.
|
|
@@ -1971,8 +1995,6 @@ class SimpleTable extends Simple {
|
|
|
1971
1995
|
/**
|
|
1972
1996
|
* Adds a new column to the table containing the row number, starting at 0 (like an index).
|
|
1973
1997
|
*
|
|
1974
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1975
|
-
*
|
|
1976
1998
|
* @param newColumn - The name of the new column that will store the row number.
|
|
1977
1999
|
* @param options - An optional object with configuration options:
|
|
1978
2000
|
* @param options.by - A column name or an array of column names to partition by. The row number restarts at 0 within each group.
|
|
@@ -1999,8 +2021,6 @@ class SimpleTable extends Simple {
|
|
|
1999
2021
|
* 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.
|
|
2000
2022
|
* This means that if the left table has `n` rows and the right table has `m` rows, the result will have `n * m` rows.
|
|
2001
2023
|
*
|
|
2002
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2003
|
-
*
|
|
2004
2024
|
* @param rightTable - The SimpleTable instance to cross join with.
|
|
2005
2025
|
* @param options - An optional object with configuration options:
|
|
2006
2026
|
* @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`.
|
|
@@ -2032,7 +2052,6 @@ class SimpleTable extends Simple {
|
|
|
2032
2052
|
* Merges the data of this table (considered the left table) with another table (the right table) based on a common column or multiple columns.
|
|
2033
2053
|
* Note that the order of rows in the returned data is not guaranteed to be the same as in the original tables.
|
|
2034
2054
|
* This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
|
|
2035
|
-
* 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.
|
|
2036
2055
|
*
|
|
2037
2056
|
* @param rightTable - The SimpleTable instance to be joined with this table.
|
|
2038
2057
|
* @param options - An optional object with configuration options:
|
|
@@ -2080,8 +2099,6 @@ class SimpleTable extends Simple {
|
|
|
2080
2099
|
*
|
|
2081
2100
|
* This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
|
|
2082
2101
|
*
|
|
2083
|
-
* 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.
|
|
2084
|
-
*
|
|
2085
2102
|
* @param rightTable - The SimpleTable instance to be joined with this table.
|
|
2086
2103
|
* @param leftColumn - The name of the column in this (left) table containing the text to compare.
|
|
2087
2104
|
* @param rightColumn - The name of the column in the right table containing the text to compare.
|
|
@@ -2148,8 +2165,6 @@ class SimpleTable extends Simple {
|
|
|
2148
2165
|
* Similarity is computed using the [rapidfuzz](https://query.farm/duckdb_extension_rapidfuzz) DuckDB community extension,
|
|
2149
2166
|
* which is installed and loaded automatically.
|
|
2150
2167
|
*
|
|
2151
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2152
|
-
*
|
|
2153
2168
|
* @param column - The name of the column containing the strings to normalize.
|
|
2154
2169
|
* @param newColumn - The name of the column to write the normalized values to. Use the same name as `column` to normalize in-place.
|
|
2155
2170
|
* @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.
|
|
@@ -2203,8 +2218,6 @@ class SimpleTable extends Simple {
|
|
|
2203
2218
|
/**
|
|
2204
2219
|
* Replaces specified strings in the selected columns.
|
|
2205
2220
|
*
|
|
2206
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2207
|
-
*
|
|
2208
2221
|
* @param columns - The column name, an array of column names, or `"all"` to apply the replacement to every column in the table.
|
|
2209
2222
|
* @param replacements - An object mapping old strings to new strings (e.g., `{ "oldValue": "newValue" }`).
|
|
2210
2223
|
* @param options - An optional object with configuration options:
|
|
@@ -2248,7 +2261,7 @@ class SimpleTable extends Simple {
|
|
|
2248
2261
|
return this;
|
|
2249
2262
|
}
|
|
2250
2263
|
/**
|
|
2251
|
-
* Converts string values in the specified columns to lowercase.
|
|
2264
|
+
* Converts string values in the specified columns to lowercase.
|
|
2252
2265
|
*
|
|
2253
2266
|
* @param columns - The column name or an array of column names to be converted to lowercase.
|
|
2254
2267
|
* @returns The table, so methods can be chained.
|
|
@@ -2271,7 +2284,7 @@ class SimpleTable extends Simple {
|
|
|
2271
2284
|
return this;
|
|
2272
2285
|
}
|
|
2273
2286
|
/**
|
|
2274
|
-
* Converts string values in the specified columns to uppercase.
|
|
2287
|
+
* Converts string values in the specified columns to uppercase.
|
|
2275
2288
|
*
|
|
2276
2289
|
* @param columns - The column name or an array of column names to be converted to uppercase.
|
|
2277
2290
|
* @returns The table, so methods can be chained.
|
|
@@ -2294,7 +2307,7 @@ class SimpleTable extends Simple {
|
|
|
2294
2307
|
return this;
|
|
2295
2308
|
}
|
|
2296
2309
|
/**
|
|
2297
|
-
* Capitalizes the first letter of each string in the specified columns and converts the rest of the string to lowercase.
|
|
2310
|
+
* Capitalizes the first letter of each string in the specified columns and converts the rest of the string to lowercase.
|
|
2298
2311
|
*
|
|
2299
2312
|
* @param columns - The column name or an array of column names to be capitalized.
|
|
2300
2313
|
* @returns The table, so methods can be chained.
|
|
@@ -2319,8 +2332,6 @@ class SimpleTable extends Simple {
|
|
|
2319
2332
|
/**
|
|
2320
2333
|
* Truncates string values in a specified column to a maximum number of characters.
|
|
2321
2334
|
*
|
|
2322
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2323
|
-
*
|
|
2324
2335
|
* @param column - The column name containing strings to be truncated.
|
|
2325
2336
|
* @param length - The maximum number of characters to keep.
|
|
2326
2337
|
* @returns The table, so methods can be chained.
|
|
@@ -2349,8 +2360,6 @@ class SimpleTable extends Simple {
|
|
|
2349
2360
|
* column is of a different type. `null` values remain `null`. If any string
|
|
2350
2361
|
* already exceeds the target length, an error is thrown (no silent truncation).
|
|
2351
2362
|
*
|
|
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
2363
|
* @param columns - The column name(s) containing strings to be padded.
|
|
2355
2364
|
* @param length - The target length of the padded strings.
|
|
2356
2365
|
* @param options - An optional object with configuration options:
|
|
@@ -2390,8 +2399,6 @@ class SimpleTable extends Simple {
|
|
|
2390
2399
|
* 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.
|
|
2391
2400
|
* If the index is out of bounds, an empty string will be returned for that row.
|
|
2392
2401
|
*
|
|
2393
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2394
|
-
*
|
|
2395
2402
|
* @param column - The name of the column containing the strings to be split.
|
|
2396
2403
|
* @param separator - The substring to use as a delimiter for splitting the strings.
|
|
2397
2404
|
* @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.
|
|
@@ -2424,8 +2431,6 @@ class SimpleTable extends Simple {
|
|
|
2424
2431
|
* 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`).
|
|
2425
2432
|
* If a row has more parts than the number of new columns, an error will be thrown unless `strict` is set to `false`.
|
|
2426
2433
|
*
|
|
2427
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2428
|
-
*
|
|
2429
2434
|
* @param column - The name of the column containing the strings to be split.
|
|
2430
2435
|
* @param separator - The substring to use as a delimiter for splitting the strings.
|
|
2431
2436
|
* @param newColumns - An array of column names for the extracted parts.
|
|
@@ -2461,8 +2466,6 @@ class SimpleTable extends Simple {
|
|
|
2461
2466
|
/**
|
|
2462
2467
|
* Extracts a specific number of characters from the beginning (left side) of string values in the specified column.
|
|
2463
2468
|
*
|
|
2464
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2465
|
-
*
|
|
2466
2469
|
* @param column - The name of the column containing the strings to be modified.
|
|
2467
2470
|
* @param count - The number of characters to extract from the left side of each string.
|
|
2468
2471
|
* @returns The table, so methods can be chained.
|
|
@@ -2482,8 +2485,6 @@ class SimpleTable extends Simple {
|
|
|
2482
2485
|
/**
|
|
2483
2486
|
* Extracts a specific number of characters from the end (right side) of string values in the specified column.
|
|
2484
2487
|
*
|
|
2485
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2486
|
-
*
|
|
2487
2488
|
* @param column - The name of the column containing the strings to be modified.
|
|
2488
2489
|
* @param count - The number of characters to extract from the right side of each string.
|
|
2489
2490
|
* @returns The table, so methods can be chained.
|
|
@@ -2503,8 +2504,6 @@ class SimpleTable extends Simple {
|
|
|
2503
2504
|
/**
|
|
2504
2505
|
* Replaces `NULL` values in the specified columns with a given value.
|
|
2505
2506
|
*
|
|
2506
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2507
|
-
*
|
|
2508
2507
|
* @param columns - The column name, an array of column names, or `"all"` to apply the replacement to every column in the table.
|
|
2509
2508
|
* @param value - The value to replace `NULL` occurrences with.
|
|
2510
2509
|
* @returns The table, so methods can be chained.
|
|
@@ -2541,8 +2540,6 @@ class SimpleTable extends Simple {
|
|
|
2541
2540
|
/**
|
|
2542
2541
|
* Concatenates values from specified columns into a new column.
|
|
2543
2542
|
*
|
|
2544
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2545
|
-
*
|
|
2546
2543
|
* @param columns - An array of column names whose values will be concatenated.
|
|
2547
2544
|
* @param newColumn - The name of the new column to store the concatenated values.
|
|
2548
2545
|
* @param options - An optional object with configuration options:
|
|
@@ -2577,8 +2574,6 @@ class SimpleTable extends Simple {
|
|
|
2577
2574
|
*
|
|
2578
2575
|
* If a column value is `NULL`, it will be replaced by `'Unknown'` in the concatenated result.
|
|
2579
2576
|
*
|
|
2580
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2581
|
-
*
|
|
2582
2577
|
* @param columns - An array of column names whose values will be concatenated with labels.
|
|
2583
2578
|
* @param newColumn - The name of the new column to create with the concatenated values.
|
|
2584
2579
|
* @returns The table, so methods can be chained.
|
|
@@ -2626,8 +2621,6 @@ class SimpleTable extends Simple {
|
|
|
2626
2621
|
*
|
|
2627
2622
|
* 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.
|
|
2628
2623
|
*
|
|
2629
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2630
|
-
*
|
|
2631
2624
|
* @param column - The name of the column containing string values to be split and unnested.
|
|
2632
2625
|
* @param separator - The delimiter string used to split the column values.
|
|
2633
2626
|
* @returns The table, so methods can be chained.
|
|
@@ -2660,8 +2653,6 @@ class SimpleTable extends Simple {
|
|
|
2660
2653
|
*
|
|
2661
2654
|
* 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.
|
|
2662
2655
|
*
|
|
2663
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2664
|
-
*
|
|
2665
2656
|
* @param column - The name of the column containing the number of times each row should be repeated.
|
|
2666
2657
|
* @param options - An optional object with configuration options:
|
|
2667
2658
|
* @param options.index - The name of a new column to store the index of the repeated row (starting at 0).
|
|
@@ -2693,8 +2684,6 @@ class SimpleTable extends Simple {
|
|
|
2693
2684
|
*
|
|
2694
2685
|
* 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.
|
|
2695
2686
|
*
|
|
2696
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2697
|
-
*
|
|
2698
2687
|
* @param column - The name of the column whose values will be aggregated and concatenated.
|
|
2699
2688
|
* @param separator - The delimiter string used to join the column values.
|
|
2700
2689
|
* @param by - The column name or an array of column names to group by.
|
|
@@ -2727,8 +2716,6 @@ class SimpleTable extends Simple {
|
|
|
2727
2716
|
/**
|
|
2728
2717
|
* Rounds numeric values in specified columns.
|
|
2729
2718
|
*
|
|
2730
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2731
|
-
*
|
|
2732
2719
|
* @param columns - The column name or an array of column names containing numeric values to be rounded.
|
|
2733
2720
|
* @param options - An optional integer specifying the number of decimal places, or an object with configuration options:
|
|
2734
2721
|
* @param options.decimals - The number of decimal places to round to. Defaults to `0` (rounds to the nearest integer).
|
|
@@ -2774,8 +2761,6 @@ class SimpleTable extends Simple {
|
|
|
2774
2761
|
* Adds independently generated uniform random noise to numeric values in one or more columns.
|
|
2775
2762
|
* 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.
|
|
2776
2763
|
*
|
|
2777
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2778
|
-
*
|
|
2779
2764
|
* @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.
|
|
2780
2765
|
* @param max - The maximum absolute offset, expressed in each column's units. Must be a finite number greater than or equal to `0`.
|
|
2781
2766
|
* @param options - An optional object with configuration options:
|
|
@@ -2803,8 +2788,7 @@ class SimpleTable extends Simple {
|
|
|
2803
2788
|
}
|
|
2804
2789
|
/**
|
|
2805
2790
|
* Updates values in a specified column using a SQL expression.
|
|
2806
|
-
*
|
|
2807
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2791
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, expressions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
2808
2792
|
*
|
|
2809
2793
|
* @param column - The name of the column to be updated.
|
|
2810
2794
|
* @param definition - The SQL expression used to set the new values in the column (e.g., `"column1 * 2"`, `"UPPER(column_name)"`).
|
|
@@ -2828,6 +2812,16 @@ class SimpleTable extends Simple {
|
|
|
2828
2812
|
* // Set 'status' to 'active' where 'isActive' is true
|
|
2829
2813
|
* await table.updateColumn("status", `CASE WHEN isActive THEN 'active' ELSE 'inactive' END`).log();
|
|
2830
2814
|
* ```
|
|
2815
|
+
*
|
|
2816
|
+
* @example
|
|
2817
|
+
* ```ts
|
|
2818
|
+
* // Update an existing column with a value from a JSON object using dot notation.
|
|
2819
|
+
* await table.loadArray([{ count: 0, details: { count: 3 } }], {
|
|
2820
|
+
* columnTypes: { details: "JSON" },
|
|
2821
|
+
* })
|
|
2822
|
+
* .updateColumn("count", "details.count")
|
|
2823
|
+
* .log();
|
|
2824
|
+
* ```
|
|
2831
2825
|
*/
|
|
2832
2826
|
updateColumn(column, definition) {
|
|
2833
2827
|
updateColumn(this, column, definition);
|
|
@@ -2836,8 +2830,6 @@ class SimpleTable extends Simple {
|
|
|
2836
2830
|
/**
|
|
2837
2831
|
* Assigns ranks to rows in a new column based on the values of a specified column.
|
|
2838
2832
|
*
|
|
2839
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2840
|
-
*
|
|
2841
2833
|
* @param column - The column containing the values to be used for ranking.
|
|
2842
2834
|
* @param newColumn - The name of the new column where the ranks will be stored.
|
|
2843
2835
|
* @param options - An optional object with configuration options:
|
|
@@ -2878,8 +2870,6 @@ class SimpleTable extends Simple {
|
|
|
2878
2870
|
/**
|
|
2879
2871
|
* Assigns quantiles to rows in a new column based on specified column values.
|
|
2880
2872
|
*
|
|
2881
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2882
|
-
*
|
|
2883
2873
|
* @param column - The column containing values from which quantiles will be assigned.
|
|
2884
2874
|
* @param count - The number of quantiles to divide the data into (e.g., `4` for quartiles, `10` for deciles).
|
|
2885
2875
|
* @param newColumn - The name of the new column where the assigned quantiles will be stored.
|
|
@@ -2911,34 +2901,36 @@ class SimpleTable extends Simple {
|
|
|
2911
2901
|
return this;
|
|
2912
2902
|
}
|
|
2913
2903
|
/**
|
|
2914
|
-
*
|
|
2915
|
-
*
|
|
2916
|
-
*
|
|
2904
|
+
* Adds numeric start and end columns for bins of the specified interval size.
|
|
2905
|
+
* Each bin includes its start and excludes its end: `start <= value < end`.
|
|
2906
|
+
* A value exactly on an end boundary belongs to the next bin. Null source
|
|
2907
|
+
* values produce null in both output columns.
|
|
2917
2908
|
*
|
|
2918
|
-
* @param column - The column containing values from which bins will be computed.
|
|
2919
|
-
* @param interval - The interval size for binning the values.
|
|
2920
|
-
* @param
|
|
2909
|
+
* @param column - The numeric column containing values from which bins will be computed.
|
|
2910
|
+
* @param interval - The finite, positive interval size for binning the values.
|
|
2911
|
+
* @param startColumn - The required name of the new numeric column containing inclusive bin starts.
|
|
2912
|
+
* @param endColumn - The required name of the new numeric column containing exclusive bin ends. Must differ from startColumn.
|
|
2921
2913
|
* @param options - An optional object with configuration options:
|
|
2922
|
-
* @param options.startValue - The starting value for binning. Defaults to the minimum value in the specified column.
|
|
2914
|
+
* @param options.startValue - The finite starting value for binning, no greater than the minimum source value. Defaults to the minimum value in the specified column.
|
|
2923
2915
|
* @returns The table, so methods can be chained.
|
|
2924
2916
|
* @category Analyzing Data
|
|
2925
2917
|
*
|
|
2926
2918
|
* @example
|
|
2927
2919
|
* ```ts
|
|
2928
|
-
* //
|
|
2929
|
-
*
|
|
2930
|
-
* await table.bins("column1", 10, "bins").log();
|
|
2920
|
+
* // If the minimum is 5, bins have boundaries 5 and 15, 15 and 25, etc.
|
|
2921
|
+
* await table.bins("column1", 10, "binStart", "binEnd").log();
|
|
2931
2922
|
* ```
|
|
2932
2923
|
*
|
|
2933
2924
|
* @example
|
|
2934
2925
|
* ```ts
|
|
2935
|
-
* //
|
|
2936
|
-
*
|
|
2937
|
-
*
|
|
2926
|
+
* // Bins start at 0: a value of 10 has binStart 10 and binEnd 20.
|
|
2927
|
+
* await table
|
|
2928
|
+
* .bins("column1", 10, "binStart", "binEnd", { startValue: 0 })
|
|
2929
|
+
* .log();
|
|
2938
2930
|
* ```
|
|
2939
2931
|
*/
|
|
2940
|
-
bins(column, interval,
|
|
2941
|
-
bins(this, column, interval,
|
|
2932
|
+
bins(column, interval, startColumn, endColumn, options = {}) {
|
|
2933
|
+
bins(this, column, interval, startColumn, endColumn, options);
|
|
2942
2934
|
return this;
|
|
2943
2935
|
}
|
|
2944
2936
|
/**
|
|
@@ -2990,8 +2982,6 @@ class SimpleTable extends Simple {
|
|
|
2990
2982
|
* await table.rowProportions(["Men", "Women", "NonBinary"], { base: 100, decimals: 1 }).log();
|
|
2991
2983
|
* ```
|
|
2992
2984
|
*
|
|
2993
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2994
|
-
*
|
|
2995
2985
|
* @param columns - An array of column names for which proportions will be computed on each row.
|
|
2996
2986
|
* @param options - An optional object with configuration options:
|
|
2997
2987
|
* @param options.suffix - A string suffix to append to the names of the new columns storing the computed proportions. Defaults to `"Perc"`.
|
|
@@ -3015,9 +3005,6 @@ class SimpleTable extends Simple {
|
|
|
3015
3005
|
* option can therefore increase the table's row count. If null values leave
|
|
3016
3006
|
* a row without the requested rank, the new columns contain null.
|
|
3017
3007
|
*
|
|
3018
|
-
* This method queues the operation; it runs when an async observer method
|
|
3019
|
-
* (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3020
|
-
*
|
|
3021
3008
|
* @param columns - The numeric columns to rank within each row.
|
|
3022
3009
|
* @param options - The output columns and ranking configuration. At least one of `nameColumn` or `valueColumn` is required.
|
|
3023
3010
|
* @param options.nameColumn - The name of a new column containing the selected source column's name.
|
|
@@ -3054,8 +3041,6 @@ class SimpleTable extends Simple {
|
|
|
3054
3041
|
/**
|
|
3055
3042
|
* Computes proportions vertically over a column's values, relative to the sum of all values in that column or group.
|
|
3056
3043
|
*
|
|
3057
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3058
|
-
*
|
|
3059
3044
|
* @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.
|
|
3060
3045
|
* @param newColumn - The name of the new column where the proportions will be stored.
|
|
3061
3046
|
* @param options - An optional object with configuration options:
|
|
@@ -3097,8 +3082,6 @@ class SimpleTable extends Simple {
|
|
|
3097
3082
|
* Creates a summary table from selected columns, optionally grouped by other columns.
|
|
3098
3083
|
* This method allows you to aggregate data, calculate statistics (e.g., count, mean, sum), and group results by categorical columns.
|
|
3099
3084
|
*
|
|
3100
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3101
|
-
*
|
|
3102
3085
|
* @param options - An object with configuration options for summarization:
|
|
3103
3086
|
* @param options.columns - The column name or an array of column names to summarize. If omitted, only the row count is returned.
|
|
3104
3087
|
* @param options.by - The column name or an array of column names to group by.
|
|
@@ -3197,9 +3180,6 @@ class SimpleTable extends Simple {
|
|
|
3197
3180
|
* string is also used as its row label; pass an object to customize that
|
|
3198
3181
|
* label. If `options.stats` is omitted, every supported stat is added.
|
|
3199
3182
|
*
|
|
3200
|
-
* This method queues the operation; it runs when an async observer method
|
|
3201
|
-
* (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3202
|
-
*
|
|
3203
3183
|
* @param columns - The numeric column name, an array of numeric column names, or `"all"` to summarize every numeric column.
|
|
3204
3184
|
* @param labelColumn - The existing string column in which stat row labels will be written.
|
|
3205
3185
|
* @param options - An optional object with configuration options:
|
|
@@ -3241,8 +3221,6 @@ class SimpleTable extends Simple {
|
|
|
3241
3221
|
/**
|
|
3242
3222
|
* Computes the cumulative sum of values in a column. For this method to work properly, ensure your data is sorted first.
|
|
3243
3223
|
*
|
|
3244
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3245
|
-
*
|
|
3246
3224
|
* @param column - The name of the column storing the values to be accumulated.
|
|
3247
3225
|
* @param newColumn - The name of the new column in which the computed cumulative values will be stored.
|
|
3248
3226
|
* @param options - An optional object with configuration options:
|
|
@@ -3279,8 +3257,6 @@ class SimpleTable extends Simple {
|
|
|
3279
3257
|
* For rows without enough preceding or following rows to form a complete window, `NULL` will be returned.
|
|
3280
3258
|
* For this method to work properly, ensure your data is sorted by the relevant column(s) first.
|
|
3281
3259
|
*
|
|
3282
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3283
|
-
*
|
|
3284
3260
|
* @param column - The name of the column storing the values to be aggregated.
|
|
3285
3261
|
* @param newColumn - The name of the new column in which the computed rolling values will be stored.
|
|
3286
3262
|
* @param stat - The aggregation function to apply: `"min"`, `"max"`, `"mean"`, `"median"`, or `"sum"`.
|
|
@@ -3319,8 +3295,6 @@ class SimpleTable extends Simple {
|
|
|
3319
3295
|
* Calculates correlations between columns. If no `x` and `y` columns are specified, the method computes the correlations for all numeric column combinations.
|
|
3320
3296
|
* Note that correlation is symmetrical: the correlation of `x` with `y` is the same as `y` with `x`.
|
|
3321
3297
|
*
|
|
3322
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3323
|
-
*
|
|
3324
3298
|
* @param options - An optional object with configuration options:
|
|
3325
3299
|
* @param options.x - The name of the column for the x-values. If omitted, correlations will be computed for all numeric columns.
|
|
3326
3300
|
* @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.
|
|
@@ -3368,8 +3342,6 @@ class SimpleTable extends Simple {
|
|
|
3368
3342
|
* If no `x` and `y` columns are specified, the method computes linear regression analysis for all numeric column permutations.
|
|
3369
3343
|
* Note that linear regression analysis is asymmetrical: the linear regression of `x` over `y` is not the same as `y` over `x`.
|
|
3370
3344
|
*
|
|
3371
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3372
|
-
*
|
|
3373
3345
|
* @param options - An optional object with configuration options:
|
|
3374
3346
|
* @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.
|
|
3375
3347
|
* @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.
|
|
@@ -3415,8 +3387,6 @@ class SimpleTable extends Simple {
|
|
|
3415
3387
|
/**
|
|
3416
3388
|
* Identifies outliers in a specified column using the Interquartile Range (IQR) method.
|
|
3417
3389
|
*
|
|
3418
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3419
|
-
*
|
|
3420
3390
|
* @param column - The name of the column in which outliers will be identified.
|
|
3421
3391
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for outlier, `FALSE` otherwise) will be stored.
|
|
3422
3392
|
* @param options - An optional object with configuration options:
|
|
@@ -3443,8 +3413,6 @@ class SimpleTable extends Simple {
|
|
|
3443
3413
|
/**
|
|
3444
3414
|
* Computes the Z-score for values in a specified column.
|
|
3445
3415
|
*
|
|
3446
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3447
|
-
*
|
|
3448
3416
|
* @param column - The name of the column for which Z-scores will be calculated.
|
|
3449
3417
|
* @param newColumn - The name of the new column where the computed Z-scores will be stored.
|
|
3450
3418
|
* @param options - An optional object with configuration options:
|
|
@@ -3478,8 +3446,6 @@ class SimpleTable extends Simple {
|
|
|
3478
3446
|
/**
|
|
3479
3447
|
* Normalizes the values in a column using min-max normalization.
|
|
3480
3448
|
*
|
|
3481
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3482
|
-
*
|
|
3483
3449
|
* @param column - The name of the column in which values will be normalized.
|
|
3484
3450
|
* @param newColumn - The name of the new column where normalized values will be stored.
|
|
3485
3451
|
* @param options - An optional object with configuration options:
|
|
@@ -3524,8 +3490,6 @@ class SimpleTable extends Simple {
|
|
|
3524
3490
|
*
|
|
3525
3491
|
* 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.
|
|
3526
3492
|
*
|
|
3527
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3528
|
-
*
|
|
3529
3493
|
* @param column - The numeric column containing the values to index.
|
|
3530
3494
|
* @param newColumn - The name of the new column where indexed values will be stored.
|
|
3531
3495
|
* @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.
|
|
@@ -3583,48 +3547,84 @@ class SimpleTable extends Simple {
|
|
|
3583
3547
|
/**
|
|
3584
3548
|
* 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.
|
|
3585
3549
|
* This method offers high flexibility for data manipulation but can be slow for large tables as it involves transferring data between DuckDB and JavaScript.
|
|
3586
|
-
*
|
|
3550
|
+
* Before writing a JavaScript callback, check for an existing SDA method that
|
|
3551
|
+
* performs the same operation; it will usually be faster and more efficient.
|
|
3587
3552
|
*
|
|
3588
|
-
*
|
|
3553
|
+
* If the table has geometry columns, the callback can read and modify their
|
|
3554
|
+
* GeoJSON geometry objects directly. Extra properties added to these objects
|
|
3555
|
+
* are ignored; create new columns on the returned rows to store additional
|
|
3556
|
+
* attributes. All geometry columns must use EPSG:4326; use reproject() first
|
|
3557
|
+
* if needed.
|
|
3589
3558
|
*
|
|
3590
3559
|
* @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).
|
|
3591
3560
|
* @param options - An optional object with configuration options:
|
|
3592
|
-
* @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.
|
|
3561
|
+
* @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.
|
|
3562
|
+
* @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.
|
|
3593
3563
|
* @returns The table, so methods can be chained.
|
|
3594
3564
|
* @category Updating Data
|
|
3595
3565
|
*
|
|
3596
3566
|
* @example
|
|
3597
3567
|
* ```ts
|
|
3598
|
-
* //
|
|
3599
|
-
*
|
|
3600
|
-
* .
|
|
3601
|
-
*
|
|
3602
|
-
*
|
|
3603
|
-
* return rows.map((row) => ({
|
|
3604
|
-
* ...row,
|
|
3605
|
-
* hostname: typeof row.url === "string"
|
|
3606
|
-
* ? new URL(row.url).hostname
|
|
3607
|
-
* : null,
|
|
3608
|
-
* }));
|
|
3609
|
-
* })
|
|
3568
|
+
* // Double the value in each row with a JavaScript callback.
|
|
3569
|
+
* await table.loadArray([{ value: 1 }, { value: 2 }])
|
|
3570
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3571
|
+
* value: Number(row.value) * 2,
|
|
3572
|
+
* })))
|
|
3610
3573
|
* .log();
|
|
3611
3574
|
* ```
|
|
3612
3575
|
*
|
|
3613
3576
|
* @example
|
|
3614
3577
|
* ```ts
|
|
3615
|
-
* //
|
|
3616
|
-
*
|
|
3617
|
-
* .updateWithJS(
|
|
3618
|
-
*
|
|
3619
|
-
*
|
|
3620
|
-
* headers: { "content-type": "application/json" },
|
|
3621
|
-
* body: JSON.stringify(rows.map((row) => row.review)),
|
|
3622
|
-
* });
|
|
3623
|
-
* const scores = await response.json() as number[];
|
|
3624
|
-
* return rows.map((row, index) => ({ ...row, score: scores[index] }));
|
|
3625
|
-
* }, { batchSize: 100 })
|
|
3578
|
+
* // Process two rows per callback to limit how many rows are handled at once.
|
|
3579
|
+
* await table.loadArray([{ value: 1 }, { value: 2 }, { value: 3 }])
|
|
3580
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3581
|
+
* value: Number(row.value) * 2,
|
|
3582
|
+
* })), { batchSize: 2 })
|
|
3626
3583
|
* .log();
|
|
3627
3584
|
* ```
|
|
3585
|
+
*
|
|
3586
|
+
* @example
|
|
3587
|
+
* ```ts
|
|
3588
|
+
* // Add a JSON object column to keep related attributes together.
|
|
3589
|
+
* await table.loadArray([{ name: "Station" }])
|
|
3590
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3591
|
+
* ...row, details: { active: true, category: "weather" },
|
|
3592
|
+
* })), { columnTypes: { details: "JSON" } })
|
|
3593
|
+
* .log();
|
|
3594
|
+
* ```
|
|
3595
|
+
*
|
|
3596
|
+
* @example
|
|
3597
|
+
* ```ts
|
|
3598
|
+
* // Add a three-element float vector, such as an embedding.
|
|
3599
|
+
* await table.loadArray([{ name: "Station" }])
|
|
3600
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3601
|
+
* ...row, embedding: [0.25, 0.5, 0.75],
|
|
3602
|
+
* })), { columnTypes: { embedding: "FLOAT[3]" } })
|
|
3603
|
+
* .log();
|
|
3604
|
+
* ```
|
|
3605
|
+
*
|
|
3606
|
+
* @example
|
|
3607
|
+
* ```ts
|
|
3608
|
+
* // Move each point slightly east by editing its longitude.
|
|
3609
|
+
* await sdb.newTable().loadArray([{
|
|
3610
|
+
* geom: { type: "Point", coordinates: [-73, 45] },
|
|
3611
|
+
* }], { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } })
|
|
3612
|
+
* .updateWithJS((rows) => rows.map((row) => {
|
|
3613
|
+
* // This example loads only Points. Narrow the type for coordinate access.
|
|
3614
|
+
* const geom = row.geom as { type: "Point"; coordinates: number[] } | null;
|
|
3615
|
+
* if (geom !== null) geom.coordinates[0] += 0.01;
|
|
3616
|
+
* return row;
|
|
3617
|
+
* })).log();
|
|
3618
|
+
* ```
|
|
3619
|
+
*
|
|
3620
|
+
* @example
|
|
3621
|
+
* ```ts
|
|
3622
|
+
* // Create a geometry column from longitude and latitude values.
|
|
3623
|
+
* await sdb.newTable().loadArray([{ longitude: -73, latitude: 45 }])
|
|
3624
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3625
|
+
* ...row, geom: { type: "Point", coordinates: [row.longitude, row.latitude] },
|
|
3626
|
+
* })), { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } }).log();
|
|
3627
|
+
* ```
|
|
3628
3628
|
*/
|
|
3629
3629
|
updateWithJS(dataModifier, options = {}) {
|
|
3630
3630
|
updateWithJS(this, dataModifier, options);
|
|
@@ -3705,8 +3705,6 @@ class SimpleTable extends Simple {
|
|
|
3705
3705
|
* Produces identical output to `journalism-format`'s `normalizeString()` function
|
|
3706
3706
|
* for all common cases including accented Latin characters.
|
|
3707
3707
|
*
|
|
3708
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3709
|
-
*
|
|
3710
3708
|
* @param column The column containing the text to normalize
|
|
3711
3709
|
* @param newColumn The column to store the normalized results
|
|
3712
3710
|
* @param options Configuration options
|
|
@@ -3757,8 +3755,6 @@ class SimpleTable extends Simple {
|
|
|
3757
3755
|
* 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.
|
|
3758
3756
|
* `NULL` input values produce `NULL` counts.
|
|
3759
3757
|
*
|
|
3760
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3761
|
-
*
|
|
3762
3758
|
* @param column - The name of the column containing the strings to count.
|
|
3763
3759
|
* @param newColumn - The name of the new column where the character counts will be stored.
|
|
3764
3760
|
* @returns The table, so methods can be chained.
|
|
@@ -3778,8 +3774,6 @@ class SimpleTable extends Simple {
|
|
|
3778
3774
|
* Adds a new column containing the word count for each string in the specified column.
|
|
3779
3775
|
* 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.
|
|
3780
3776
|
*
|
|
3781
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3782
|
-
*
|
|
3783
3777
|
* @param column - The name of the column containing the strings to count.
|
|
3784
3778
|
* @param newColumn - The name of the new column where the word counts will be stored.
|
|
3785
3779
|
* @returns The table, so methods can be chained.
|
|
@@ -3815,6 +3809,7 @@ class SimpleTable extends Simple {
|
|
|
3815
3809
|
}
|
|
3816
3810
|
/**
|
|
3817
3811
|
* Returns the number of rows in the table.
|
|
3812
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
3818
3813
|
*
|
|
3819
3814
|
* @param options - An optional object with configuration options:
|
|
3820
3815
|
* @param options.conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"category = 'Book'"`).
|
|
@@ -4155,7 +4150,7 @@ class SimpleTable extends Simple {
|
|
|
4155
4150
|
}
|
|
4156
4151
|
/**
|
|
4157
4152
|
* Returns the first row of the table, optionally filtered by SQL conditions.
|
|
4158
|
-
*
|
|
4153
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4159
4154
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4160
4155
|
*
|
|
4161
4156
|
* @param options - An optional object with configuration options:
|
|
@@ -4182,7 +4177,7 @@ class SimpleTable extends Simple {
|
|
|
4182
4177
|
}
|
|
4183
4178
|
/**
|
|
4184
4179
|
* Returns the last row of the table, optionally filtered by SQL conditions.
|
|
4185
|
-
*
|
|
4180
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4186
4181
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4187
4182
|
*
|
|
4188
4183
|
* @param options - An optional object with configuration options:
|
|
@@ -4209,7 +4204,7 @@ class SimpleTable extends Simple {
|
|
|
4209
4204
|
}
|
|
4210
4205
|
/**
|
|
4211
4206
|
* Returns the top `n` rows of the table, optionally filtered by SQL conditions.
|
|
4212
|
-
*
|
|
4207
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4213
4208
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4214
4209
|
*
|
|
4215
4210
|
* @param count - The number of rows to return from the top of the table.
|
|
@@ -4238,7 +4233,7 @@ class SimpleTable extends Simple {
|
|
|
4238
4233
|
/**
|
|
4239
4234
|
* Returns the bottom `n` rows of the table, optionally filtered by SQL conditions.
|
|
4240
4235
|
* By default, the last row will be returned first. To preserve the original order, use the `originalOrder` option.
|
|
4241
|
-
*
|
|
4236
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4242
4237
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4243
4238
|
*
|
|
4244
4239
|
* @param count - The number of rows to return from the bottom of the table.
|
|
@@ -4274,7 +4269,7 @@ class SimpleTable extends Simple {
|
|
|
4274
4269
|
}
|
|
4275
4270
|
/**
|
|
4276
4271
|
* 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.
|
|
4277
|
-
*
|
|
4272
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4278
4273
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4279
4274
|
*
|
|
4280
4275
|
* @param conditions - The conditions to match, specified as a SQL `WHERE` clause.
|
|
@@ -4319,13 +4314,26 @@ class SimpleTable extends Simple {
|
|
|
4319
4314
|
}
|
|
4320
4315
|
/**
|
|
4321
4316
|
* Returns the data from the table as an array of objects, optionally filtered by SQL conditions.
|
|
4322
|
-
*
|
|
4317
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4323
4318
|
*
|
|
4324
4319
|
* Top-level DuckDB `DATE` and `TIMESTAMP` columns are returned as JavaScript
|
|
4325
4320
|
* `Date` objects interpreted in UTC. `TIMESTAMP WITH TIME ZONE` values are
|
|
4326
4321
|
* returned as UTC strings, preserving DuckDB's microsecond precision;
|
|
4327
4322
|
* JavaScript `Date` supports only milliseconds.
|
|
4328
4323
|
*
|
|
4324
|
+
* Top-level `BIGINT`, `UBIGINT`, `HUGEINT`, and `UHUGEINT` columns are
|
|
4325
|
+
* returned as JavaScript numbers. Values outside `Number.MIN_SAFE_INTEGER`
|
|
4326
|
+
* through `Number.MAX_SAFE_INTEGER` throw instead of losing precision.
|
|
4327
|
+
* Use `convert({ columnName: "string" })` before `getData()` to retrieve
|
|
4328
|
+
* their exact digits as strings.
|
|
4329
|
+
*
|
|
4330
|
+
* SQL arrays and lists, including float vectors, return their actual elements
|
|
4331
|
+
* as JavaScript arrays. Null cells and null elements remain null.
|
|
4332
|
+
*
|
|
4333
|
+
* Nested SQL lists and structs become JavaScript arrays and objects. Within
|
|
4334
|
+
* them, `BIGINT`, `UBIGINT`, `HUGEINT`, `UHUGEINT`, and `DECIMAL` values remain
|
|
4335
|
+
* strings to preserve precision, even for small integers.
|
|
4336
|
+
*
|
|
4329
4337
|
* @param options - An optional object with configuration options:
|
|
4330
4338
|
* @param options.columns - An array of column names to include in the result. If omitted, all columns will be included.
|
|
4331
4339
|
* @param options.conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"category = 'Book'"`).
|
|
@@ -4359,6 +4367,18 @@ class SimpleTable extends Simple {
|
|
|
4359
4367
|
* // Return at most two rows.
|
|
4360
4368
|
* const preview = await table.getData({ limit: 2 });
|
|
4361
4369
|
* ```
|
|
4370
|
+
*
|
|
4371
|
+
* @example
|
|
4372
|
+
* ```ts
|
|
4373
|
+
* // Read nested integers without losing digits. SQL creates the nested types.
|
|
4374
|
+
* await sdb.customQuery(`CREATE TABLE nested_example AS SELECT
|
|
4375
|
+
* [42::BIGINT, 9007199254740993::BIGINT] AS ids,
|
|
4376
|
+
* {'count': 2::INTEGER, 'amount': 123.450::DECIMAL(6,3)} AS details`);
|
|
4377
|
+
* const nested = sdb.newTable("nested_example");
|
|
4378
|
+
* const rows = await nested.getData();
|
|
4379
|
+
* // [{ ids: ["42", "9007199254740993"], details: { count: 2, amount: "123.450" } }]
|
|
4380
|
+
* await nested.log();
|
|
4381
|
+
* ```
|
|
4362
4382
|
*/
|
|
4363
4383
|
async getData(options = {}) {
|
|
4364
4384
|
return await getData(this, options);
|
|
@@ -4367,6 +4387,7 @@ class SimpleTable extends Simple {
|
|
|
4367
4387
|
* Streams the table rows one by one as an async iterator, without
|
|
4368
4388
|
* materializing the whole table in memory. Values are converted to
|
|
4369
4389
|
* JavaScript types the same way as `getData()`.
|
|
4390
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4370
4391
|
*
|
|
4371
4392
|
* The underlying DuckDB result is streamed chunk by chunk, so tables
|
|
4372
4393
|
* larger than the available memory can be iterated. Avoid running other
|
|
@@ -4399,7 +4420,7 @@ class SimpleTable extends Simple {
|
|
|
4399
4420
|
}
|
|
4400
4421
|
/**
|
|
4401
4422
|
* Returns the data from the table as a CSV string, optionally filtered by SQL conditions.
|
|
4402
|
-
*
|
|
4423
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4403
4424
|
* Temporal values are first converted as they are in `getData()`, then
|
|
4404
4425
|
* serialized using UTC date and timestamp text.
|
|
4405
4426
|
*
|
|
@@ -4438,8 +4459,6 @@ class SimpleTable extends Simple {
|
|
|
4438
4459
|
/**
|
|
4439
4460
|
* Creates point geometries from latitude (y) and longitude (x) columns.
|
|
4440
4461
|
*
|
|
4441
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4442
|
-
*
|
|
4443
4462
|
* @param latColumn - The name of the column storing the latitude (y-coordinate) values.
|
|
4444
4463
|
* @param lonColumn - The name of the column storing the longitude (x-coordinate) values.
|
|
4445
4464
|
* @param newColumn - The name of the new column where the point geometries will be stored.
|
|
@@ -4469,8 +4488,6 @@ class SimpleTable extends Simple {
|
|
|
4469
4488
|
/**
|
|
4470
4489
|
* Adds a column with boolean values indicating the validity of geometries.
|
|
4471
4490
|
*
|
|
4472
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4473
|
-
*
|
|
4474
4491
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for valid, `FALSE` for invalid) will be stored.
|
|
4475
4492
|
* @param options - An optional object with configuration options:
|
|
4476
4493
|
* @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.
|
|
@@ -4497,8 +4514,6 @@ class SimpleTable extends Simple {
|
|
|
4497
4514
|
/**
|
|
4498
4515
|
* Adds a column with the number of vertices (points) in each geometry.
|
|
4499
4516
|
*
|
|
4500
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4501
|
-
*
|
|
4502
4517
|
* @param newColumn - The name of the new column where the vertex counts will be stored.
|
|
4503
4518
|
* @param options - An optional object with configuration options:
|
|
4504
4519
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4525,8 +4540,6 @@ class SimpleTable extends Simple {
|
|
|
4525
4540
|
/**
|
|
4526
4541
|
* Attempts to make invalid geometries valid without removing any vertices.
|
|
4527
4542
|
*
|
|
4528
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4529
|
-
*
|
|
4530
4543
|
* @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.
|
|
4531
4544
|
* @returns The table, so methods can be chained.
|
|
4532
4545
|
* @category Geospatial
|
|
@@ -4550,8 +4563,6 @@ class SimpleTable extends Simple {
|
|
|
4550
4563
|
/**
|
|
4551
4564
|
* Adds a column with boolean values indicating whether geometries are closed (e.g., polygons) or open (e.g., linestrings).
|
|
4552
4565
|
*
|
|
4553
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4554
|
-
*
|
|
4555
4566
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for closed, `FALSE` for open) will be stored.
|
|
4556
4567
|
* @param options - An optional object with configuration options:
|
|
4557
4568
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4577,8 +4588,6 @@ class SimpleTable extends Simple {
|
|
|
4577
4588
|
/**
|
|
4578
4589
|
* Adds a column with the geometry type (e.g., `"POINT"`, `"LINESTRING"`, `"POLYGON"`) for each geometry.
|
|
4579
4590
|
*
|
|
4580
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4581
|
-
*
|
|
4582
4591
|
* @param newColumn - The name of the new column where the geometry types will be stored.
|
|
4583
4592
|
* @param options - An optional object with configuration options:
|
|
4584
4593
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4605,8 +4614,6 @@ class SimpleTable extends Simple {
|
|
|
4605
4614
|
* 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).
|
|
4606
4615
|
* **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.
|
|
4607
4616
|
*
|
|
4608
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4609
|
-
*
|
|
4610
4617
|
* @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
4611
4618
|
* @returns The table, so methods can be chained.
|
|
4612
4619
|
* @category Geospatial
|
|
@@ -4632,7 +4639,7 @@ class SimpleTable extends Simple {
|
|
|
4632
4639
|
*
|
|
4633
4640
|
* 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.
|
|
4634
4641
|
*
|
|
4635
|
-
* This method supports only `POINT` geometries in `EPSG:4326`. Null and empty geometries are preserved.
|
|
4642
|
+
* This method supports only `POINT` geometries in `EPSG:4326`. Null and empty geometries are preserved.
|
|
4636
4643
|
*
|
|
4637
4644
|
* @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.
|
|
4638
4645
|
* @param options - An optional object with configuration options:
|
|
@@ -4665,8 +4672,6 @@ class SimpleTable extends Simple {
|
|
|
4665
4672
|
/**
|
|
4666
4673
|
* Reduces the precision of geometries in a specified column to a given number of decimal places.
|
|
4667
4674
|
*
|
|
4668
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4669
|
-
*
|
|
4670
4675
|
* @param decimals - The number of decimal places to keep in the coordinates of the geometries.
|
|
4671
4676
|
* @param options - An optional object with configuration options:
|
|
4672
4677
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4692,8 +4697,6 @@ class SimpleTable extends Simple {
|
|
|
4692
4697
|
/**
|
|
4693
4698
|
* Reprojects the geometries in a specified column to another Spatial Reference System (SRS).
|
|
4694
4699
|
*
|
|
4695
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4696
|
-
*
|
|
4697
4700
|
* @param crs - The target SRS (e.g., `"EPSG:3347"`, or `"EPSG:4326"` for EPSG:4326 (WGS84)).
|
|
4698
4701
|
* @param options - An optional object with configuration options:
|
|
4699
4702
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4720,8 +4723,6 @@ class SimpleTable extends Simple {
|
|
|
4720
4723
|
* Computes the area of geometries in square meters (`"m2"`) or optionally square kilometers (`"km2"`).
|
|
4721
4724
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4722
4725
|
*
|
|
4723
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4724
|
-
*
|
|
4725
4726
|
* @param newColumn - The name of the new column where the computed areas will be stored.
|
|
4726
4727
|
* @param options - An optional object with configuration options:
|
|
4727
4728
|
* @param options.unit - The unit for the computed area: `"m2"` (square meters) or `"km2"` (square kilometers). Defaults to `"m2"`.
|
|
@@ -4762,8 +4763,6 @@ class SimpleTable extends Simple {
|
|
|
4762
4763
|
* Computes the length of line geometries in meters (`"m"`) or optionally kilometers (`"km"`).
|
|
4763
4764
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4764
4765
|
*
|
|
4765
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4766
|
-
*
|
|
4767
4766
|
* @param newColumn - The name of the new column where the computed lengths will be stored.
|
|
4768
4767
|
* @param options - An optional object with configuration options:
|
|
4769
4768
|
* @param options.unit - The unit for the computed length: `"m"` (meters) or `"km"` (kilometers). Defaults to `"m"`.
|
|
@@ -4804,8 +4803,6 @@ class SimpleTable extends Simple {
|
|
|
4804
4803
|
* Computes the perimeter of polygon geometries in meters (`"m"`) or optionally kilometers (`"km"`).
|
|
4805
4804
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4806
4805
|
*
|
|
4807
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4808
|
-
*
|
|
4809
4806
|
* @param newColumn - The name of the new column where the computed perimeters will be stored.
|
|
4810
4807
|
* @param options - An optional object with configuration options:
|
|
4811
4808
|
* @param options.unit - The unit for the computed perimeter: `"m"` (meters) or `"km"` (kilometers). Defaults to `"m"`.
|
|
@@ -4846,8 +4843,6 @@ class SimpleTable extends Simple {
|
|
|
4846
4843
|
* Computes a buffer (a polygon representing a specified distance around a geometry) for geometries in a specified column.
|
|
4847
4844
|
* The distance is in the Spatial Reference System (SRS) unit of the input geometries.
|
|
4848
4845
|
*
|
|
4849
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4850
|
-
*
|
|
4851
4846
|
* @param newColumn - The name of the new column where the buffered geometries will be stored.
|
|
4852
4847
|
* @param distance - The distance for the buffer. This value is in the units of the geometry's SRS.
|
|
4853
4848
|
* @param options - An optional object with configuration options:
|
|
@@ -4875,7 +4870,6 @@ class SimpleTable extends Simple {
|
|
|
4875
4870
|
* Merges the data of this table (considered the left table) with another table (the right table) based on a spatial relationship.
|
|
4876
4871
|
* Note that the order of rows in the returned data is not guaranteed to be the same as in the original tables.
|
|
4877
4872
|
* This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
|
|
4878
|
-
* 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.
|
|
4879
4873
|
*
|
|
4880
4874
|
* @param rightTable - The SimpleTable instance to be joined with this table.
|
|
4881
4875
|
* @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).
|
|
@@ -4947,8 +4941,6 @@ class SimpleTable extends Simple {
|
|
|
4947
4941
|
/**
|
|
4948
4942
|
* Computes the intersection of two sets of geometries, creating new geometries where they overlap.
|
|
4949
4943
|
*
|
|
4950
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4951
|
-
*
|
|
4952
4944
|
* @param column1 - The name of the first column storing geometries.
|
|
4953
4945
|
* @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
|
|
4954
4946
|
* @param newColumn - The name of the new column where the computed intersection geometries will be stored.
|
|
@@ -4968,8 +4960,6 @@ class SimpleTable extends Simple {
|
|
|
4968
4960
|
/**
|
|
4969
4961
|
* Computes the geometric difference between two geometries, returning the portion of the first geometry that does not intersect the second.
|
|
4970
4962
|
*
|
|
4971
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4972
|
-
*
|
|
4973
4963
|
* @param column1 - The name of the column storing the geometries from which the second geometries will be subtracted.
|
|
4974
4964
|
* @param column2 - The name of the column storing the geometries to subtract. Both columns must have the same projection.
|
|
4975
4965
|
* @param newColumn - The name of the new column where the geometric differences will be stored.
|
|
@@ -4989,8 +4979,6 @@ class SimpleTable extends Simple {
|
|
|
4989
4979
|
/**
|
|
4990
4980
|
* Fills holes in polygon geometries.
|
|
4991
4981
|
*
|
|
4992
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4993
|
-
*
|
|
4994
4982
|
* @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
4995
4983
|
* @returns The table, so methods can be chained.
|
|
4996
4984
|
* @category Geospatial
|
|
@@ -5014,8 +5002,6 @@ class SimpleTable extends Simple {
|
|
|
5014
5002
|
/**
|
|
5015
5003
|
* Returns `TRUE` if two geometries intersect (overlap in any way), and `FALSE` otherwise.
|
|
5016
5004
|
*
|
|
5017
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5018
|
-
*
|
|
5019
5005
|
* @param column1 - The name of the first column storing geometries.
|
|
5020
5006
|
* @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
|
|
5021
5007
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for intersection, `FALSE` otherwise) will be stored.
|
|
@@ -5035,8 +5021,6 @@ class SimpleTable extends Simple {
|
|
|
5035
5021
|
/**
|
|
5036
5022
|
* Returns `TRUE` if every point of a geometry in `column` is covered by a geometry in `containerColumn`, including their boundaries, and `FALSE` otherwise.
|
|
5037
5023
|
*
|
|
5038
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5039
|
-
*
|
|
5040
5024
|
* @param column - The name of the column storing the geometries to be tested for containment.
|
|
5041
5025
|
* @param containerColumn - The name of the column storing the geometries to be tested as containers. Both columns must have the same projection.
|
|
5042
5026
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` when covered, `FALSE` otherwise) will be stored.
|
|
@@ -5056,8 +5040,6 @@ class SimpleTable extends Simple {
|
|
|
5056
5040
|
/**
|
|
5057
5041
|
* Computes the union of two geometries, creating a new geometry that represents the merged area of both.
|
|
5058
5042
|
*
|
|
5059
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5060
|
-
*
|
|
5061
5043
|
* @param column1 - The name of the first column storing geometries.
|
|
5062
5044
|
* @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
|
|
5063
5045
|
* @param newColumn - The name of the new column where the computed union geometries will be stored.
|
|
@@ -5078,8 +5060,6 @@ class SimpleTable extends Simple {
|
|
|
5078
5060
|
* Extracts the latitude (y) and longitude (x) coordinates from point geometries.
|
|
5079
5061
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
5080
5062
|
*
|
|
5081
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5082
|
-
*
|
|
5083
5063
|
* @param column - The name of the column storing the point geometries.
|
|
5084
5064
|
* @param latColumn - The name of the new column where the extracted latitude (y-coordinate) values will be stored.
|
|
5085
5065
|
* @param lonColumn - The name of the new column where the extracted longitude (x-coordinate) values will be stored.
|
|
@@ -5099,8 +5079,6 @@ class SimpleTable extends Simple {
|
|
|
5099
5079
|
/**
|
|
5100
5080
|
* Simplifies geometries while preserving their overall coverage. A higher tolerance results in more significant simplification.
|
|
5101
5081
|
*
|
|
5102
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5103
|
-
*
|
|
5104
5082
|
* @param tolerance - A numeric value representing the simplification tolerance. A higher value leads to greater simplification.
|
|
5105
5083
|
* @param options - An optional object with configuration options:
|
|
5106
5084
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -5128,8 +5106,6 @@ class SimpleTable extends Simple {
|
|
|
5128
5106
|
* Computes the centroid of geometries.
|
|
5129
5107
|
* The values are returned in the SRS unit of the input geometries.
|
|
5130
5108
|
*
|
|
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
5109
|
* @param newColumn - The name of the new column where the computed centroid geometries will be stored.
|
|
5134
5110
|
* @param options - An optional object with configuration options:
|
|
5135
5111
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -5155,8 +5131,6 @@ class SimpleTable extends Simple {
|
|
|
5155
5131
|
/**
|
|
5156
5132
|
* Generates a random point within the geometries of a specified column.
|
|
5157
5133
|
*
|
|
5158
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5159
|
-
*
|
|
5160
5134
|
* @param newColumn - The name of the new column where the random points will be stored.
|
|
5161
5135
|
* @param tries - The number of points to generate within the bounding box of each geometry to find one that is within the geometry itself.
|
|
5162
5136
|
* @param options - An optional object with configuration options:
|
|
@@ -5191,8 +5165,6 @@ class SimpleTable extends Simple {
|
|
|
5191
5165
|
* You can optionally specify `"spheroid"` or `"haversine"` methods to get results in meters or kilometers.
|
|
5192
5166
|
* If using `"spheroid"` or `"haversine"`, the input geometries must be in EPSG:4326 (WGS84).
|
|
5193
5167
|
*
|
|
5194
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5195
|
-
*
|
|
5196
5168
|
* @param column1 - The name of the first column storing geometries.
|
|
5197
5169
|
* @param column2 - The name of the second column storing geometries.
|
|
5198
5170
|
* @param newColumn - The name of the new column where the computed distances will be stored.
|
|
@@ -5237,8 +5209,6 @@ class SimpleTable extends Simple {
|
|
|
5237
5209
|
/**
|
|
5238
5210
|
* Unnests geometries recursively, transforming multi-part geometries (e.g., MultiPolygon) into individual single-part geometries (e.g., Polygon).
|
|
5239
5211
|
*
|
|
5240
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5241
|
-
*
|
|
5242
5212
|
* @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.
|
|
5243
5213
|
* @returns The table, so methods can be chained.
|
|
5244
5214
|
* @category Geospatial
|
|
@@ -5262,8 +5232,6 @@ class SimpleTable extends Simple {
|
|
|
5262
5232
|
/**
|
|
5263
5233
|
* Adds the bounding box coordinates of geometries in a specified column as four new columns: `minLon`, `minLat`, `maxLon`, and `maxLat`.
|
|
5264
5234
|
*
|
|
5265
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5266
|
-
*
|
|
5267
5235
|
* @param options - An optional object with configuration options:
|
|
5268
5236
|
* @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.
|
|
5269
5237
|
* @param options.decimals - The number of decimal places to round the bounding box coordinates. Defaults to `undefined` (no rounding).
|
|
@@ -5291,8 +5259,6 @@ class SimpleTable extends Simple {
|
|
|
5291
5259
|
/**
|
|
5292
5260
|
* Aggregates geometries in a specified column based on a chosen aggregation method.
|
|
5293
5261
|
*
|
|
5294
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5295
|
-
*
|
|
5296
5262
|
* @param method - The aggregation method to apply: `"union"` (combines all geometries into a single multi-geometry) or `"intersection"` (computes the intersection of all geometries).
|
|
5297
5263
|
* @param options - An optional object with configuration options:
|
|
5298
5264
|
* @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.
|
|
@@ -5325,8 +5291,6 @@ class SimpleTable extends Simple {
|
|
|
5325
5291
|
/**
|
|
5326
5292
|
* Transforms closed linestring geometries into polygon geometries.
|
|
5327
5293
|
*
|
|
5328
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5329
|
-
*
|
|
5330
5294
|
* @param column - The name of the column storing the linestring geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
5331
5295
|
* @returns The table, so methods can be chained.
|
|
5332
5296
|
* @category Geospatial
|
|
@@ -5373,7 +5337,9 @@ class SimpleTable extends Simple {
|
|
|
5373
5337
|
return await getBoundingBox(this, column);
|
|
5374
5338
|
}
|
|
5375
5339
|
/**
|
|
5376
|
-
* Returns the table's geospatial data as a GeoJSON
|
|
5340
|
+
* Returns the table's geospatial data as a GeoJSON FeatureCollection.
|
|
5341
|
+
* Each row becomes a Feature: the selected geometry column becomes its geometry,
|
|
5342
|
+
* and the remaining columns become its properties.
|
|
5377
5343
|
* If the table has multiple geometry columns, you must specify which one to use.
|
|
5378
5344
|
*
|
|
5379
5345
|
* @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -5411,12 +5377,13 @@ class SimpleTable extends Simple {
|
|
|
5411
5377
|
}
|
|
5412
5378
|
/**
|
|
5413
5379
|
* Writes the table's data to a file in various formats (CSV, JSON, Parquet, DuckDB, SQLite).
|
|
5380
|
+
* Tables with geometry columns must use `writeGeoData()` instead.
|
|
5414
5381
|
* If the specified path does not exist, it will be created.
|
|
5415
5382
|
*
|
|
5416
5383
|
* @param file - The absolute path to the output file (e.g., `"./output.csv"`, `"./output.json"`).
|
|
5417
5384
|
* @param options - An optional object with configuration options:
|
|
5418
5385
|
* @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`.
|
|
5419
|
-
* @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.
|
|
5386
|
+
* @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.
|
|
5420
5387
|
* @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`.
|
|
5421
5388
|
* @returns A promise that resolves to the table, so methods can be chained.
|
|
5422
5389
|
* @category File Operations
|
|
@@ -5517,28 +5484,28 @@ class SimpleTable extends Simple {
|
|
|
5517
5484
|
* Caches the results of computations in `./.sda-cache`.
|
|
5518
5485
|
* You should add `./.sda-cache` to your `.gitignore` file.
|
|
5519
5486
|
*
|
|
5520
|
-
* Cache entries are stored as DuckDB database files. Full-text search (FTS)
|
|
5521
|
-
* indexes are persisted in the cache file and restored directly on a cache
|
|
5522
|
-
* hit. Vector similarity search (VSS/HNSW) indexes are not persisted in the
|
|
5523
|
-
* cache file; their definitions are stored as metadata and used to rebuild
|
|
5524
|
-
* the indexes on every cache hit. If loading the entry or restoring its
|
|
5525
|
-
* indexes fails, the computation runs again and replaces the cache entry.
|
|
5526
|
-
*
|
|
5527
5487
|
* `cache()` automatically tracks whether earlier SDA operations changed the
|
|
5528
5488
|
* table. It also records every other already registered `SimpleTable` read
|
|
5529
5489
|
* through `SimpleTable` methods while `compute` runs and invalidates the
|
|
5530
5490
|
* cached step when any of their generations change. Tables created inside
|
|
5531
5491
|
* `compute` are part of the computation itself and are not dependencies.
|
|
5532
5492
|
*
|
|
5493
|
+
* Inside `compute`, you may modify the table being cached and create or
|
|
5494
|
+
* modify temporary tables, provided you remove them before the callback
|
|
5495
|
+
* finishes. Other tables that already existed may be read but not modified,
|
|
5496
|
+
* renamed, or removed. `customQuery()` bypasses enforcement of these rules.
|
|
5497
|
+
*
|
|
5533
5498
|
* `SimpleDB.customQuery()` bypasses this tracking. Reading or changing a
|
|
5534
5499
|
* table with `customQuery()` can therefore return stale cached data. Include
|
|
5535
5500
|
* a value that identifies the custom query's dependencies in `options.inputs`
|
|
5536
5501
|
* (such as a table content hash), or use tracked `SimpleTable` methods.
|
|
5537
5502
|
*
|
|
5538
|
-
*
|
|
5539
|
-
*
|
|
5540
|
-
*
|
|
5541
|
-
*
|
|
5503
|
+
* Cache entries are stored as DuckDB database files. Full-text search (FTS)
|
|
5504
|
+
* indexes are persisted in the cache file and restored directly on a cache
|
|
5505
|
+
* hit. Vector similarity search (VSS/HNSW) indexes are not persisted in the
|
|
5506
|
+
* cache file; their definitions are stored as metadata and used to rebuild
|
|
5507
|
+
* the indexes on every cache hit. If loading the entry or restoring its
|
|
5508
|
+
* indexes fails, the computation runs again and replaces the cache entry.
|
|
5542
5509
|
*
|
|
5543
5510
|
* @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.
|
|
5544
5511
|
* @param options - An optional object with configuration options:
|
|
@@ -5621,12 +5588,23 @@ class SimpleTable extends Simple {
|
|
|
5621
5588
|
return this;
|
|
5622
5589
|
}
|
|
5623
5590
|
/**
|
|
5624
|
-
* Logs a specified number of rows from the table to the console. By default, the first 10 rows are logged.
|
|
5591
|
+
* Logs up to a specified number of rows from the table to the console. By default, the first 10 rows are logged.
|
|
5625
5592
|
* You can optionally log the column types and filter the data based on conditions.
|
|
5626
|
-
*
|
|
5593
|
+
* The footer reports the total number of matching rows and, only when some rows
|
|
5594
|
+
* are omitted, the number actually shown (for example, `100 rows in total / showing 15 rows`).
|
|
5595
|
+
* SQL dates and timestamps retain their native precision for display, including
|
|
5596
|
+
* temporal infinities. Lists and objects are stringified using the same nested
|
|
5597
|
+
* representations as `getData()`, then truncated according to `charsToLog`.
|
|
5598
|
+
* Unsafe top-level large integers throw, just as with `getData()`.
|
|
5599
|
+
* Type annotations describe the SQL type and the JavaScript extraction type
|
|
5600
|
+
* before display formatting; nulls do not determine the column's annotation.
|
|
5601
|
+
* Colors reflect the SQL value's meaning, so exact decimal strings use numeric
|
|
5602
|
+
* coloring. Column width is independent of the content truncation budget.
|
|
5603
|
+
*
|
|
5604
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
5627
5605
|
*
|
|
5628
5606
|
* @param options - Either the number of rows to log (a specific number or `"all"`) or an object with configuration options:
|
|
5629
|
-
* @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.
|
|
5607
|
+
* @param options.count - The maximum number of rows to log. Defaults to 10 or the value set in the SimpleDB instance. Use `"all"` to log all rows.
|
|
5630
5608
|
* @param options.types - Whether to log the column types along with the data. Defaults to the value set in the SimpleDB instance.
|
|
5631
5609
|
* @param options.conditions - A SQL `WHERE` clause condition to filter the data before logging. Defaults to no condition.
|
|
5632
5610
|
* @returns A promise that resolves to the table, so methods can be chained.
|
|
@@ -5663,57 +5641,7 @@ class SimpleTable extends Simple {
|
|
|
5663
5641
|
* ```
|
|
5664
5642
|
*/
|
|
5665
5643
|
async log(options = {}) {
|
|
5666
|
-
|
|
5667
|
-
await this.sdb.start();
|
|
5668
|
-
this.db = this.sdb.db;
|
|
5669
|
-
this.connection = this.sdb.connection;
|
|
5670
|
-
}
|
|
5671
|
-
if (this.connection === undefined) {
|
|
5672
|
-
throw new Error("this.connection is undefined");
|
|
5673
|
-
}
|
|
5674
|
-
let count;
|
|
5675
|
-
if (typeof options === "number") {
|
|
5676
|
-
count = options;
|
|
5677
|
-
}
|
|
5678
|
-
else if (options === "all") {
|
|
5679
|
-
count = await this.getRowCount();
|
|
5680
|
-
}
|
|
5681
|
-
else if (typeof options === "object") {
|
|
5682
|
-
if (options.count === "all") {
|
|
5683
|
-
count = await this.getRowCount();
|
|
5684
|
-
}
|
|
5685
|
-
else if (typeof options.count === "number") {
|
|
5686
|
-
count = options.count;
|
|
5687
|
-
}
|
|
5688
|
-
else {
|
|
5689
|
-
count = this.rowsToLog;
|
|
5690
|
-
}
|
|
5691
|
-
}
|
|
5692
|
-
else {
|
|
5693
|
-
count = this.rowsToLog;
|
|
5694
|
-
}
|
|
5695
|
-
const types = typeof options === "object"
|
|
5696
|
-
? options.types ?? this.typesToLog
|
|
5697
|
-
: this.typesToLog;
|
|
5698
|
-
const conditions = typeof options === "object"
|
|
5699
|
-
? options.conditions ?? undefined
|
|
5700
|
-
: undefined;
|
|
5701
|
-
if (this.connection === undefined ||
|
|
5702
|
-
!(await this.sdb.hasTable(this.name))) {
|
|
5703
|
-
console.log(`\nTable ${this.name}: no data`);
|
|
5704
|
-
}
|
|
5705
|
-
else {
|
|
5706
|
-
console.log(`\nTable ${this.name}:`);
|
|
5707
|
-
conditions && console.log(`Conditions: ${conditions}`);
|
|
5708
|
-
const data = await this.getTop(count, { conditions });
|
|
5709
|
-
logData(types ? await this.getTypes() : null, data, this.charsToLog);
|
|
5710
|
-
const rowCount = conditions
|
|
5711
|
-
? parseInt((await this.sdb.customQuery(`select count(*) as count from ${quoteIdentifier(this.name)} where ${conditions}`, { returnData: true }))[0].count)
|
|
5712
|
-
: await this.getRowCount();
|
|
5713
|
-
console.log(`${formatNumber(rowCount)} rows in total ${`(count: ${count}${typeof this.charsToLog === "number"
|
|
5714
|
-
? `, charsToLog: ${this.charsToLog}`
|
|
5715
|
-
: ""})`}`);
|
|
5716
|
-
}
|
|
5644
|
+
await log(this, options);
|
|
5717
5645
|
return this;
|
|
5718
5646
|
}
|
|
5719
5647
|
/**
|
|
@@ -5915,6 +5843,10 @@ class SimpleTable extends Simple {
|
|
|
5915
5843
|
/**
|
|
5916
5844
|
* 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.
|
|
5917
5845
|
*
|
|
5846
|
+
* Uses the same precision-preserving temporal display, nested stringification,
|
|
5847
|
+
* numeric coloring, and `charsToLog` truncation as `log()`. Unsafe top-level
|
|
5848
|
+
* large integers throw, just as with `getData()`.
|
|
5849
|
+
*
|
|
5918
5850
|
* @param count - The number of rows to log from the bottom of the table. Defaults to the table's `rowsToLog` option if not specified.
|
|
5919
5851
|
* @param options - An optional object with logging preferences.
|
|
5920
5852
|
* @param options.originalOrder - If true, the rows are displayed in their original order (top to bottom). Defaults to false.
|
|
@@ -5940,10 +5872,7 @@ class SimpleTable extends Simple {
|
|
|
5940
5872
|
* ```
|
|
5941
5873
|
*/
|
|
5942
5874
|
async logBottom(count, options = {}) {
|
|
5943
|
-
|
|
5944
|
-
console.log(`\nTable ${this.name} (${rows} bottom rows):`);
|
|
5945
|
-
const data = await this.getBottom(rows, options);
|
|
5946
|
-
logData(null, data, this.charsToLog);
|
|
5875
|
+
await logBottom(this, count, options);
|
|
5947
5876
|
return this;
|
|
5948
5877
|
}
|
|
5949
5878
|
/**
|