mirror of
https://github.com/lancedb/lancedb.git
synced 2026-09-06 13:29:08 +00:00
fix: store namespaced view definitions under their own kind
Keeping `kind: "select"` for a namespaced definition was a silent downgrade hazard: released readers drop unknown fields and resolve a select source at the root, so a rolled-back worker could refresh a view from a same-name root table and certify the wrong rows. Root definitions keep the `select` form byte-for-byte; a namespaced source is stored as `namespaced_select`, which older readers route to their existing unrecognized-kind refusal. The reader also refuses a kind that disagrees with its namespace, since no correct writer produces one. The Python and Node definition parsers learn the new kind alongside the Rust core, so every same-version reader agrees.
This commit is contained in:
@@ -48,6 +48,28 @@ describe("materialized views", () => {
|
||||
expect(definitionFromMetadata(safe, "v").limit).toBe(42);
|
||||
});
|
||||
|
||||
it("reads the namespaced select kind and refuses unknown kinds", () => {
|
||||
// "namespaced_select" is the namespaced form of "select": same shape, a
|
||||
// separate kind so readers that predate it refuse instead of resolving
|
||||
// the source at the root.
|
||||
const namespaced = new Map([
|
||||
[
|
||||
DEFINITION_META_KEY,
|
||||
'{"kind":"namespaced_select","source_table":"people","source_namespace":["ns"]}',
|
||||
],
|
||||
]);
|
||||
const definition = definitionFromMetadata(namespaced, "v");
|
||||
expect(definition.sourceTable).toBe("people");
|
||||
expect(definition.sourceNamespace).toEqual(["ns"]);
|
||||
|
||||
const unknown = new Map([
|
||||
[DEFINITION_META_KEY, '{"kind":"select_v3","source_table":"people"}'],
|
||||
]);
|
||||
expect(() => definitionFromMetadata(unknown, "v")).toThrow(
|
||||
/cannot refresh/,
|
||||
);
|
||||
});
|
||||
|
||||
it("creates, refreshes and queries a view", async () => {
|
||||
const view = await db.createMaterializedView("adults", "people", {
|
||||
select: ["name", ["shout", "upper(name)"]],
|
||||
|
||||
Reference in New Issue
Block a user