@nshiab/simple-data-analysis-core 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -12
- package/esm/class/Simple.d.ts +8 -2
- package/esm/class/Simple.d.ts.map +1 -1
- package/esm/class/Simple.js +9 -3
- package/esm/class/SimpleDB.d.ts +72 -1
- package/esm/class/SimpleDB.d.ts.map +1 -1
- package/esm/class/SimpleDB.js +81 -1
- package/esm/class/SimpleTable.d.ts +251 -274
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +248 -325
- 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/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 +58 -0
- package/esm/methods/logBottom.d.ts +5 -0
- package/esm/methods/logBottom.d.ts.map +1 -0
- package/esm/methods/logBottom.js +9 -0
- package/esm/methods/removeTable.d.ts.map +1 -1
- package/esm/methods/removeTable.js +2 -0
- package/esm/methods/removeTables.d.ts.map +1 -1
- package/esm/methods/removeTables.js +7 -0
- package/esm/methods/renameTable.d.ts.map +1 -1
- package/esm/methods/renameTable.js +4 -0
- package/esm/methods/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 +337 -444
- 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 +251 -274
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +248 -325
- 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/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 +64 -0
- package/script/methods/logBottom.d.ts +5 -0
- package/script/methods/logBottom.d.ts.map +1 -0
- package/script/methods/logBottom.js +15 -0
- package/script/methods/removeTable.d.ts.map +1 -1
- package/script/methods/removeTable.js +2 -0
- package/script/methods/removeTables.d.ts.map +1 -1
- package/script/methods/removeTables.js +7 -0
- package/script/methods/renameTable.d.ts.map +1 -1
- package/script/methods/renameTable.js +4 -0
- package/script/methods/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
|
@@ -111,7 +111,7 @@ export default class SimpleTable extends Simple {
|
|
|
111
111
|
* @param simpleDB - The SimpleDB instance that this table belongs to.
|
|
112
112
|
* @param options - An optional object with configuration options:
|
|
113
113
|
* @param options.rowsToLog - The number of rows to log when displaying table data.
|
|
114
|
-
* @param options.charsToLog - The maximum
|
|
114
|
+
* @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.
|
|
115
115
|
* @param options.typesToLog - A boolean indicating whether to include data types when logging a table.
|
|
116
116
|
* @category Constructor
|
|
117
117
|
*/
|
|
@@ -148,6 +148,7 @@ export default class SimpleTable extends Simple {
|
|
|
148
148
|
run(): Promise<this>;
|
|
149
149
|
/**
|
|
150
150
|
* Renames the current table.
|
|
151
|
+
* The new name must not belong to another registered table, ignoring ASCII letter case.
|
|
151
152
|
*
|
|
152
153
|
* @param name - The new name for the table.
|
|
153
154
|
* @returns A promise that resolves to the renamed table.
|
|
@@ -165,9 +166,7 @@ export default class SimpleTable extends Simple {
|
|
|
165
166
|
* Sets the data types for columns in a new table. If the table already exists, it will be replaced.
|
|
166
167
|
* To convert the types of an existing table, use the `.convert()` method instead.
|
|
167
168
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* @param types - An object specifying the column names and their target data types (JavaScript or SQL types).
|
|
169
|
+
* @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.
|
|
171
170
|
* @returns The table, so methods can be chained.
|
|
172
171
|
* @category Table Management
|
|
173
172
|
*
|
|
@@ -180,27 +179,42 @@ export default class SimpleTable extends Simple {
|
|
|
180
179
|
* raise: "float",
|
|
181
180
|
* }).log();
|
|
182
181
|
* ```
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* // Create an empty table with JSON, embedding, and geometry columns.
|
|
186
|
+
* await table.setTypes({
|
|
187
|
+
* details: "JSON",
|
|
188
|
+
* embedding: "FLOAT[3]",
|
|
189
|
+
* geom: "GEOMETRY('EPSG:4326')",
|
|
190
|
+
* }).log();
|
|
191
|
+
* ```
|
|
183
192
|
*/
|
|
184
193
|
setTypes(types: {
|
|
185
|
-
[key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | `geometry('${string}')` | `GEOMETRY('${string}')`;
|
|
194
|
+
[key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "json" | "JSON" | `float[${number}]` | `FLOAT[${number}]` | `geometry('${string}')` | `GEOMETRY('${string}')`;
|
|
186
195
|
}): this;
|
|
187
196
|
/**
|
|
188
|
-
* Loads an array of JavaScript objects into the table. Types
|
|
197
|
+
* Loads an array of JavaScript objects into the table. Types are inferred for
|
|
198
|
+
* numbers, bigints, strings, booleans, and Date values. Array and object cells
|
|
199
|
+
* require an explicit supported type in columnTypes. Types can also be
|
|
200
|
+
* specified for scalar columns instead of inferred from their values.
|
|
189
201
|
*
|
|
190
202
|
* JavaScript `Date` values are inferred as DuckDB `TIMESTAMP` values. Their
|
|
191
203
|
* instant is preserved, but JavaScript `Date` does not retain the timezone or
|
|
192
|
-
* offset originally used to construct it.
|
|
193
|
-
*
|
|
204
|
+
* offset originally used to construct it.
|
|
205
|
+
*
|
|
206
|
+
* Declare `JSON` for general nested data, `FLOAT[n]` for a fixed-size float
|
|
207
|
+
* vector, or `GEOMETRY('EPSG:4326')` for GeoJSON geometries in WGS84.
|
|
194
208
|
*
|
|
195
209
|
* @param rows - An array of objects, where each object represents a row and its properties represent columns.
|
|
196
210
|
* @param options - Options for loading the array, captured when called.
|
|
197
|
-
* @param options.columnTypes - Types for specific columns; omitted columns are inferred. Values must be compatible with the selected type without losing information.
|
|
211
|
+
* @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.
|
|
198
212
|
* @returns The table, so methods can be chained.
|
|
199
213
|
* @category Importing Data
|
|
200
214
|
*
|
|
201
215
|
* @example
|
|
202
216
|
* ```ts
|
|
203
|
-
* // Load
|
|
217
|
+
* // Load scalar columns without columnTypes; strings and numbers are inferred.
|
|
204
218
|
* const data = [
|
|
205
219
|
* { letter: "a", number: 1 },
|
|
206
220
|
* { letter: "b", number: 2 }
|
|
@@ -210,7 +224,7 @@ export default class SimpleTable extends Simple {
|
|
|
210
224
|
*
|
|
211
225
|
* @example
|
|
212
226
|
* ```ts
|
|
213
|
-
* //
|
|
227
|
+
* // Choose a numeric type when all-null values provide nothing to infer.
|
|
214
228
|
* await table.loadArray(
|
|
215
229
|
* [{ name: "A", value: null }, { name: "B", value: null }],
|
|
216
230
|
* { columnTypes: { value: "DOUBLE" } },
|
|
@@ -219,34 +233,62 @@ export default class SimpleTable extends Simple {
|
|
|
219
233
|
*
|
|
220
234
|
* @example
|
|
221
235
|
* ```ts
|
|
222
|
-
* //
|
|
223
|
-
* //
|
|
236
|
+
* // Store the Date as a UTC timestamp with JavaScript's millisecond precision.
|
|
237
|
+
* // The original -04:00 offset is not retained.
|
|
224
238
|
* await table.loadArray([{
|
|
225
239
|
* observedAt: new Date("2024-04-07T13:00:00-04:00"),
|
|
226
240
|
* }]).log();
|
|
227
241
|
* ```
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* // Declare JSON to load nested objects and variable-length arrays directly.
|
|
246
|
+
* await table.loadArray([{
|
|
247
|
+
* name: "Station",
|
|
248
|
+
* metadata: { active: true, tags: ["weather", "urban"] },
|
|
249
|
+
* measurements: [1, 2.5, null],
|
|
250
|
+
* }], { columnTypes: { metadata: "JSON", measurements: "JSON" } }).log();
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* // Declare FLOAT[3] to store each three-element array as a fixed-size vector.
|
|
256
|
+
* await table.loadArray([{ vector: [1, 2, 3] }], {
|
|
257
|
+
* columnTypes: { vector: "FLOAT[3]" },
|
|
258
|
+
* }).log();
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* // Declare a geometry type to store WGS84 GeoJSON as a spatial column.
|
|
264
|
+
* await table.loadArray([{
|
|
265
|
+
* name: "Montreal",
|
|
266
|
+
* geom: { type: "Point", coordinates: [-73.57, 45.50] },
|
|
267
|
+
* }], { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } }).log();
|
|
268
|
+
* ```
|
|
228
269
|
*/
|
|
229
270
|
loadArray(rows: {
|
|
230
271
|
[key: string]: unknown;
|
|
231
272
|
}[], options?: {
|
|
232
273
|
columnTypes?: {
|
|
233
|
-
[key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "INTEGER" | "BIGINT" | "DOUBLE" | "VARCHAR" | "BOOLEAN" | "DATE" | "TIME" | "TIMESTAMP" | "TIMESTAMP WITH TIME ZONE" | `FLOAT[${number}]` | `float[${number}]`;
|
|
274
|
+
[key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "INTEGER" | "BIGINT" | "DOUBLE" | "VARCHAR" | "BOOLEAN" | "DATE" | "TIME" | "TIMESTAMP" | "TIMESTAMP WITH TIME ZONE" | "GEOMETRY('EPSG:4326')" | "geometry('EPSG:4326')" | "JSON" | "json" | `FLOAT[${number}]` | `float[${number}]`;
|
|
234
275
|
};
|
|
235
276
|
}): this;
|
|
236
277
|
/**
|
|
237
278
|
* Loads data from one or more local or remote files into the table.
|
|
238
279
|
* Supported file formats include CSV, JSON, Parquet, and Excel.
|
|
239
|
-
*
|
|
280
|
+
*
|
|
281
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
240
282
|
*
|
|
241
283
|
* @param files - The path(s) or URL(s) of the file(s) containing the data to be loaded.
|
|
242
284
|
* @param options - An optional object with configuration options:
|
|
243
285
|
* @param options.fileType - The type of file to load ("csv", "dsv", "json", "parquet", "excel"). Defaults to being inferred from the file extension.
|
|
244
286
|
* @param options.autoDetect - A boolean indicating whether to automatically detect the data format. Defaults to `true`.
|
|
245
|
-
* @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before applying `limit`.
|
|
287
|
+
* @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`.
|
|
246
288
|
* @param options.limit - A number indicating the maximum number of matching rows to load, after applying `conditions` if provided. Defaults to all matching rows.
|
|
247
289
|
* @param options.includeFilename - A boolean indicating whether to include the filename as a new column in the loaded data. Defaults to `false`.
|
|
248
290
|
* @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`.
|
|
249
|
-
* @param options.columnTypes - An object mapping column names to their expected data types. By default, types are inferred.
|
|
291
|
+
* @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.
|
|
250
292
|
* @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.
|
|
251
293
|
* @param options.header - A boolean indicating whether the file has a header row. Applicable to CSV files. Defaults to `true`.
|
|
252
294
|
* @param options.allText - A boolean indicating whether all columns should be treated as text. Applicable to CSV files. Defaults to `false`.
|
|
@@ -343,8 +385,6 @@ export default class SimpleTable extends Simple {
|
|
|
343
385
|
}): this;
|
|
344
386
|
/**
|
|
345
387
|
* Downloads a complete Statistics Canada table and loads it into this table.
|
|
346
|
-
* The method queues the download and load; they run when an async observer
|
|
347
|
-
* method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
348
388
|
*
|
|
349
389
|
* Results are cached as Parquet files in `.sda-cache/statcan` by default.
|
|
350
390
|
* Cached data does not expire unless a TTL is provided.
|
|
@@ -399,9 +439,6 @@ export default class SimpleTable extends Simple {
|
|
|
399
439
|
* research, and journalistic purposes. Before using it, review Yahoo's terms
|
|
400
440
|
* and any applicable data-provider restrictions.
|
|
401
441
|
*
|
|
402
|
-
* The method queues the download and load; they run when an async observer
|
|
403
|
-
* method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
404
|
-
*
|
|
405
442
|
* @param symbol - The stock or index symbol, such as `"AAPL"` or `"^GSPTSE"`.
|
|
406
443
|
* @param startDate - The inclusive UTC start of the requested range.
|
|
407
444
|
* @param endDate - The inclusive UTC end of the requested range. The UTC day,
|
|
@@ -445,14 +482,13 @@ export default class SimpleTable extends Simple {
|
|
|
445
482
|
loadYahooFinanceData(symbol: string, startDate: Date, endDate: Date, interval: "1d" | "1h" | "1m"): this;
|
|
446
483
|
/**
|
|
447
484
|
* Loads geospatial data from an external file or URL into the table.
|
|
448
|
-
*
|
|
449
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
485
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
450
486
|
*
|
|
451
487
|
* @param file - The path or URL of the external file containing the geospatial data.
|
|
452
488
|
* @param options - An optional object with configuration options:
|
|
453
489
|
* @param options.toEPSG4326 - If `true`, the method will attempt to reproject the data to EPSG:4326 (WGS84).
|
|
454
490
|
* @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.
|
|
455
|
-
* @param options.conditions - A SQL `WHERE` clause expression, without the `WHERE` keyword, to filter source rows before materialization and reprojection.
|
|
491
|
+
* @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.
|
|
456
492
|
* @returns The table, so methods can be chained.
|
|
457
493
|
* @category Geospatial
|
|
458
494
|
*
|
|
@@ -507,7 +543,7 @@ export default class SimpleTable extends Simple {
|
|
|
507
543
|
conditions?: string;
|
|
508
544
|
}): this;
|
|
509
545
|
/**
|
|
510
|
-
* 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.
|
|
546
|
+
* 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.
|
|
511
547
|
*
|
|
512
548
|
* 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.
|
|
513
549
|
*
|
|
@@ -605,8 +641,6 @@ export default class SimpleTable extends Simple {
|
|
|
605
641
|
* DuckDB FTS indexes do not update automatically when the table changes; use
|
|
606
642
|
* `overwrite: true` to rebuild the index after modifying the table.
|
|
607
643
|
*
|
|
608
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
609
|
-
*
|
|
610
644
|
* @param idColumn - The column containing the document identifiers.
|
|
611
645
|
* @param textColumn - The column containing the text to search.
|
|
612
646
|
* @param options - An optional object with configuration options:
|
|
@@ -670,8 +704,6 @@ export default class SimpleTable extends Simple {
|
|
|
670
704
|
* 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`.
|
|
671
705
|
* The index definition is recorded in {@link indexes}.
|
|
672
706
|
*
|
|
673
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
674
|
-
*
|
|
675
707
|
* @param column - The name of the column containing vector embeddings (must be FLOAT array type).
|
|
676
708
|
* @param options - An optional object with configuration options:
|
|
677
709
|
* @param options.overwrite - If `true`, drops and recreates the index even if it already exists. Defaults to `false`.
|
|
@@ -735,8 +767,6 @@ export default class SimpleTable extends Simple {
|
|
|
735
767
|
* changes; use `overwriteIndex: true` to rebuild the index after modifying
|
|
736
768
|
* the table.
|
|
737
769
|
*
|
|
738
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
739
|
-
*
|
|
740
770
|
* @param text - The search query text to match against the text column.
|
|
741
771
|
* @param idColumn - The name of the column containing unique identifiers for each row.
|
|
742
772
|
* @param textColumn - The name of the column containing the text to search.
|
|
@@ -850,8 +880,6 @@ export default class SimpleTable extends Simple {
|
|
|
850
880
|
/**
|
|
851
881
|
* Inserts rows, provided as an array of JavaScript objects, into the table.
|
|
852
882
|
*
|
|
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
883
|
* @param rows - An array of objects, where each object represents a row to be inserted and its properties correspond to column names.
|
|
856
884
|
* @returns The table, so methods can be chained.
|
|
857
885
|
* @category Importing Data
|
|
@@ -870,7 +898,7 @@ export default class SimpleTable extends Simple {
|
|
|
870
898
|
[key: string]: unknown;
|
|
871
899
|
}[]): this;
|
|
872
900
|
/**
|
|
873
|
-
* 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`.
|
|
901
|
+
* 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`.
|
|
874
902
|
*
|
|
875
903
|
* @param tables - The name(s) of the table(s) or SimpleTable instance(s) from which rows will be inserted.
|
|
876
904
|
* @param options - An optional object with configuration options:
|
|
@@ -902,8 +930,6 @@ export default class SimpleTable extends Simple {
|
|
|
902
930
|
/**
|
|
903
931
|
* Fetches sample data from the simple-data-analysis-core GitHub repository.
|
|
904
932
|
*
|
|
905
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
906
|
-
*
|
|
907
933
|
* @param sample - The name of the sample to load.
|
|
908
934
|
*
|
|
909
935
|
* Tabular data:
|
|
@@ -927,13 +953,12 @@ export default class SimpleTable extends Simple {
|
|
|
927
953
|
loadSample(sample: "fires" | "recipes" | "temperatures" | "temperaturesCities" | "canada" | "firesGeo"): this;
|
|
928
954
|
/**
|
|
929
955
|
* 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.
|
|
956
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
930
957
|
*
|
|
931
958
|
* If `conditions`, `limit`, and `offset` are all used, they are applied in this order: `conditions` (WHERE clause) first, then `offset`, and finally `limit` (LIMIT).
|
|
932
959
|
*
|
|
933
960
|
* Note that cloning large tables can be a slow operation.
|
|
934
961
|
*
|
|
935
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
936
|
-
*
|
|
937
962
|
* @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.
|
|
938
963
|
* @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.
|
|
939
964
|
* @param nameOrOptions.conditions - A SQL `WHERE` clause condition to filter the data during cloning. Defaults to no condition (clones all rows).
|
|
@@ -1006,8 +1031,6 @@ export default class SimpleTable extends Simple {
|
|
|
1006
1031
|
/**
|
|
1007
1032
|
* Clones an existing column in this table, creating a new column with identical values.
|
|
1008
1033
|
*
|
|
1009
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1010
|
-
*
|
|
1011
1034
|
* @param column - The name of the original column to clone.
|
|
1012
1035
|
* @param newColumn - The name of the new column to be created.
|
|
1013
1036
|
* @returns The table, so methods can be chained.
|
|
@@ -1026,8 +1049,6 @@ export default class SimpleTable extends Simple {
|
|
|
1026
1049
|
*
|
|
1027
1050
|
* **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.
|
|
1028
1051
|
*
|
|
1029
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1030
|
-
*
|
|
1031
1052
|
* @param column - The name of the original column.
|
|
1032
1053
|
* @param newColumn - The name of the new column to be created with offset values.
|
|
1033
1054
|
* @param options - An optional object with configuration options:
|
|
@@ -1073,8 +1094,6 @@ export default class SimpleTable extends Simple {
|
|
|
1073
1094
|
/**
|
|
1074
1095
|
* 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`.
|
|
1075
1096
|
*
|
|
1076
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1077
|
-
*
|
|
1078
1097
|
* @param columns - The column(s) for which to fill `NULL` values.
|
|
1079
1098
|
* @param options - An optional object with configuration options:
|
|
1080
1099
|
* @param options.by - A column name or an array of column names to partition by. The fill is applied independently within each group.
|
|
@@ -1134,7 +1153,7 @@ export default class SimpleTable extends Simple {
|
|
|
1134
1153
|
* Sorts the rows of the table based on specified column(s) and order(s).
|
|
1135
1154
|
* If no columns are specified, all columns are sorted from left to right in ascending order.
|
|
1136
1155
|
*
|
|
1137
|
-
*
|
|
1156
|
+
* 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.
|
|
1138
1157
|
*
|
|
1139
1158
|
* @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.
|
|
1140
1159
|
* @param options - An optional object with configuration options:
|
|
@@ -1174,7 +1193,7 @@ export default class SimpleTable extends Simple {
|
|
|
1174
1193
|
};
|
|
1175
1194
|
}): this;
|
|
1176
1195
|
/**
|
|
1177
|
-
* Selects specific columns in the table, removing all others.
|
|
1196
|
+
* Selects specific columns in the table, removing all others.
|
|
1178
1197
|
*
|
|
1179
1198
|
* @param columns - The name or an array of names of the columns to be selected.
|
|
1180
1199
|
* @returns The table, so methods can be chained.
|
|
@@ -1196,8 +1215,6 @@ export default class SimpleTable extends Simple {
|
|
|
1196
1215
|
/**
|
|
1197
1216
|
* Skips the first `n` rows of the table, effectively removing them.
|
|
1198
1217
|
*
|
|
1199
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1200
|
-
*
|
|
1201
1218
|
* @param count - The number of rows to skip from the beginning of the table.
|
|
1202
1219
|
* @returns The table, so methods can be chained.
|
|
1203
1220
|
* @category Selecting or Filtering Data
|
|
@@ -1227,8 +1244,6 @@ export default class SimpleTable extends Simple {
|
|
|
1227
1244
|
/**
|
|
1228
1245
|
* Selects random rows from the table, removing all others. You can optionally specify a seed to ensure repeatable sampling.
|
|
1229
1246
|
*
|
|
1230
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1231
|
-
*
|
|
1232
1247
|
* @param count - The number of rows to select (e.g., `100`) or a percentage string (e.g., `"10%"`) specifying the sampling size.
|
|
1233
1248
|
* @param options - An optional object with configuration options:
|
|
1234
1249
|
* @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.
|
|
@@ -1259,8 +1274,6 @@ export default class SimpleTable extends Simple {
|
|
|
1259
1274
|
/**
|
|
1260
1275
|
* 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.
|
|
1261
1276
|
*
|
|
1262
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1263
|
-
*
|
|
1264
1277
|
* @param count - The number of rows to select.
|
|
1265
1278
|
* @param options - An optional object with configuration options:
|
|
1266
1279
|
* @param options.offset - The number of rows to skip from the beginning of the table before selecting. Defaults to `0`.
|
|
@@ -1300,8 +1313,6 @@ export default class SimpleTable extends Simple {
|
|
|
1300
1313
|
* Removes duplicate rows from this table, keeping only unique rows.
|
|
1301
1314
|
* Note that the resulting data order might differ from the original.
|
|
1302
1315
|
*
|
|
1303
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1304
|
-
*
|
|
1305
1316
|
* @param options - An optional object with configuration options:
|
|
1306
1317
|
* @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.
|
|
1307
1318
|
* @returns The table, so methods can be chained.
|
|
@@ -1331,7 +1342,6 @@ export default class SimpleTable extends Simple {
|
|
|
1331
1342
|
/**
|
|
1332
1343
|
* Removes rows with missing values from this table.
|
|
1333
1344
|
* By default, missing values include SQL `NULL`, as well as string representations like `"NULL"`, `"null"`, `"NaN"`, `"undefined"`, and empty strings `""`.
|
|
1334
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1335
1345
|
*
|
|
1336
1346
|
* @param options - An optional object with configuration options:
|
|
1337
1347
|
* @param options.columns - A string or an array of strings specifying the columns to consider for missing values. If omitted, all columns are considered.
|
|
@@ -1370,7 +1380,7 @@ export default class SimpleTable extends Simple {
|
|
|
1370
1380
|
invert?: boolean;
|
|
1371
1381
|
}): this;
|
|
1372
1382
|
/**
|
|
1373
|
-
* Trims specified characters from the beginning, end, or both sides of string values in the given columns.
|
|
1383
|
+
* Trims specified characters from the beginning, end, or both sides of string values in the given columns.
|
|
1374
1384
|
*
|
|
1375
1385
|
* @param columns - The column name or an array of column names to trim.
|
|
1376
1386
|
* @param options - An optional object with configuration options:
|
|
@@ -1403,8 +1413,7 @@ export default class SimpleTable extends Simple {
|
|
|
1403
1413
|
}): this;
|
|
1404
1414
|
/**
|
|
1405
1415
|
* Filters rows from this table based on SQL conditions. Note that it's often faster to use the `removeRows` method for simple removals.
|
|
1406
|
-
*
|
|
1407
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1416
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
1408
1417
|
*
|
|
1409
1418
|
* @param conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"column1 > 10 AND column2 = 'value'"`).
|
|
1410
1419
|
* @returns The table, so methods can be chained.
|
|
@@ -1438,8 +1447,6 @@ export default class SimpleTable extends Simple {
|
|
|
1438
1447
|
/**
|
|
1439
1448
|
* Keeps rows in this table that have specific values in specified columns, removing all other rows.
|
|
1440
1449
|
*
|
|
1441
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1442
|
-
*
|
|
1443
1450
|
* @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`.
|
|
1444
1451
|
* @returns The table, so methods can be chained.
|
|
1445
1452
|
* @category Selecting or Filtering Data
|
|
@@ -1468,8 +1475,6 @@ export default class SimpleTable extends Simple {
|
|
|
1468
1475
|
/**
|
|
1469
1476
|
* Removes rows from this table that have specific values in specified columns.
|
|
1470
1477
|
*
|
|
1471
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1472
|
-
*
|
|
1473
1478
|
* @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.
|
|
1474
1479
|
* @returns The table, so methods can be chained.
|
|
1475
1480
|
* @category Selecting or Filtering Data
|
|
@@ -1497,9 +1502,7 @@ export default class SimpleTable extends Simple {
|
|
|
1497
1502
|
}): this;
|
|
1498
1503
|
/**
|
|
1499
1504
|
* Removes rows from this table based on SQL conditions. This method is similar to `filter()`, but removes rows instead of keeping them.
|
|
1500
|
-
*
|
|
1501
|
-
*
|
|
1502
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1505
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
1503
1506
|
*
|
|
1504
1507
|
* @param conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"fruit = 'apple'"`).
|
|
1505
1508
|
* @returns The table, so methods can be chained.
|
|
@@ -1534,8 +1537,6 @@ export default class SimpleTable extends Simple {
|
|
|
1534
1537
|
* Renames one or more columns in the table. Throws if a source column does
|
|
1535
1538
|
* not exist, so a typo fails loudly instead of being silently ignored.
|
|
1536
1539
|
*
|
|
1537
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1538
|
-
*
|
|
1539
1540
|
* @param names - An object mapping old column names to their new column names (e.g., `{ "oldName": "newName", "anotherOld": "anotherNew" }`).
|
|
1540
1541
|
* @param options - Configuration options.
|
|
1541
1542
|
* @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.
|
|
@@ -1568,8 +1569,6 @@ export default class SimpleTable extends Simple {
|
|
|
1568
1569
|
/**
|
|
1569
1570
|
* Cleans column names by removing non-alphanumeric characters and formatting them to camel case.
|
|
1570
1571
|
*
|
|
1571
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1572
|
-
*
|
|
1573
1572
|
* @returns The table, so methods can be chained.
|
|
1574
1573
|
* @category Column Operations
|
|
1575
1574
|
*
|
|
@@ -1610,8 +1609,6 @@ export default class SimpleTable extends Simple {
|
|
|
1610
1609
|
* | Sales | 2022 | 75 |
|
|
1611
1610
|
* | Sales | 2023 | 98 |
|
|
1612
1611
|
*
|
|
1613
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1614
|
-
*
|
|
1615
1612
|
* @param columns - An array of strings representing the names of the columns to be stacked (unpivoted).
|
|
1616
1613
|
* @param namesTo - The name of the new column that will contain the original column names (e.g., "Year").
|
|
1617
1614
|
* @param valuesTo - The name of the new column that will contain the values from the stacked columns (e.g., "Employees").
|
|
@@ -1650,8 +1647,6 @@ export default class SimpleTable extends Simple {
|
|
|
1650
1647
|
*
|
|
1651
1648
|
* When multiple rows share the same `namesFrom`/grouping combination, their `valuesFrom` values are combined with the `options.stat` function (`"sum"` by default).
|
|
1652
1649
|
*
|
|
1653
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1654
|
-
*
|
|
1655
1650
|
* @param namesFrom - The name of the column containing the values that will be transformed into new column headers (e.g., "Year").
|
|
1656
1651
|
* @param valuesFrom - The name of the column containing the values to be spread across the new columns (e.g., "Employees").
|
|
1657
1652
|
* @param options - An optional object with configuration options:
|
|
@@ -1675,9 +1670,7 @@ export default class SimpleTable extends Simple {
|
|
|
1675
1670
|
*
|
|
1676
1671
|
* When converting strings to numbers, commas (often used as thousand separators) will be automatically removed before conversion.
|
|
1677
1672
|
*
|
|
1678
|
-
*
|
|
1679
|
-
*
|
|
1680
|
-
* @param types - An object mapping column names to their target data types for conversion.
|
|
1673
|
+
* @param types - An object mapping column names to their target data types for conversion, including JSON, FLOAT[n] vectors, and GEOMETRY with a CRS.
|
|
1681
1674
|
* @param options - An optional object with configuration options:
|
|
1682
1675
|
* @param options.strict - If `false`, values that cannot be converted will be replaced by `NULL` instead of throwing an error. Defaults to `true`.
|
|
1683
1676
|
* @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).
|
|
@@ -1724,9 +1717,21 @@ export default class SimpleTable extends Simple {
|
|
|
1724
1717
|
* // Convert 'amount' to float, replacing unconvertible values with NULL
|
|
1725
1718
|
* await table.convert({ amount: "float" }, { strict: false }).log();
|
|
1726
1719
|
* ```
|
|
1720
|
+
*
|
|
1721
|
+
* @example
|
|
1722
|
+
* ```ts
|
|
1723
|
+
* // Parse JSON, a fixed-size float vector, and WKT geometry from text.
|
|
1724
|
+
* await table.loadArray([{
|
|
1725
|
+
* details: '{"count":3}',
|
|
1726
|
+
* embedding: "[0.25,0.5,0.75]",
|
|
1727
|
+
* geom: "POINT (-73 45)",
|
|
1728
|
+
* }])
|
|
1729
|
+
* .convert({ details: "JSON", embedding: "FLOAT[3]", geom: "GEOMETRY('EPSG:4326')" })
|
|
1730
|
+
* .log();
|
|
1731
|
+
* ```
|
|
1727
1732
|
*/
|
|
1728
1733
|
convert(types: {
|
|
1729
|
-
[key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean"
|
|
1734
|
+
[key: string]: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "json" | "JSON" | `float[${number}]` | `FLOAT[${number}]` | `geometry('${string}')` | `GEOMETRY('${string}')`;
|
|
1730
1735
|
}, options?: {
|
|
1731
1736
|
strict?: boolean;
|
|
1732
1737
|
datetimeFormat?: string;
|
|
@@ -1745,7 +1750,7 @@ export default class SimpleTable extends Simple {
|
|
|
1745
1750
|
*/
|
|
1746
1751
|
removeTable(): Promise<this>;
|
|
1747
1752
|
/**
|
|
1748
|
-
* Removes one or more columns from this table.
|
|
1753
|
+
* Removes one or more columns from this table.
|
|
1749
1754
|
*
|
|
1750
1755
|
* @param columns - The name or an array of names of the columns to be removed.
|
|
1751
1756
|
* @returns The table, so methods can be chained.
|
|
@@ -1765,10 +1770,11 @@ export default class SimpleTable extends Simple {
|
|
|
1765
1770
|
*/
|
|
1766
1771
|
removeColumns(columns: string | string[]): this;
|
|
1767
1772
|
/**
|
|
1768
|
-
* Adds a new column to the table based on a specified data type (JavaScript or SQL types) and a SQL definition.
|
|
1773
|
+
* Adds a new column to the table based on a specified data type (JavaScript or SQL types) and a SQL definition.
|
|
1774
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, expressions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
1769
1775
|
*
|
|
1770
1776
|
* @param newColumn - The name of the new column to be added.
|
|
1771
|
-
* @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"`).
|
|
1777
|
+
* @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')"`).
|
|
1772
1778
|
* @param definition - A SQL expression defining how the values for the new column should be computed (e.g., `"column1 + column2"`, `"ST_Centroid(geom_column)"`).
|
|
1773
1779
|
* @returns The table, so methods can be chained.
|
|
1774
1780
|
* @category Column Operations
|
|
@@ -1784,8 +1790,27 @@ export default class SimpleTable extends Simple {
|
|
|
1784
1790
|
* // Add a new geometry column 'centroid' using the centroid of an existing 'country' geometry column
|
|
1785
1791
|
* await table.addColumn("centroid", "geometry('EPSG:4326')", `ST_Centroid("country")`).log();
|
|
1786
1792
|
* ```
|
|
1793
|
+
*
|
|
1794
|
+
* @example
|
|
1795
|
+
* ```ts
|
|
1796
|
+
* // Read a number from a JSON object into a new column using dot notation.
|
|
1797
|
+
* await table.loadArray([{ details: { count: 3 } }], {
|
|
1798
|
+
* columnTypes: { details: "JSON" },
|
|
1799
|
+
* })
|
|
1800
|
+
* .addColumn("count", "integer", "details.count")
|
|
1801
|
+
* .log();
|
|
1802
|
+
* ```
|
|
1803
|
+
*
|
|
1804
|
+
* @example
|
|
1805
|
+
* ```ts
|
|
1806
|
+
* // Create JSON and fixed-size vector columns with DuckDB expressions.
|
|
1807
|
+
* await table.loadArray([{ count: 3 }])
|
|
1808
|
+
* .addColumn("details", "JSON", "json_object('count', count)")
|
|
1809
|
+
* .addColumn("embedding", "FLOAT[3]", "[0.25, 0.5, 0.75]")
|
|
1810
|
+
* .log();
|
|
1811
|
+
* ```
|
|
1787
1812
|
*/
|
|
1788
|
-
addColumn(newColumn: string, type: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | `geometry('${string}')` | `GEOMETRY('${string}')`, definition: string): this;
|
|
1813
|
+
addColumn(newColumn: string, type: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "json" | "JSON" | `float[${number}]` | `FLOAT[${number}]` | `geometry('${string}')` | `GEOMETRY('${string}')`, definition: string): this;
|
|
1789
1814
|
/**
|
|
1790
1815
|
* Extracts one or more components from a temporal column into new columns.
|
|
1791
1816
|
* Pass a single part to create a column with that part's name, or pass an
|
|
@@ -1800,9 +1825,6 @@ export default class SimpleTable extends Simple {
|
|
|
1800
1825
|
* values produce `NULL` extracted values. Parts extracted from
|
|
1801
1826
|
* `TIMESTAMP WITH TIME ZONE` values use UTC.
|
|
1802
1827
|
*
|
|
1803
|
-
* This method queues the operation; it runs when an async observer method
|
|
1804
|
-
* (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1805
|
-
*
|
|
1806
1828
|
* @param column - The temporal column from which to extract components.
|
|
1807
1829
|
* @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.
|
|
1808
1830
|
* @returns The table, so methods can be chained.
|
|
@@ -1829,8 +1851,6 @@ export default class SimpleTable extends Simple {
|
|
|
1829
1851
|
/**
|
|
1830
1852
|
* Adds a new column to the table containing the row number, starting at 0 (like an index).
|
|
1831
1853
|
*
|
|
1832
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1833
|
-
*
|
|
1834
1854
|
* @param newColumn - The name of the new column that will store the row number.
|
|
1835
1855
|
* @param options - An optional object with configuration options:
|
|
1836
1856
|
* @param options.by - A column name or an array of column names to partition by. The row number restarts at 0 within each group.
|
|
@@ -1856,8 +1876,6 @@ export default class SimpleTable extends Simple {
|
|
|
1856
1876
|
* 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.
|
|
1857
1877
|
* This means that if the left table has `n` rows and the right table has `m` rows, the result will have `n * m` rows.
|
|
1858
1878
|
*
|
|
1859
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
1860
|
-
*
|
|
1861
1879
|
* @param rightTable - The SimpleTable instance to cross join with.
|
|
1862
1880
|
* @param options - An optional object with configuration options:
|
|
1863
1881
|
* @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`.
|
|
@@ -1889,7 +1907,6 @@ export default class SimpleTable extends Simple {
|
|
|
1889
1907
|
* Merges the data of this table (considered the left table) with another table (the right table) based on a common column or multiple columns.
|
|
1890
1908
|
* Note that the order of rows in the returned data is not guaranteed to be the same as in the original tables.
|
|
1891
1909
|
* This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
|
|
1892
|
-
* 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.
|
|
1893
1910
|
*
|
|
1894
1911
|
* @param rightTable - The SimpleTable instance to be joined with this table.
|
|
1895
1912
|
* @param options - An optional object with configuration options:
|
|
@@ -1931,8 +1948,6 @@ export default class SimpleTable extends Simple {
|
|
|
1931
1948
|
*
|
|
1932
1949
|
* This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
|
|
1933
1950
|
*
|
|
1934
|
-
* 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.
|
|
1935
|
-
*
|
|
1936
1951
|
* @param rightTable - The SimpleTable instance to be joined with this table.
|
|
1937
1952
|
* @param leftColumn - The name of the column in this (left) table containing the text to compare.
|
|
1938
1953
|
* @param rightColumn - The name of the column in the right table containing the text to compare.
|
|
@@ -1997,8 +2012,6 @@ export default class SimpleTable extends Simple {
|
|
|
1997
2012
|
* Similarity is computed using the [rapidfuzz](https://query.farm/duckdb_extension_rapidfuzz) DuckDB community extension,
|
|
1998
2013
|
* which is installed and loaded automatically.
|
|
1999
2014
|
*
|
|
2000
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2001
|
-
*
|
|
2002
2015
|
* @param column - The name of the column containing the strings to normalize.
|
|
2003
2016
|
* @param newColumn - The name of the column to write the normalized values to. Use the same name as `column` to normalize in-place.
|
|
2004
2017
|
* @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.
|
|
@@ -2053,8 +2066,6 @@ export default class SimpleTable extends Simple {
|
|
|
2053
2066
|
/**
|
|
2054
2067
|
* Replaces specified strings in the selected columns.
|
|
2055
2068
|
*
|
|
2056
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2057
|
-
*
|
|
2058
2069
|
* @param columns - The column name, an array of column names, or `"all"` to apply the replacement to every column in the table.
|
|
2059
2070
|
* @param replacements - An object mapping old strings to new strings (e.g., `{ "oldValue": "newValue" }`).
|
|
2060
2071
|
* @param options - An optional object with configuration options:
|
|
@@ -2100,7 +2111,7 @@ export default class SimpleTable extends Simple {
|
|
|
2100
2111
|
regex?: boolean;
|
|
2101
2112
|
}): this;
|
|
2102
2113
|
/**
|
|
2103
|
-
* Converts string values in the specified columns to lowercase.
|
|
2114
|
+
* Converts string values in the specified columns to lowercase.
|
|
2104
2115
|
*
|
|
2105
2116
|
* @param columns - The column name or an array of column names to be converted to lowercase.
|
|
2106
2117
|
* @returns The table, so methods can be chained.
|
|
@@ -2120,7 +2131,7 @@ export default class SimpleTable extends Simple {
|
|
|
2120
2131
|
*/
|
|
2121
2132
|
lower(columns: string | string[]): this;
|
|
2122
2133
|
/**
|
|
2123
|
-
* Converts string values in the specified columns to uppercase.
|
|
2134
|
+
* Converts string values in the specified columns to uppercase.
|
|
2124
2135
|
*
|
|
2125
2136
|
* @param columns - The column name or an array of column names to be converted to uppercase.
|
|
2126
2137
|
* @returns The table, so methods can be chained.
|
|
@@ -2140,7 +2151,7 @@ export default class SimpleTable extends Simple {
|
|
|
2140
2151
|
*/
|
|
2141
2152
|
upper(columns: string | string[]): this;
|
|
2142
2153
|
/**
|
|
2143
|
-
* Capitalizes the first letter of each string in the specified columns and converts the rest of the string to lowercase.
|
|
2154
|
+
* Capitalizes the first letter of each string in the specified columns and converts the rest of the string to lowercase.
|
|
2144
2155
|
*
|
|
2145
2156
|
* @param columns - The column name or an array of column names to be capitalized.
|
|
2146
2157
|
* @returns The table, so methods can be chained.
|
|
@@ -2162,8 +2173,6 @@ export default class SimpleTable extends Simple {
|
|
|
2162
2173
|
/**
|
|
2163
2174
|
* Truncates string values in a specified column to a maximum number of characters.
|
|
2164
2175
|
*
|
|
2165
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2166
|
-
*
|
|
2167
2176
|
* @param column - The column name containing strings to be truncated.
|
|
2168
2177
|
* @param length - The maximum number of characters to keep.
|
|
2169
2178
|
* @returns The table, so methods can be chained.
|
|
@@ -2189,8 +2198,6 @@ export default class SimpleTable extends Simple {
|
|
|
2189
2198
|
* column is of a different type. `null` values remain `null`. If any string
|
|
2190
2199
|
* already exceeds the target length, an error is thrown (no silent truncation).
|
|
2191
2200
|
*
|
|
2192
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2193
|
-
*
|
|
2194
2201
|
* @param columns - The column name(s) containing strings to be padded.
|
|
2195
2202
|
* @param length - The target length of the padded strings.
|
|
2196
2203
|
* @param options - An optional object with configuration options:
|
|
@@ -2230,8 +2237,6 @@ export default class SimpleTable extends Simple {
|
|
|
2230
2237
|
* 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.
|
|
2231
2238
|
* If the index is out of bounds, an empty string will be returned for that row.
|
|
2232
2239
|
*
|
|
2233
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2234
|
-
*
|
|
2235
2240
|
* @param column - The name of the column containing the strings to be split.
|
|
2236
2241
|
* @param separator - The substring to use as a delimiter for splitting the strings.
|
|
2237
2242
|
* @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.
|
|
@@ -2261,8 +2266,6 @@ export default class SimpleTable extends Simple {
|
|
|
2261
2266
|
* 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`).
|
|
2262
2267
|
* If a row has more parts than the number of new columns, an error will be thrown unless `strict` is set to `false`.
|
|
2263
2268
|
*
|
|
2264
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2265
|
-
*
|
|
2266
2269
|
* @param column - The name of the column containing the strings to be split.
|
|
2267
2270
|
* @param separator - The substring to use as a delimiter for splitting the strings.
|
|
2268
2271
|
* @param newColumns - An array of column names for the extracted parts.
|
|
@@ -2297,8 +2300,6 @@ export default class SimpleTable extends Simple {
|
|
|
2297
2300
|
/**
|
|
2298
2301
|
* Extracts a specific number of characters from the beginning (left side) of string values in the specified column.
|
|
2299
2302
|
*
|
|
2300
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2301
|
-
*
|
|
2302
2303
|
* @param column - The name of the column containing the strings to be modified.
|
|
2303
2304
|
* @param count - The number of characters to extract from the left side of each string.
|
|
2304
2305
|
* @returns The table, so methods can be chained.
|
|
@@ -2315,8 +2316,6 @@ export default class SimpleTable extends Simple {
|
|
|
2315
2316
|
/**
|
|
2316
2317
|
* Extracts a specific number of characters from the end (right side) of string values in the specified column.
|
|
2317
2318
|
*
|
|
2318
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2319
|
-
*
|
|
2320
2319
|
* @param column - The name of the column containing the strings to be modified.
|
|
2321
2320
|
* @param count - The number of characters to extract from the right side of each string.
|
|
2322
2321
|
* @returns The table, so methods can be chained.
|
|
@@ -2333,8 +2332,6 @@ export default class SimpleTable extends Simple {
|
|
|
2333
2332
|
/**
|
|
2334
2333
|
* Replaces `NULL` values in the specified columns with a given value.
|
|
2335
2334
|
*
|
|
2336
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2337
|
-
*
|
|
2338
2335
|
* @param columns - The column name, an array of column names, or `"all"` to apply the replacement to every column in the table.
|
|
2339
2336
|
* @param value - The value to replace `NULL` occurrences with.
|
|
2340
2337
|
* @returns The table, so methods can be chained.
|
|
@@ -2368,8 +2365,6 @@ export default class SimpleTable extends Simple {
|
|
|
2368
2365
|
/**
|
|
2369
2366
|
* Concatenates values from specified columns into a new column.
|
|
2370
2367
|
*
|
|
2371
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2372
|
-
*
|
|
2373
2368
|
* @param columns - An array of column names whose values will be concatenated.
|
|
2374
2369
|
* @param newColumn - The name of the new column to store the concatenated values.
|
|
2375
2370
|
* @param options - An optional object with configuration options:
|
|
@@ -2403,8 +2398,6 @@ export default class SimpleTable extends Simple {
|
|
|
2403
2398
|
*
|
|
2404
2399
|
* If a column value is `NULL`, it will be replaced by `'Unknown'` in the concatenated result.
|
|
2405
2400
|
*
|
|
2406
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2407
|
-
*
|
|
2408
2401
|
* @param columns - An array of column names whose values will be concatenated with labels.
|
|
2409
2402
|
* @param newColumn - The name of the new column to create with the concatenated values.
|
|
2410
2403
|
* @returns The table, so methods can be chained.
|
|
@@ -2449,8 +2442,6 @@ export default class SimpleTable extends Simple {
|
|
|
2449
2442
|
*
|
|
2450
2443
|
* 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.
|
|
2451
2444
|
*
|
|
2452
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2453
|
-
*
|
|
2454
2445
|
* @param column - The name of the column containing string values to be split and unnested.
|
|
2455
2446
|
* @param separator - The delimiter string used to split the column values.
|
|
2456
2447
|
* @returns The table, so methods can be chained.
|
|
@@ -2480,8 +2471,6 @@ export default class SimpleTable extends Simple {
|
|
|
2480
2471
|
*
|
|
2481
2472
|
* 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.
|
|
2482
2473
|
*
|
|
2483
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2484
|
-
*
|
|
2485
2474
|
* @param column - The name of the column containing the number of times each row should be repeated.
|
|
2486
2475
|
* @param options - An optional object with configuration options:
|
|
2487
2476
|
* @param options.index - The name of a new column to store the index of the repeated row (starting at 0).
|
|
@@ -2512,8 +2501,6 @@ export default class SimpleTable extends Simple {
|
|
|
2512
2501
|
*
|
|
2513
2502
|
* 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.
|
|
2514
2503
|
*
|
|
2515
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2516
|
-
*
|
|
2517
2504
|
* @param column - The name of the column whose values will be aggregated and concatenated.
|
|
2518
2505
|
* @param separator - The delimiter string used to join the column values.
|
|
2519
2506
|
* @param by - The column name or an array of column names to group by.
|
|
@@ -2543,8 +2530,6 @@ export default class SimpleTable extends Simple {
|
|
|
2543
2530
|
/**
|
|
2544
2531
|
* Rounds numeric values in specified columns.
|
|
2545
2532
|
*
|
|
2546
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2547
|
-
*
|
|
2548
2533
|
* @param columns - The column name or an array of column names containing numeric values to be rounded.
|
|
2549
2534
|
* @param options - An optional integer specifying the number of decimal places, or an object with configuration options:
|
|
2550
2535
|
* @param options.decimals - The number of decimal places to round to. Defaults to `0` (rounds to the nearest integer).
|
|
@@ -2590,8 +2575,6 @@ export default class SimpleTable extends Simple {
|
|
|
2590
2575
|
* Adds independently generated uniform random noise to numeric values in one or more columns.
|
|
2591
2576
|
* 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.
|
|
2592
2577
|
*
|
|
2593
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2594
|
-
*
|
|
2595
2578
|
* @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.
|
|
2596
2579
|
* @param max - The maximum absolute offset, expressed in each column's units. Must be a finite number greater than or equal to `0`.
|
|
2597
2580
|
* @param options - An optional object with configuration options:
|
|
@@ -2618,8 +2601,7 @@ export default class SimpleTable extends Simple {
|
|
|
2618
2601
|
}): this;
|
|
2619
2602
|
/**
|
|
2620
2603
|
* Updates values in a specified column using a SQL expression.
|
|
2621
|
-
*
|
|
2622
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2604
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, expressions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
2623
2605
|
*
|
|
2624
2606
|
* @param column - The name of the column to be updated.
|
|
2625
2607
|
* @param definition - The SQL expression used to set the new values in the column (e.g., `"column1 * 2"`, `"UPPER(column_name)"`).
|
|
@@ -2643,13 +2625,21 @@ export default class SimpleTable extends Simple {
|
|
|
2643
2625
|
* // Set 'status' to 'active' where 'isActive' is true
|
|
2644
2626
|
* await table.updateColumn("status", `CASE WHEN isActive THEN 'active' ELSE 'inactive' END`).log();
|
|
2645
2627
|
* ```
|
|
2628
|
+
*
|
|
2629
|
+
* @example
|
|
2630
|
+
* ```ts
|
|
2631
|
+
* // Update an existing column with a value from a JSON object using dot notation.
|
|
2632
|
+
* await table.loadArray([{ count: 0, details: { count: 3 } }], {
|
|
2633
|
+
* columnTypes: { details: "JSON" },
|
|
2634
|
+
* })
|
|
2635
|
+
* .updateColumn("count", "details.count")
|
|
2636
|
+
* .log();
|
|
2637
|
+
* ```
|
|
2646
2638
|
*/
|
|
2647
2639
|
updateColumn(column: string, definition: string): this;
|
|
2648
2640
|
/**
|
|
2649
2641
|
* Assigns ranks to rows in a new column based on the values of a specified column.
|
|
2650
2642
|
*
|
|
2651
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2652
|
-
*
|
|
2653
2643
|
* @param column - The column containing the values to be used for ranking.
|
|
2654
2644
|
* @param newColumn - The name of the new column where the ranks will be stored.
|
|
2655
2645
|
* @param options - An optional object with configuration options:
|
|
@@ -2691,8 +2681,6 @@ export default class SimpleTable extends Simple {
|
|
|
2691
2681
|
/**
|
|
2692
2682
|
* Assigns quantiles to rows in a new column based on specified column values.
|
|
2693
2683
|
*
|
|
2694
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2695
|
-
*
|
|
2696
2684
|
* @param column - The column containing values from which quantiles will be assigned.
|
|
2697
2685
|
* @param count - The number of quantiles to divide the data into (e.g., `4` for quartiles, `10` for deciles).
|
|
2698
2686
|
* @param newColumn - The name of the new column where the assigned quantiles will be stored.
|
|
@@ -2725,8 +2713,6 @@ export default class SimpleTable extends Simple {
|
|
|
2725
2713
|
/**
|
|
2726
2714
|
* Assigns bins for specified column values based on an interval size.
|
|
2727
2715
|
*
|
|
2728
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2729
|
-
*
|
|
2730
2716
|
* @param column - The column containing values from which bins will be computed.
|
|
2731
2717
|
* @param interval - The interval size for binning the values.
|
|
2732
2718
|
* @param newColumn - The name of the new column where the bins will be stored.
|
|
@@ -2801,8 +2787,6 @@ export default class SimpleTable extends Simple {
|
|
|
2801
2787
|
* await table.rowProportions(["Men", "Women", "NonBinary"], { base: 100, decimals: 1 }).log();
|
|
2802
2788
|
* ```
|
|
2803
2789
|
*
|
|
2804
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2805
|
-
*
|
|
2806
2790
|
* @param columns - An array of column names for which proportions will be computed on each row.
|
|
2807
2791
|
* @param options - An optional object with configuration options:
|
|
2808
2792
|
* @param options.suffix - A string suffix to append to the names of the new columns storing the computed proportions. Defaults to `"Perc"`.
|
|
@@ -2827,9 +2811,6 @@ export default class SimpleTable extends Simple {
|
|
|
2827
2811
|
* option can therefore increase the table's row count. If null values leave
|
|
2828
2812
|
* a row without the requested rank, the new columns contain null.
|
|
2829
2813
|
*
|
|
2830
|
-
* This method queues the operation; it runs when an async observer method
|
|
2831
|
-
* (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2832
|
-
*
|
|
2833
2814
|
* @param columns - The numeric columns to rank within each row.
|
|
2834
2815
|
* @param options - The output columns and ranking configuration. At least one of `nameColumn` or `valueColumn` is required.
|
|
2835
2816
|
* @param options.nameColumn - The name of a new column containing the selected source column's name.
|
|
@@ -2930,8 +2911,6 @@ export default class SimpleTable extends Simple {
|
|
|
2930
2911
|
/**
|
|
2931
2912
|
* Computes proportions vertically over a column's values, relative to the sum of all values in that column or group.
|
|
2932
2913
|
*
|
|
2933
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2934
|
-
*
|
|
2935
2914
|
* @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.
|
|
2936
2915
|
* @param newColumn - The name of the new column where the proportions will be stored.
|
|
2937
2916
|
* @param options - An optional object with configuration options:
|
|
@@ -2974,8 +2953,6 @@ export default class SimpleTable extends Simple {
|
|
|
2974
2953
|
* Creates a summary table from selected columns, optionally grouped by other columns.
|
|
2975
2954
|
* This method allows you to aggregate data, calculate statistics (e.g., count, mean, sum), and group results by categorical columns.
|
|
2976
2955
|
*
|
|
2977
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
2978
|
-
*
|
|
2979
2956
|
* @param options - An object with configuration options for summarization:
|
|
2980
2957
|
* @param options.columns - The column name or an array of column names to summarize. If omitted, only the row count is returned.
|
|
2981
2958
|
* @param options.by - The column name or an array of column names to group by.
|
|
@@ -3081,9 +3058,6 @@ export default class SimpleTable extends Simple {
|
|
|
3081
3058
|
* string is also used as its row label; pass an object to customize that
|
|
3082
3059
|
* label. If `options.stats` is omitted, every supported stat is added.
|
|
3083
3060
|
*
|
|
3084
|
-
* This method queues the operation; it runs when an async observer method
|
|
3085
|
-
* (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3086
|
-
*
|
|
3087
3061
|
* @param columns - The numeric column name, an array of numeric column names, or `"all"` to summarize every numeric column.
|
|
3088
3062
|
* @param labelColumn - The existing string column in which stat row labels will be written.
|
|
3089
3063
|
* @param options - An optional object with configuration options:
|
|
@@ -3131,8 +3105,6 @@ export default class SimpleTable extends Simple {
|
|
|
3131
3105
|
/**
|
|
3132
3106
|
* Computes the cumulative sum of values in a column. For this method to work properly, ensure your data is sorted first.
|
|
3133
3107
|
*
|
|
3134
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3135
|
-
*
|
|
3136
3108
|
* @param column - The name of the column storing the values to be accumulated.
|
|
3137
3109
|
* @param newColumn - The name of the new column in which the computed cumulative values will be stored.
|
|
3138
3110
|
* @param options - An optional object with configuration options:
|
|
@@ -3168,8 +3140,6 @@ export default class SimpleTable extends Simple {
|
|
|
3168
3140
|
* For rows without enough preceding or following rows to form a complete window, `NULL` will be returned.
|
|
3169
3141
|
* For this method to work properly, ensure your data is sorted by the relevant column(s) first.
|
|
3170
3142
|
*
|
|
3171
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3172
|
-
*
|
|
3173
3143
|
* @param column - The name of the column storing the values to be aggregated.
|
|
3174
3144
|
* @param newColumn - The name of the new column in which the computed rolling values will be stored.
|
|
3175
3145
|
* @param stat - The aggregation function to apply: `"min"`, `"max"`, `"mean"`, `"median"`, or `"sum"`.
|
|
@@ -3208,8 +3178,6 @@ export default class SimpleTable extends Simple {
|
|
|
3208
3178
|
* Calculates correlations between columns. If no `x` and `y` columns are specified, the method computes the correlations for all numeric column combinations.
|
|
3209
3179
|
* Note that correlation is symmetrical: the correlation of `x` with `y` is the same as `y` with `x`.
|
|
3210
3180
|
*
|
|
3211
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3212
|
-
*
|
|
3213
3181
|
* @param options - An optional object with configuration options:
|
|
3214
3182
|
* @param options.x - The name of the column for the x-values. If omitted, correlations will be computed for all numeric columns.
|
|
3215
3183
|
* @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.
|
|
@@ -3261,8 +3229,6 @@ export default class SimpleTable extends Simple {
|
|
|
3261
3229
|
* If no `x` and `y` columns are specified, the method computes linear regression analysis for all numeric column permutations.
|
|
3262
3230
|
* Note that linear regression analysis is asymmetrical: the linear regression of `x` over `y` is not the same as `y` over `x`.
|
|
3263
3231
|
*
|
|
3264
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3265
|
-
*
|
|
3266
3232
|
* @param options - An optional object with configuration options:
|
|
3267
3233
|
* @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.
|
|
3268
3234
|
* @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.
|
|
@@ -3312,8 +3278,6 @@ export default class SimpleTable extends Simple {
|
|
|
3312
3278
|
/**
|
|
3313
3279
|
* Identifies outliers in a specified column using the Interquartile Range (IQR) method.
|
|
3314
3280
|
*
|
|
3315
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3316
|
-
*
|
|
3317
3281
|
* @param column - The name of the column in which outliers will be identified.
|
|
3318
3282
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for outlier, `FALSE` otherwise) will be stored.
|
|
3319
3283
|
* @param options - An optional object with configuration options:
|
|
@@ -3339,8 +3303,6 @@ export default class SimpleTable extends Simple {
|
|
|
3339
3303
|
/**
|
|
3340
3304
|
* Computes the Z-score for values in a specified column.
|
|
3341
3305
|
*
|
|
3342
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3343
|
-
*
|
|
3344
3306
|
* @param column - The name of the column for which Z-scores will be calculated.
|
|
3345
3307
|
* @param newColumn - The name of the new column where the computed Z-scores will be stored.
|
|
3346
3308
|
* @param options - An optional object with configuration options:
|
|
@@ -3374,8 +3336,6 @@ export default class SimpleTable extends Simple {
|
|
|
3374
3336
|
/**
|
|
3375
3337
|
* Normalizes the values in a column using min-max normalization.
|
|
3376
3338
|
*
|
|
3377
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3378
|
-
*
|
|
3379
3339
|
* @param column - The name of the column in which values will be normalized.
|
|
3380
3340
|
* @param newColumn - The name of the new column where normalized values will be stored.
|
|
3381
3341
|
* @param options - An optional object with configuration options:
|
|
@@ -3421,8 +3381,6 @@ export default class SimpleTable extends Simple {
|
|
|
3421
3381
|
*
|
|
3422
3382
|
* 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.
|
|
3423
3383
|
*
|
|
3424
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3425
|
-
*
|
|
3426
3384
|
* @param column - The numeric column containing the values to index.
|
|
3427
3385
|
* @param newColumn - The name of the new column where indexed values will be stored.
|
|
3428
3386
|
* @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.
|
|
@@ -3496,48 +3454,84 @@ export default class SimpleTable extends Simple {
|
|
|
3496
3454
|
/**
|
|
3497
3455
|
* 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.
|
|
3498
3456
|
* This method offers high flexibility for data manipulation but can be slow for large tables as it involves transferring data between DuckDB and JavaScript.
|
|
3499
|
-
*
|
|
3457
|
+
* Before writing a JavaScript callback, check for an existing SDA method that
|
|
3458
|
+
* performs the same operation; it will usually be faster and more efficient.
|
|
3500
3459
|
*
|
|
3501
|
-
*
|
|
3460
|
+
* If the table has geometry columns, the callback can read and modify their
|
|
3461
|
+
* GeoJSON geometry objects directly. Extra properties added to these objects
|
|
3462
|
+
* are ignored; create new columns on the returned rows to store additional
|
|
3463
|
+
* attributes. All geometry columns must use EPSG:4326; use reproject() first
|
|
3464
|
+
* if needed.
|
|
3502
3465
|
*
|
|
3503
3466
|
* @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).
|
|
3504
3467
|
* @param options - An optional object with configuration options:
|
|
3505
|
-
* @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.
|
|
3468
|
+
* @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.
|
|
3469
|
+
* @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.
|
|
3506
3470
|
* @returns The table, so methods can be chained.
|
|
3507
3471
|
* @category Updating Data
|
|
3508
3472
|
*
|
|
3509
3473
|
* @example
|
|
3510
3474
|
* ```ts
|
|
3511
|
-
* //
|
|
3512
|
-
*
|
|
3513
|
-
* .
|
|
3514
|
-
*
|
|
3515
|
-
*
|
|
3516
|
-
* return rows.map((row) => ({
|
|
3517
|
-
* ...row,
|
|
3518
|
-
* hostname: typeof row.url === "string"
|
|
3519
|
-
* ? new URL(row.url).hostname
|
|
3520
|
-
* : null,
|
|
3521
|
-
* }));
|
|
3522
|
-
* })
|
|
3475
|
+
* // Double the value in each row with a JavaScript callback.
|
|
3476
|
+
* await table.loadArray([{ value: 1 }, { value: 2 }])
|
|
3477
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3478
|
+
* value: Number(row.value) * 2,
|
|
3479
|
+
* })))
|
|
3523
3480
|
* .log();
|
|
3524
3481
|
* ```
|
|
3525
3482
|
*
|
|
3526
3483
|
* @example
|
|
3527
3484
|
* ```ts
|
|
3528
|
-
* //
|
|
3529
|
-
*
|
|
3530
|
-
* .updateWithJS(
|
|
3531
|
-
*
|
|
3532
|
-
*
|
|
3533
|
-
*
|
|
3534
|
-
*
|
|
3535
|
-
*
|
|
3536
|
-
*
|
|
3537
|
-
*
|
|
3538
|
-
*
|
|
3485
|
+
* // Process two rows per callback to limit how many rows are handled at once.
|
|
3486
|
+
* await table.loadArray([{ value: 1 }, { value: 2 }, { value: 3 }])
|
|
3487
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3488
|
+
* value: Number(row.value) * 2,
|
|
3489
|
+
* })), { batchSize: 2 })
|
|
3490
|
+
* .log();
|
|
3491
|
+
* ```
|
|
3492
|
+
*
|
|
3493
|
+
* @example
|
|
3494
|
+
* ```ts
|
|
3495
|
+
* // Add a JSON object column to keep related attributes together.
|
|
3496
|
+
* await table.loadArray([{ name: "Station" }])
|
|
3497
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3498
|
+
* ...row, details: { active: true, category: "weather" },
|
|
3499
|
+
* })), { columnTypes: { details: "JSON" } })
|
|
3500
|
+
* .log();
|
|
3501
|
+
* ```
|
|
3502
|
+
*
|
|
3503
|
+
* @example
|
|
3504
|
+
* ```ts
|
|
3505
|
+
* // Add a three-element float vector, such as an embedding.
|
|
3506
|
+
* await table.loadArray([{ name: "Station" }])
|
|
3507
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3508
|
+
* ...row, embedding: [0.25, 0.5, 0.75],
|
|
3509
|
+
* })), { columnTypes: { embedding: "FLOAT[3]" } })
|
|
3539
3510
|
* .log();
|
|
3540
3511
|
* ```
|
|
3512
|
+
*
|
|
3513
|
+
* @example
|
|
3514
|
+
* ```ts
|
|
3515
|
+
* // Move each point slightly east by editing its longitude.
|
|
3516
|
+
* await sdb.newTable().loadArray([{
|
|
3517
|
+
* geom: { type: "Point", coordinates: [-73, 45] },
|
|
3518
|
+
* }], { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } })
|
|
3519
|
+
* .updateWithJS((rows) => rows.map((row) => {
|
|
3520
|
+
* // This example loads only Points. Narrow the type for coordinate access.
|
|
3521
|
+
* const geom = row.geom as { type: "Point"; coordinates: number[] } | null;
|
|
3522
|
+
* if (geom !== null) geom.coordinates[0] += 0.01;
|
|
3523
|
+
* return row;
|
|
3524
|
+
* })).log();
|
|
3525
|
+
* ```
|
|
3526
|
+
*
|
|
3527
|
+
* @example
|
|
3528
|
+
* ```ts
|
|
3529
|
+
* // Create a geometry column from longitude and latitude values.
|
|
3530
|
+
* await sdb.newTable().loadArray([{ longitude: -73, latitude: 45 }])
|
|
3531
|
+
* .updateWithJS((rows) => rows.map((row) => ({
|
|
3532
|
+
* ...row, geom: { type: "Point", coordinates: [row.longitude, row.latitude] },
|
|
3533
|
+
* })), { columnTypes: { geom: "GEOMETRY('EPSG:4326')" } }).log();
|
|
3534
|
+
* ```
|
|
3541
3535
|
*/
|
|
3542
3536
|
updateWithJS(dataModifier: ((rows: {
|
|
3543
3537
|
[key: string]: unknown;
|
|
@@ -3549,6 +3543,9 @@ export default class SimpleTable extends Simple {
|
|
|
3549
3543
|
[key: string]: unknown;
|
|
3550
3544
|
}[]), options?: {
|
|
3551
3545
|
batchSize?: number;
|
|
3546
|
+
columnTypes?: {
|
|
3547
|
+
[key: string]: string;
|
|
3548
|
+
};
|
|
3552
3549
|
}): this;
|
|
3553
3550
|
/**
|
|
3554
3551
|
* Returns the schema of the table, including column names and their data types.
|
|
@@ -3621,8 +3618,6 @@ export default class SimpleTable extends Simple {
|
|
|
3621
3618
|
* Produces identical output to `journalism-format`'s `normalizeString()` function
|
|
3622
3619
|
* for all common cases including accented Latin characters.
|
|
3623
3620
|
*
|
|
3624
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3625
|
-
*
|
|
3626
3621
|
* @param column The column containing the text to normalize
|
|
3627
3622
|
* @param newColumn The column to store the normalized results
|
|
3628
3623
|
* @param options Configuration options
|
|
@@ -3669,8 +3664,6 @@ export default class SimpleTable extends Simple {
|
|
|
3669
3664
|
* 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.
|
|
3670
3665
|
* `NULL` input values produce `NULL` counts.
|
|
3671
3666
|
*
|
|
3672
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3673
|
-
*
|
|
3674
3667
|
* @param column - The name of the column containing the strings to count.
|
|
3675
3668
|
* @param newColumn - The name of the new column where the character counts will be stored.
|
|
3676
3669
|
* @returns The table, so methods can be chained.
|
|
@@ -3687,8 +3680,6 @@ export default class SimpleTable extends Simple {
|
|
|
3687
3680
|
* Adds a new column containing the word count for each string in the specified column.
|
|
3688
3681
|
* 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.
|
|
3689
3682
|
*
|
|
3690
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
3691
|
-
*
|
|
3692
3683
|
* @param column - The name of the column containing the strings to count.
|
|
3693
3684
|
* @param newColumn - The name of the new column where the word counts will be stored.
|
|
3694
3685
|
* @returns The table, so methods can be chained.
|
|
@@ -3719,6 +3710,7 @@ export default class SimpleTable extends Simple {
|
|
|
3719
3710
|
getCharacterCount(column: string): Promise<number>;
|
|
3720
3711
|
/**
|
|
3721
3712
|
* Returns the number of rows in the table.
|
|
3713
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
3722
3714
|
*
|
|
3723
3715
|
* @param options - An optional object with configuration options:
|
|
3724
3716
|
* @param options.conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"category = 'Book'"`).
|
|
@@ -4045,7 +4037,7 @@ export default class SimpleTable extends Simple {
|
|
|
4045
4037
|
getUniques(column: string): Promise<unknown[]>;
|
|
4046
4038
|
/**
|
|
4047
4039
|
* Returns the first row of the table, optionally filtered by SQL conditions.
|
|
4048
|
-
*
|
|
4040
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4049
4041
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4050
4042
|
*
|
|
4051
4043
|
* @param options - An optional object with configuration options:
|
|
@@ -4074,7 +4066,7 @@ export default class SimpleTable extends Simple {
|
|
|
4074
4066
|
} | null>;
|
|
4075
4067
|
/**
|
|
4076
4068
|
* Returns the last row of the table, optionally filtered by SQL conditions.
|
|
4077
|
-
*
|
|
4069
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4078
4070
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4079
4071
|
*
|
|
4080
4072
|
* @param options - An optional object with configuration options:
|
|
@@ -4103,7 +4095,7 @@ export default class SimpleTable extends Simple {
|
|
|
4103
4095
|
} | null>;
|
|
4104
4096
|
/**
|
|
4105
4097
|
* Returns the top `n` rows of the table, optionally filtered by SQL conditions.
|
|
4106
|
-
*
|
|
4098
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4107
4099
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4108
4100
|
*
|
|
4109
4101
|
* @param count - The number of rows to return from the top of the table.
|
|
@@ -4134,7 +4126,7 @@ export default class SimpleTable extends Simple {
|
|
|
4134
4126
|
/**
|
|
4135
4127
|
* Returns the bottom `n` rows of the table, optionally filtered by SQL conditions.
|
|
4136
4128
|
* By default, the last row will be returned first. To preserve the original order, use the `originalOrder` option.
|
|
4137
|
-
*
|
|
4129
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4138
4130
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4139
4131
|
*
|
|
4140
4132
|
* @param count - The number of rows to return from the bottom of the table.
|
|
@@ -4173,7 +4165,7 @@ export default class SimpleTable extends Simple {
|
|
|
4173
4165
|
}[]>;
|
|
4174
4166
|
/**
|
|
4175
4167
|
* 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.
|
|
4176
|
-
*
|
|
4168
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4177
4169
|
* Temporal values use the same JavaScript representations as `getData()`.
|
|
4178
4170
|
*
|
|
4179
4171
|
* @param conditions - The conditions to match, specified as a SQL `WHERE` clause.
|
|
@@ -4211,13 +4203,26 @@ export default class SimpleTable extends Simple {
|
|
|
4211
4203
|
} | null>;
|
|
4212
4204
|
/**
|
|
4213
4205
|
* Returns the data from the table as an array of objects, optionally filtered by SQL conditions.
|
|
4214
|
-
*
|
|
4206
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4215
4207
|
*
|
|
4216
4208
|
* Top-level DuckDB `DATE` and `TIMESTAMP` columns are returned as JavaScript
|
|
4217
4209
|
* `Date` objects interpreted in UTC. `TIMESTAMP WITH TIME ZONE` values are
|
|
4218
4210
|
* returned as UTC strings, preserving DuckDB's microsecond precision;
|
|
4219
4211
|
* JavaScript `Date` supports only milliseconds.
|
|
4220
4212
|
*
|
|
4213
|
+
* Top-level `BIGINT`, `UBIGINT`, `HUGEINT`, and `UHUGEINT` columns are
|
|
4214
|
+
* returned as JavaScript numbers. Values outside `Number.MIN_SAFE_INTEGER`
|
|
4215
|
+
* through `Number.MAX_SAFE_INTEGER` throw instead of losing precision.
|
|
4216
|
+
* Use `convert({ columnName: "string" })` before `getData()` to retrieve
|
|
4217
|
+
* their exact digits as strings.
|
|
4218
|
+
*
|
|
4219
|
+
* SQL arrays and lists, including float vectors, return their actual elements
|
|
4220
|
+
* as JavaScript arrays. Null cells and null elements remain null.
|
|
4221
|
+
*
|
|
4222
|
+
* Nested SQL lists and structs become JavaScript arrays and objects. Within
|
|
4223
|
+
* them, `BIGINT`, `UBIGINT`, `HUGEINT`, `UHUGEINT`, and `DECIMAL` values remain
|
|
4224
|
+
* strings to preserve precision, even for small integers.
|
|
4225
|
+
*
|
|
4221
4226
|
* @param options - An optional object with configuration options:
|
|
4222
4227
|
* @param options.columns - An array of column names to include in the result. If omitted, all columns will be included.
|
|
4223
4228
|
* @param options.conditions - The filtering conditions specified as a SQL `WHERE` clause (e.g., `"category = 'Book'"`).
|
|
@@ -4251,6 +4256,18 @@ export default class SimpleTable extends Simple {
|
|
|
4251
4256
|
* // Return at most two rows.
|
|
4252
4257
|
* const preview = await table.getData({ limit: 2 });
|
|
4253
4258
|
* ```
|
|
4259
|
+
*
|
|
4260
|
+
* @example
|
|
4261
|
+
* ```ts
|
|
4262
|
+
* // Read nested integers without losing digits. SQL creates the nested types.
|
|
4263
|
+
* await sdb.customQuery(`CREATE TABLE nested_example AS SELECT
|
|
4264
|
+
* [42::BIGINT, 9007199254740993::BIGINT] AS ids,
|
|
4265
|
+
* {'count': 2::INTEGER, 'amount': 123.450::DECIMAL(6,3)} AS details`);
|
|
4266
|
+
* const nested = sdb.newTable("nested_example");
|
|
4267
|
+
* const rows = await nested.getData();
|
|
4268
|
+
* // [{ ids: ["42", "9007199254740993"], details: { count: 2, amount: "123.450" } }]
|
|
4269
|
+
* await nested.log();
|
|
4270
|
+
* ```
|
|
4254
4271
|
*/
|
|
4255
4272
|
getData(options?: {
|
|
4256
4273
|
columns?: string | string[];
|
|
@@ -4263,6 +4280,7 @@ export default class SimpleTable extends Simple {
|
|
|
4263
4280
|
* Streams the table rows one by one as an async iterator, without
|
|
4264
4281
|
* materializing the whole table in memory. Values are converted to
|
|
4265
4282
|
* JavaScript types the same way as `getData()`.
|
|
4283
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4266
4284
|
*
|
|
4267
4285
|
* The underlying DuckDB result is streamed chunk by chunk, so tables
|
|
4268
4286
|
* larger than the available memory can be iterated. Avoid running other
|
|
@@ -4298,7 +4316,7 @@ export default class SimpleTable extends Simple {
|
|
|
4298
4316
|
}, void, undefined>;
|
|
4299
4317
|
/**
|
|
4300
4318
|
* Returns the data from the table as a CSV string, optionally filtered by SQL conditions.
|
|
4301
|
-
*
|
|
4319
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
4302
4320
|
* Temporal values are first converted as they are in `getData()`, then
|
|
4303
4321
|
* serialized using UTC date and timestamp text.
|
|
4304
4322
|
*
|
|
@@ -4336,8 +4354,6 @@ export default class SimpleTable extends Simple {
|
|
|
4336
4354
|
/**
|
|
4337
4355
|
* Creates point geometries from latitude (y) and longitude (x) columns.
|
|
4338
4356
|
*
|
|
4339
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4340
|
-
*
|
|
4341
4357
|
* @param latColumn - The name of the column storing the latitude (y-coordinate) values.
|
|
4342
4358
|
* @param lonColumn - The name of the column storing the longitude (x-coordinate) values.
|
|
4343
4359
|
* @param newColumn - The name of the new column where the point geometries will be stored.
|
|
@@ -4366,8 +4382,6 @@ export default class SimpleTable extends Simple {
|
|
|
4366
4382
|
/**
|
|
4367
4383
|
* Adds a column with boolean values indicating the validity of geometries.
|
|
4368
4384
|
*
|
|
4369
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4370
|
-
*
|
|
4371
4385
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for valid, `FALSE` for invalid) will be stored.
|
|
4372
4386
|
* @param options - An optional object with configuration options:
|
|
4373
4387
|
* @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.
|
|
@@ -4393,8 +4407,6 @@ export default class SimpleTable extends Simple {
|
|
|
4393
4407
|
/**
|
|
4394
4408
|
* Adds a column with the number of vertices (points) in each geometry.
|
|
4395
4409
|
*
|
|
4396
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4397
|
-
*
|
|
4398
4410
|
* @param newColumn - The name of the new column where the vertex counts will be stored.
|
|
4399
4411
|
* @param options - An optional object with configuration options:
|
|
4400
4412
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4420,8 +4432,6 @@ export default class SimpleTable extends Simple {
|
|
|
4420
4432
|
/**
|
|
4421
4433
|
* Attempts to make invalid geometries valid without removing any vertices.
|
|
4422
4434
|
*
|
|
4423
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4424
|
-
*
|
|
4425
4435
|
* @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.
|
|
4426
4436
|
* @returns The table, so methods can be chained.
|
|
4427
4437
|
* @category Geospatial
|
|
@@ -4442,8 +4452,6 @@ export default class SimpleTable extends Simple {
|
|
|
4442
4452
|
/**
|
|
4443
4453
|
* Adds a column with boolean values indicating whether geometries are closed (e.g., polygons) or open (e.g., linestrings).
|
|
4444
4454
|
*
|
|
4445
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4446
|
-
*
|
|
4447
4455
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for closed, `FALSE` for open) will be stored.
|
|
4448
4456
|
* @param options - An optional object with configuration options:
|
|
4449
4457
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4468,8 +4476,6 @@ export default class SimpleTable extends Simple {
|
|
|
4468
4476
|
/**
|
|
4469
4477
|
* Adds a column with the geometry type (e.g., `"POINT"`, `"LINESTRING"`, `"POLYGON"`) for each geometry.
|
|
4470
4478
|
*
|
|
4471
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4472
|
-
*
|
|
4473
4479
|
* @param newColumn - The name of the new column where the geometry types will be stored.
|
|
4474
4480
|
* @param options - An optional object with configuration options:
|
|
4475
4481
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4495,8 +4501,6 @@ export default class SimpleTable extends Simple {
|
|
|
4495
4501
|
* 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).
|
|
4496
4502
|
* **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.
|
|
4497
4503
|
*
|
|
4498
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4499
|
-
*
|
|
4500
4504
|
* @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
4501
4505
|
* @returns The table, so methods can be chained.
|
|
4502
4506
|
* @category Geospatial
|
|
@@ -4519,7 +4523,7 @@ export default class SimpleTable extends Simple {
|
|
|
4519
4523
|
*
|
|
4520
4524
|
* 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.
|
|
4521
4525
|
*
|
|
4522
|
-
* This method supports only `POINT` geometries in `EPSG:4326`. Null and empty geometries are preserved.
|
|
4526
|
+
* This method supports only `POINT` geometries in `EPSG:4326`. Null and empty geometries are preserved.
|
|
4523
4527
|
*
|
|
4524
4528
|
* @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.
|
|
4525
4529
|
* @param options - An optional object with configuration options:
|
|
@@ -4553,8 +4557,6 @@ export default class SimpleTable extends Simple {
|
|
|
4553
4557
|
/**
|
|
4554
4558
|
* Reduces the precision of geometries in a specified column to a given number of decimal places.
|
|
4555
4559
|
*
|
|
4556
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4557
|
-
*
|
|
4558
4560
|
* @param decimals - The number of decimal places to keep in the coordinates of the geometries.
|
|
4559
4561
|
* @param options - An optional object with configuration options:
|
|
4560
4562
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4579,8 +4581,6 @@ export default class SimpleTable extends Simple {
|
|
|
4579
4581
|
/**
|
|
4580
4582
|
* Reprojects the geometries in a specified column to another Spatial Reference System (SRS).
|
|
4581
4583
|
*
|
|
4582
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4583
|
-
*
|
|
4584
4584
|
* @param crs - The target SRS (e.g., `"EPSG:3347"`, or `"EPSG:4326"` for EPSG:4326 (WGS84)).
|
|
4585
4585
|
* @param options - An optional object with configuration options:
|
|
4586
4586
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4606,8 +4606,6 @@ export default class SimpleTable extends Simple {
|
|
|
4606
4606
|
* Computes the area of geometries in square meters (`"m2"`) or optionally square kilometers (`"km2"`).
|
|
4607
4607
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4608
4608
|
*
|
|
4609
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4610
|
-
*
|
|
4611
4609
|
* @param newColumn - The name of the new column where the computed areas will be stored.
|
|
4612
4610
|
* @param options - An optional object with configuration options:
|
|
4613
4611
|
* @param options.unit - The unit for the computed area: `"m2"` (square meters) or `"km2"` (square kilometers). Defaults to `"m2"`.
|
|
@@ -4649,8 +4647,6 @@ export default class SimpleTable extends Simple {
|
|
|
4649
4647
|
* Computes the length of line geometries in meters (`"m"`) or optionally kilometers (`"km"`).
|
|
4650
4648
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4651
4649
|
*
|
|
4652
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4653
|
-
*
|
|
4654
4650
|
* @param newColumn - The name of the new column where the computed lengths will be stored.
|
|
4655
4651
|
* @param options - An optional object with configuration options:
|
|
4656
4652
|
* @param options.unit - The unit for the computed length: `"m"` (meters) or `"km"` (kilometers). Defaults to `"m"`.
|
|
@@ -4692,8 +4688,6 @@ export default class SimpleTable extends Simple {
|
|
|
4692
4688
|
* Computes the perimeter of polygon geometries in meters (`"m"`) or optionally kilometers (`"km"`).
|
|
4693
4689
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4694
4690
|
*
|
|
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
4691
|
* @param newColumn - The name of the new column where the computed perimeters will be stored.
|
|
4698
4692
|
* @param options - An optional object with configuration options:
|
|
4699
4693
|
* @param options.unit - The unit for the computed perimeter: `"m"` (meters) or `"km"` (kilometers). Defaults to `"m"`.
|
|
@@ -4735,8 +4729,6 @@ export default class SimpleTable extends Simple {
|
|
|
4735
4729
|
* Computes a buffer (a polygon representing a specified distance around a geometry) for geometries in a specified column.
|
|
4736
4730
|
* The distance is in the Spatial Reference System (SRS) unit of the input geometries.
|
|
4737
4731
|
*
|
|
4738
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4739
|
-
*
|
|
4740
4732
|
* @param newColumn - The name of the new column where the buffered geometries will be stored.
|
|
4741
4733
|
* @param distance - The distance for the buffer. This value is in the units of the geometry's SRS.
|
|
4742
4734
|
* @param options - An optional object with configuration options:
|
|
@@ -4763,7 +4755,6 @@ export default class SimpleTable extends Simple {
|
|
|
4763
4755
|
* Merges the data of this table (considered the left table) with another table (the right table) based on a spatial relationship.
|
|
4764
4756
|
* Note that the order of rows in the returned data is not guaranteed to be the same as in the original tables.
|
|
4765
4757
|
* This operation might create temporary files in a `.tmp` folder; consider adding `.tmp` to your `.gitignore`.
|
|
4766
|
-
* 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.
|
|
4767
4758
|
*
|
|
4768
4759
|
* @param rightTable - The SimpleTable instance to be joined with this table.
|
|
4769
4760
|
* @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).
|
|
@@ -4837,8 +4828,6 @@ export default class SimpleTable extends Simple {
|
|
|
4837
4828
|
/**
|
|
4838
4829
|
* Computes the intersection of two sets of geometries, creating new geometries where they overlap.
|
|
4839
4830
|
*
|
|
4840
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4841
|
-
*
|
|
4842
4831
|
* @param column1 - The name of the first column storing geometries.
|
|
4843
4832
|
* @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
|
|
4844
4833
|
* @param newColumn - The name of the new column where the computed intersection geometries will be stored.
|
|
@@ -4855,8 +4844,6 @@ export default class SimpleTable extends Simple {
|
|
|
4855
4844
|
/**
|
|
4856
4845
|
* Computes the geometric difference between two geometries, returning the portion of the first geometry that does not intersect the second.
|
|
4857
4846
|
*
|
|
4858
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4859
|
-
*
|
|
4860
4847
|
* @param column1 - The name of the column storing the geometries from which the second geometries will be subtracted.
|
|
4861
4848
|
* @param column2 - The name of the column storing the geometries to subtract. Both columns must have the same projection.
|
|
4862
4849
|
* @param newColumn - The name of the new column where the geometric differences will be stored.
|
|
@@ -4873,8 +4860,6 @@ export default class SimpleTable extends Simple {
|
|
|
4873
4860
|
/**
|
|
4874
4861
|
* Fills holes in polygon geometries.
|
|
4875
4862
|
*
|
|
4876
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4877
|
-
*
|
|
4878
4863
|
* @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
4879
4864
|
* @returns The table, so methods can be chained.
|
|
4880
4865
|
* @category Geospatial
|
|
@@ -4895,8 +4880,6 @@ export default class SimpleTable extends Simple {
|
|
|
4895
4880
|
/**
|
|
4896
4881
|
* Returns `TRUE` if two geometries intersect (overlap in any way), and `FALSE` otherwise.
|
|
4897
4882
|
*
|
|
4898
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4899
|
-
*
|
|
4900
4883
|
* @param column1 - The name of the first column storing geometries.
|
|
4901
4884
|
* @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
|
|
4902
4885
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` for intersection, `FALSE` otherwise) will be stored.
|
|
@@ -4913,8 +4896,6 @@ export default class SimpleTable extends Simple {
|
|
|
4913
4896
|
/**
|
|
4914
4897
|
* Returns `TRUE` if every point of a geometry in `column` is covered by a geometry in `containerColumn`, including their boundaries, and `FALSE` otherwise.
|
|
4915
4898
|
*
|
|
4916
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4917
|
-
*
|
|
4918
4899
|
* @param column - The name of the column storing the geometries to be tested for containment.
|
|
4919
4900
|
* @param containerColumn - The name of the column storing the geometries to be tested as containers. Both columns must have the same projection.
|
|
4920
4901
|
* @param newColumn - The name of the new column where the boolean results (`TRUE` when covered, `FALSE` otherwise) will be stored.
|
|
@@ -4931,8 +4912,6 @@ export default class SimpleTable extends Simple {
|
|
|
4931
4912
|
/**
|
|
4932
4913
|
* Computes the union of two geometries, creating a new geometry that represents the merged area of both.
|
|
4933
4914
|
*
|
|
4934
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4935
|
-
*
|
|
4936
4915
|
* @param column1 - The name of the first column storing geometries.
|
|
4937
4916
|
* @param column2 - The name of the second column storing geometries. Both columns must have the same projection.
|
|
4938
4917
|
* @param newColumn - The name of the new column where the computed union geometries will be stored.
|
|
@@ -4950,8 +4929,6 @@ export default class SimpleTable extends Simple {
|
|
|
4950
4929
|
* Extracts the latitude (y) and longitude (x) coordinates from point geometries.
|
|
4951
4930
|
* The input geometry is assumed to be in EPSG:4326 (WGS84).
|
|
4952
4931
|
*
|
|
4953
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
4954
|
-
*
|
|
4955
4932
|
* @param column - The name of the column storing the point geometries.
|
|
4956
4933
|
* @param latColumn - The name of the new column where the extracted latitude (y-coordinate) values will be stored.
|
|
4957
4934
|
* @param lonColumn - The name of the new column where the extracted longitude (x-coordinate) values will be stored.
|
|
@@ -4968,8 +4945,6 @@ export default class SimpleTable extends Simple {
|
|
|
4968
4945
|
/**
|
|
4969
4946
|
* Simplifies geometries while preserving their overall coverage. A higher tolerance results in more significant simplification.
|
|
4970
4947
|
*
|
|
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
4948
|
* @param tolerance - A numeric value representing the simplification tolerance. A higher value leads to greater simplification.
|
|
4974
4949
|
* @param options - An optional object with configuration options:
|
|
4975
4950
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -4997,8 +4972,6 @@ export default class SimpleTable extends Simple {
|
|
|
4997
4972
|
* Computes the centroid of geometries.
|
|
4998
4973
|
* The values are returned in the SRS unit of the input geometries.
|
|
4999
4974
|
*
|
|
5000
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5001
|
-
*
|
|
5002
4975
|
* @param newColumn - The name of the new column where the computed centroid geometries will be stored.
|
|
5003
4976
|
* @param options - An optional object with configuration options:
|
|
5004
4977
|
* @param options.column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -5023,8 +4996,6 @@ export default class SimpleTable extends Simple {
|
|
|
5023
4996
|
/**
|
|
5024
4997
|
* Generates a random point within the geometries of a specified column.
|
|
5025
4998
|
*
|
|
5026
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5027
|
-
*
|
|
5028
4999
|
* @param newColumn - The name of the new column where the random points will be stored.
|
|
5029
5000
|
* @param tries - The number of points to generate within the bounding box of each geometry to find one that is within the geometry itself.
|
|
5030
5001
|
* @param options - An optional object with configuration options:
|
|
@@ -5059,8 +5030,6 @@ export default class SimpleTable extends Simple {
|
|
|
5059
5030
|
* You can optionally specify `"spheroid"` or `"haversine"` methods to get results in meters or kilometers.
|
|
5060
5031
|
* If using `"spheroid"` or `"haversine"`, the input geometries must be in EPSG:4326 (WGS84).
|
|
5061
5032
|
*
|
|
5062
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5063
|
-
*
|
|
5064
5033
|
* @param column1 - The name of the first column storing geometries.
|
|
5065
5034
|
* @param column2 - The name of the second column storing geometries.
|
|
5066
5035
|
* @param newColumn - The name of the new column where the computed distances will be stored.
|
|
@@ -5106,8 +5075,6 @@ export default class SimpleTable extends Simple {
|
|
|
5106
5075
|
/**
|
|
5107
5076
|
* Unnests geometries recursively, transforming multi-part geometries (e.g., MultiPolygon) into individual single-part geometries (e.g., Polygon).
|
|
5108
5077
|
*
|
|
5109
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5110
|
-
*
|
|
5111
5078
|
* @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.
|
|
5112
5079
|
* @returns The table, so methods can be chained.
|
|
5113
5080
|
* @category Geospatial
|
|
@@ -5128,8 +5095,6 @@ export default class SimpleTable extends Simple {
|
|
|
5128
5095
|
/**
|
|
5129
5096
|
* Adds the bounding box coordinates of geometries in a specified column as four new columns: `minLon`, `minLat`, `maxLon`, and `maxLat`.
|
|
5130
5097
|
*
|
|
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
5098
|
* @param options - An optional object with configuration options:
|
|
5134
5099
|
* @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.
|
|
5135
5100
|
* @param options.decimals - The number of decimal places to round the bounding box coordinates. Defaults to `undefined` (no rounding).
|
|
@@ -5157,8 +5122,6 @@ export default class SimpleTable extends Simple {
|
|
|
5157
5122
|
/**
|
|
5158
5123
|
* Aggregates geometries in a specified column based on a chosen aggregation method.
|
|
5159
5124
|
*
|
|
5160
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5161
|
-
*
|
|
5162
5125
|
* @param method - The aggregation method to apply: `"union"` (combines all geometries into a single multi-geometry) or `"intersection"` (computes the intersection of all geometries).
|
|
5163
5126
|
* @param options - An optional object with configuration options:
|
|
5164
5127
|
* @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.
|
|
@@ -5193,8 +5156,6 @@ export default class SimpleTable extends Simple {
|
|
|
5193
5156
|
/**
|
|
5194
5157
|
* Transforms closed linestring geometries into polygon geometries.
|
|
5195
5158
|
*
|
|
5196
|
-
* This method queues the operation; it runs when an async observer method (like `getData()` or `log()`) is awaited, or when `run()` is called.
|
|
5197
|
-
*
|
|
5198
5159
|
* @param column - The name of the column storing the linestring geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
5199
5160
|
* @returns The table, so methods can be chained.
|
|
5200
5161
|
* @category Geospatial
|
|
@@ -5236,7 +5197,9 @@ export default class SimpleTable extends Simple {
|
|
|
5236
5197
|
*/
|
|
5237
5198
|
getBoundingBox(column?: string): Promise<[number, number, number, number]>;
|
|
5238
5199
|
/**
|
|
5239
|
-
* Returns the table's geospatial data as a GeoJSON
|
|
5200
|
+
* Returns the table's geospatial data as a GeoJSON FeatureCollection.
|
|
5201
|
+
* Each row becomes a Feature: the selected geometry column becomes its geometry,
|
|
5202
|
+
* and the remaining columns become its properties.
|
|
5240
5203
|
* If the table has multiple geometry columns, you must specify which one to use.
|
|
5241
5204
|
*
|
|
5242
5205
|
* @param column - The name of the column storing the geometries. If omitted, the method will automatically attempt to find a geometry column.
|
|
@@ -5274,12 +5237,13 @@ export default class SimpleTable extends Simple {
|
|
|
5274
5237
|
}>;
|
|
5275
5238
|
/**
|
|
5276
5239
|
* Writes the table's data to a file in various formats (CSV, JSON, Parquet, DuckDB, SQLite).
|
|
5240
|
+
* Tables with geometry columns must use `writeGeoData()` instead.
|
|
5277
5241
|
* If the specified path does not exist, it will be created.
|
|
5278
5242
|
*
|
|
5279
5243
|
* @param file - The absolute path to the output file (e.g., `"./output.csv"`, `"./output.json"`).
|
|
5280
5244
|
* @param options - An optional object with configuration options:
|
|
5281
5245
|
* @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`.
|
|
5282
|
-
* @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.
|
|
5246
|
+
* @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.
|
|
5283
5247
|
* @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`.
|
|
5284
5248
|
* @returns A promise that resolves to the table, so methods can be chained.
|
|
5285
5249
|
* @category File Operations
|
|
@@ -5384,28 +5348,28 @@ export default class SimpleTable extends Simple {
|
|
|
5384
5348
|
* Caches the results of computations in `./.sda-cache`.
|
|
5385
5349
|
* You should add `./.sda-cache` to your `.gitignore` file.
|
|
5386
5350
|
*
|
|
5387
|
-
* Cache entries are stored as DuckDB database files. Full-text search (FTS)
|
|
5388
|
-
* indexes are persisted in the cache file and restored directly on a cache
|
|
5389
|
-
* hit. Vector similarity search (VSS/HNSW) indexes are not persisted in the
|
|
5390
|
-
* cache file; their definitions are stored as metadata and used to rebuild
|
|
5391
|
-
* the indexes on every cache hit. If loading the entry or restoring its
|
|
5392
|
-
* indexes fails, the computation runs again and replaces the cache entry.
|
|
5393
|
-
*
|
|
5394
5351
|
* `cache()` automatically tracks whether earlier SDA operations changed the
|
|
5395
5352
|
* table. It also records every other already registered `SimpleTable` read
|
|
5396
5353
|
* through `SimpleTable` methods while `compute` runs and invalidates the
|
|
5397
5354
|
* cached step when any of their generations change. Tables created inside
|
|
5398
5355
|
* `compute` are part of the computation itself and are not dependencies.
|
|
5399
5356
|
*
|
|
5357
|
+
* Inside `compute`, you may modify the table being cached and create or
|
|
5358
|
+
* modify temporary tables, provided you remove them before the callback
|
|
5359
|
+
* finishes. Other tables that already existed may be read but not modified,
|
|
5360
|
+
* renamed, or removed. `customQuery()` bypasses enforcement of these rules.
|
|
5361
|
+
*
|
|
5400
5362
|
* `SimpleDB.customQuery()` bypasses this tracking. Reading or changing a
|
|
5401
5363
|
* table with `customQuery()` can therefore return stale cached data. Include
|
|
5402
5364
|
* a value that identifies the custom query's dependencies in `options.inputs`
|
|
5403
5365
|
* (such as a table content hash), or use tracked `SimpleTable` methods.
|
|
5404
5366
|
*
|
|
5405
|
-
*
|
|
5406
|
-
*
|
|
5407
|
-
*
|
|
5408
|
-
*
|
|
5367
|
+
* Cache entries are stored as DuckDB database files. Full-text search (FTS)
|
|
5368
|
+
* indexes are persisted in the cache file and restored directly on a cache
|
|
5369
|
+
* hit. Vector similarity search (VSS/HNSW) indexes are not persisted in the
|
|
5370
|
+
* cache file; their definitions are stored as metadata and used to rebuild
|
|
5371
|
+
* the indexes on every cache hit. If loading the entry or restoring its
|
|
5372
|
+
* indexes fails, the computation runs again and replaces the cache entry.
|
|
5409
5373
|
*
|
|
5410
5374
|
* @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.
|
|
5411
5375
|
* @param options - An optional object with configuration options:
|
|
@@ -5490,7 +5454,16 @@ export default class SimpleTable extends Simple {
|
|
|
5490
5454
|
/**
|
|
5491
5455
|
* Logs a specified number of rows from the table to the console. By default, the first 10 rows are logged.
|
|
5492
5456
|
* You can optionally log the column types and filter the data based on conditions.
|
|
5493
|
-
*
|
|
5457
|
+
* SQL dates and timestamps retain their native precision for display, including
|
|
5458
|
+
* temporal infinities. Lists and objects are stringified using the same nested
|
|
5459
|
+
* representations as `getData()`, then truncated according to `charsToLog`.
|
|
5460
|
+
* Unsafe top-level large integers throw, just as with `getData()`.
|
|
5461
|
+
* Type annotations describe the SQL type and the JavaScript extraction type
|
|
5462
|
+
* before display formatting; nulls do not determine the column's annotation.
|
|
5463
|
+
* Colors reflect the SQL value's meaning, so exact decimal strings use numeric
|
|
5464
|
+
* coloring. Column width is independent of the content truncation budget.
|
|
5465
|
+
*
|
|
5466
|
+
* With the default `SimpleDB.expressionSyntax: "js"`, conditions support JavaScript-style operators (`&&`, `||`, `===`, `!==`). Set `expressionSyntax: "sql"` for unchanged SQL.
|
|
5494
5467
|
*
|
|
5495
5468
|
* @param options - Either the number of rows to log (a specific number or `"all"`) or an object with configuration options:
|
|
5496
5469
|
* @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.
|
|
@@ -5679,6 +5652,10 @@ export default class SimpleTable extends Simple {
|
|
|
5679
5652
|
/**
|
|
5680
5653
|
* 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.
|
|
5681
5654
|
*
|
|
5655
|
+
* Uses the same precision-preserving temporal display, nested stringification,
|
|
5656
|
+
* numeric coloring, and `charsToLog` truncation as `log()`. Unsafe top-level
|
|
5657
|
+
* large integers throw, just as with `getData()`.
|
|
5658
|
+
*
|
|
5682
5659
|
* @param count - The number of rows to log from the bottom of the table. Defaults to the table's `rowsToLog` option if not specified.
|
|
5683
5660
|
* @param options - An optional object with logging preferences.
|
|
5684
5661
|
* @param options.originalOrder - If true, the rows are displayed in their original order (top to bottom). Defaults to false.
|