diff --git a/docs/web-tests/ts/tables.test.ts b/docs/web-tests/ts/tables.test.ts index b2a49b6b2..ec6360008 100644 --- a/docs/web-tests/ts/tables.test.ts +++ b/docs/web-tests/ts/tables.test.ts @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: Copyright The LanceDB Authors -import { expect, test } from "@jest/globals"; +import { expect, jest, test } from "@jest/globals"; import * as arrow from "apache-arrow"; import * as lancedb from "@lancedb/lancedb"; import { withTempDirectory } from "./util.ts"; @@ -194,6 +194,40 @@ test("table creation snippets (async)", async () => { }); }); +test("add progress snippet (async)", async () => { + await withTempDirectory(async (databaseDir) => { + const db = await lancedb.connect(databaseDir); + const table = await db.createTable("progress_table", [ + { vector: [1.1, 1.2], item: "foo" }, + ]); + const moreData = [ + { vector: [2.1, 2.2], item: "bar" }, + { vector: [3.1, 3.2], item: "baz" }, + ]; + const log = jest.spyOn(console, "log").mockImplementation(() => {}); + try { + // --8<-- [start:add_progress] + // Track ingestion progress as batches are written. + await table.add(moreData, { + progress: (p) => { + const total = p.totalRows ?? "?"; + console.log( + `wrote ${p.outputRows}/${total} rows ` + + `(${p.outputBytes} bytes, ${p.elapsedSeconds.toFixed(1)}s, ` + + `${p.activeTasks}/${p.totalTasks} tasks active)` + + (p.done ? " \u2014 done" : ""), + ); + }, + }); + // --8<-- [end:add_progress] + expect(log.mock.calls.at(-1)?.[0]).toMatch(/^wrote 2\/2 rows .* — done$/); + } finally { + log.mockRestore(); + } + expect(await table.countRows()).toBe(3); + }); +}); + test("schema evolution snippets (async)", async () => { await withTempDirectory(async (databaseDir) => { const db = await lancedb.connect(databaseDir); diff --git a/docs/web/feature-engineering/data-evolution.mdx b/docs/web/feature-engineering/data-evolution.mdx index b835dbf61..5f50bdcbb 100644 --- a/docs/web/feature-engineering/data-evolution.mdx +++ b/docs/web/feature-engineering/data-evolution.mdx @@ -7,7 +7,7 @@ keywords: ["data evolution", "derived columns", "add_columns", "zero copy", "fea --- import { - PySchemaAddSetup as SchemaAddSetup, + PySchemaAddSetup, TsSchemaAddSetup as TsSchemaAddSetup, RsSchemaAddSetup as RsSchemaAddSetup, PyAddColumnsCalculated as AddColumnsCalculated, @@ -34,7 +34,7 @@ In SQL this is [`ALTER TABLE ... ADD COLUMN ... AS`](/sql/ddl/table#computed-col - {SchemaAddSetup} + {PySchemaAddSetup} diff --git a/docs/web/management/table.mdx b/docs/web/management/table.mdx index be1da63b0..bee51d147 100644 --- a/docs/web/management/table.mdx +++ b/docs/web/management/table.mdx @@ -7,7 +7,7 @@ keywords: ["table", "create_table", "open_table", "clone", "rename", "drop"] --- import { - PySchemaAddSetup as SchemaAddSetup, + PySchemaAddSetup, TsSchemaAddSetup as TsSchemaAddSetup, RsSchemaAddSetup as RsSchemaAddSetup, PyAddColumnsDefaultValues as AddColumnsDefaultValues, @@ -534,7 +534,7 @@ First, let's create a sample table with product data to demonstrate schema evolu - {SchemaAddSetup} + {PySchemaAddSetup} diff --git a/docs/web/snippets/tables.mdx b/docs/web/snippets/tables.mdx index 0d8f213db..88b33fe8a 100644 --- a/docs/web/snippets/tables.mdx +++ b/docs/web/snippets/tables.mdx @@ -148,6 +148,8 @@ export const TsAddColumnsNullable = "// Add a nullable timestamp column\nawait s export const TsAddFeatureColumnsSql = "await schemaAddTable.addColumns([\n {\n name: \"price_per_id\",\n valueSql: \"cast(price / id as float)\",\n },\n {\n name: \"price_log\",\n valueSql: \"ln(price)\",\n },\n {\n name: \"price_score\",\n valueSql: \"cast(price / (price + 100.0) as float)\",\n },\n]);\n"; +export const TsAddProgress = "// Track ingestion progress as batches are written.\nawait table.add(moreData, {\n progress: (p) => {\n const total = p.totalRows ?? \"?\";\n console.log(\n `wrote ${p.outputRows}/${total} rows ` +\n `(${p.outputBytes} bytes, ${p.elapsedSeconds.toFixed(1)}s, ` +\n `${p.activeTasks}/${p.totalTasks} tasks active)` +\n (p.done ? \" \\u2014 done\" : \"\"),\n );\n },\n});\n"; + export const TsAlterColumnsDataType = "// Change price from int32 to int64 for larger numbers\nawait schemaAlterTable.alterColumns([\n { path: \"price\", dataType: new arrow.Int64() },\n]);\n"; export const TsAlterColumnsMultiple = "// Rename, change type, and make nullable in one operation\nawait schemaAlterTable.alterColumns([\n {\n path: \"sale_price\",\n rename: \"final_price\",\n dataType: new arrow.Float64(),\n nullable: true,\n },\n]);\n";