Files
lancedb/nodejs/__test__/experimental_functions.test.ts
T
Xuanwo 8a4effa06a fix: gate experimental local functions behind an opt-in feature (#4688)
Published SDK builds currently expose local SQL computed columns and
materialized-view execution that are not ready for release. Add the
opt-in `experimental-functions` Cargo feature to the Rust core and
forward it through the Python and Node bindings; published packages
leave it disabled.

Local declarations and refreshes now return `NotSupported` before
mutating tables or spawning jobs, including prepared materialized-view
creation. Remote Cloud/Enterprise client operations, Python UDF
packaging, ordinary eager `add_columns`, and access to existing data
remain available. Stored metadata and write protections stay active, and
shared server commit helpers remain usable.

CI covers both feature configurations. Existing local execution tests
run with the feature enabled; default-build regressions cover early
rejection, unchanged table versions, existing metadata protections, and
normal eager transforms. API and source-build documentation explain the
opt-in.

Validation: Rust library tests pass with the feature disabled (1,869
tests) and enabled (1,947 tests), plus three default-build integration
regressions. Python and TypeScript bindings were rebuilt and tested in
both configurations, including mocked remote requests; Rust formatting,
Python package lint, TypeScript lint/build, and generated docs were
checked. Repository-wide Ruff still reports 48 pre-existing errors in
unchanged `docs/web-tests` files.
2026-10-27 14:32:09 +08:00

45 lines
1.6 KiB
TypeScript

// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { connect } from "../lancedb";
import { experimentalFunctionsEnabled } from "../lancedb/native";
const defaultBuildTest = experimentalFunctionsEnabled() ? it.skip : it;
defaultBuildTest(
"rejects local Functions before mutating the database",
async () => {
const directory = await mkdtemp(join(tmpdir(), "lancedb-experimental-"));
try {
const db = await connect(directory);
const table = await db.createTable("source", [{ x: 1 }, { x: 2 }]);
const version = await table.version();
const operations = [
() =>
table.addColumns({
computed: [{ name: "doubled", valueSql: "x * 2" }],
}),
() => table.refreshColumn("x"),
() => table.refreshColumnAsync("x"),
() => db.createMaterializedView("blocked", "source"),
() =>
db.createMaterializedView("blocked", "source", { withNoData: true }),
];
for (const operation of operations) {
await expect(operation()).rejects.toThrow("experimental-functions");
}
expect(await table.version()).toBe(version);
expect(await db.tableNames()).toEqual(["source"]);
await table.addColumns([{ name: "eager", valueSql: "x * 2" }]);
expect((await table.query().toArray()).map((row) => row.eager)).toEqual([
2, 4,
]);
} finally {
await rm(directory, { recursive: true, force: true });
}
},
);