feat(nodejs): add Enterprise table override APIs (#5077)

Add TypeScript `getTableOverrides`, `updateTableOverrides`, and
`resetTableOverrides` for LanceDB Enterprise tables, delegating to the
shared Rust implementation used by Python.

Document that updates perform GET → recursive local merge → full PUT.
Unrelated fields are preserved from the read snapshot, but concurrent
edits can be overwritten. CLI `set` and REST PUT retain replacement
semantics.

Fix an empty SDK update to return the current snapshot without a PUT.
Live testing found that the previous implementation submitted an empty
replacement and failed when no overrides were configured. The fix
applies to Python, Rust, and TypeScript.

Add mock HTTP/local coverage and an opt-in Enterprise integration suite
for namespaces, branch isolation, REST replacement, validation failures,
historical handles, and empty updates.
This commit is contained in:
Bruno Ramirez
2026-11-18 09:02:45 -08:00
committed by GitHub
parent dd69a2c535
commit 96c25bd6b9
12 changed files with 737 additions and 10 deletions
+74
View File
@@ -901,6 +901,26 @@ Resolves to `undefined` only when the RTE write path is not enabled.
***
### getTableOverrides()
```ts
getTableOverrides(): Promise<Record<string, unknown>>
```
Read the stored overrides for a remote Enterprise table.
Overrides configure background behavior such as automatic compaction,
cleanup, and reindex execution. Keys use the server's snake_case names.
Returns an empty object when no overrides are set. Local tables are unsupported.
Custom table implementations inherit a default rejection unless they override
this method.
#### Returns
`Promise`&lt;`Record`&lt;`string`, `unknown`&gt;&gt;
***
### indexStats()
```ts
@@ -1379,6 +1399,22 @@ console.log(await job.status()); // "finished"
***
### resetTableOverrides()
```ts
resetTableOverrides(): Promise<Record<string, unknown>>
```
Clear a remote Enterprise table's overrides and return an empty object.
Local tables and custom table implementations without override support reject
this operation.
#### Returns
`Promise`&lt;`Record`&lt;`string`, `unknown`&gt;&gt;
***
### restore()
```ts
@@ -1736,6 +1772,44 @@ resolves to the new table version.
***
### updateTableOverrides()
```ts
updateTableOverrides(overrides): Promise<Record<string, unknown>>
```
Recursively merge overrides into a remote Enterprise table's stored overrides.
Fetches the current overrides, merges nested objects locally, then sends the
complete replacement using REST PUT. Other values replace existing values;
unrelated fields from the read snapshot are preserved. This read-modify-write
is not atomic: concurrent edits can be overwritten, even to unrelated fields.
Coordinate writers when concurrent edits must be preserved. An empty update
only reads and returns the current overrides.
Unlike this SDK method, CLI `set` and REST PUT replace the overrides object
without merging. Use [Table.resetTableOverrides](Table.md#resettableoverrides) to clear all overrides.
Local tables and custom table implementations without override support reject
this operation.
#### Parameters
* **overrides**: `Record`&lt;`string`, `unknown`&gt;
#### Returns
`Promise`&lt;`Record`&lt;`string`, `unknown`&gt;&gt;
#### Example
```ts
await table.updateTableOverrides({
job_types: { compaction: { enabled: false } },
});
```
***
### vectorSearch()
```ts
+53
View File
@@ -282,6 +282,59 @@ need preserving; read the current object and retain unrelated fields when
editing an existing policy. Use the same namespace and branch for policy reads,
writes, and compaction submission.
The Python, TypeScript, and Rust SDKs can update selected fields while retaining
unrelated overrides from the current read snapshot. For an existing Enterprise
`table` handle:
<CodeGroup>
```python Python
table.update_table_overrides(
job_types={
"compaction": {
"target_rows_per_fragment": 100000,
"max_source_rows": 1000000,
}
}
)
```
```typescript TypeScript
await table.updateTableOverrides({
job_types: {
compaction: {
target_rows_per_fragment: 100000,
max_source_rows: 1000000,
},
},
});
```
```rust Rust
table
.update_table_overrides(serde_json::json!({
"job_types": {
"compaction": {
"target_rows_per_fragment": 100000,
"max_source_rows": 1000000
}
}
}))
.await?;
```
</CodeGroup>
Override keys use the server's `snake_case` names in every SDK. These examples
retain other compaction settings, such as `enabled`, and settings for other job
types from the read snapshot. An empty update only reads the current overrides;
use `reset_table_overrides()` / `resetTableOverrides()` to clear all overrides.
SDK updates perform **GET → recursive merge in the client → full PUT**. This
read–modify–write is not atomic: concurrent edits can be overwritten, even to
unrelated fields. Coordinate override writers when concurrent edits must be
preserved. CLI `set` and REST PUT replace the object without merging.
These methods require a compatible Enterprise deployment. For namespaced tables,
confirm that the deployment supports table-override reads and resets within
namespaces before relying on these APIs.
Each manual field resolves as **invocation option → table tuning →
deployment/built-in default**. Automatic jobs resolve **table tuning →
deployment/built-in default**. The fragment target has a shared deployment
+213
View File
@@ -2929,3 +2929,216 @@ describe("job wait deadlines", () => {
},
);
});
describe("table overrides", () => {
it.each([[], ["analytics", "features"]])(
"reads, recursively merges, and resets in namespace %j",
async (...namespacePath: string[]) => {
const requests: { method?: string; url: string; body?: unknown }[] = [];
const current = {
// biome-ignore lint/style/useNamingConvention: server wire format
job_types: {
compaction: {
enabled: true,
// biome-ignore lint/style/useNamingConvention: server wire format
target_rows_per_fragment: 1000,
},
cleanup: { enabled: false },
},
custom: { keep: true, replace: [1, 2], clear: "value" },
};
const patch = {
// biome-ignore lint/style/useNamingConvention: server wire format
job_types: { compaction: { enabled: false } },
custom: { replace: [3], clear: null, label: "測試" },
};
const merged = {
// biome-ignore lint/style/useNamingConvention: server wire format
job_types: {
compaction: {
enabled: false,
// biome-ignore lint/style/useNamingConvention: server wire format
target_rows_per_fragment: 1000,
},
cleanup: { enabled: false },
},
custom: { keep: true, replace: [3], clear: null, label: "測試" },
};
await withMockDatabase(
(req, res) => {
const url = req.url ?? "";
if (url.includes("/describe/")) {
res
.writeHead(200)
.end(JSON.stringify({ version: 1, schema: { fields: [] } }));
return;
}
const chunks: Buffer[] = [];
req.on("data", (chunk) => chunks.push(chunk));
req.on("end", () => {
const body = chunks.length
? JSON.parse(Buffer.concat(chunks).toString())
: undefined;
requests.push({ method: req.method, url, body });
res
.writeHead(200)
.end(
JSON.stringify(
req.method === "GET"
? current
: req.method === "PUT"
? body.overrides
: {},
),
);
});
},
async (db) => {
const table = await db.openTable("test", namespacePath);
await expect(table.getTableOverrides()).resolves.toEqual(current);
await expect(table.updateTableOverrides(patch)).resolves.toEqual(
merged,
);
// The native conversion and merge must not mutate the caller's object.
expect(patch.job_types.compaction).toEqual({ enabled: false });
expect(patch.custom.replace).toEqual([3]);
await expect(table.resetTableOverrides()).resolves.toEqual({});
},
);
expect(requests.map((request) => request.method)).toEqual([
"GET",
"GET",
"PUT",
"POST",
]);
for (const request of requests) {
const url = new URL(request.url, "http://localhost");
expect(url.pathname).toBe(
request.method === "POST"
? "/admin/table/overrides/reset"
: "/admin/table/overrides",
);
if (request.method === "PUT") {
expect(request.body).toEqual({
db: "dev",
namespace: namespacePath,
table: "test",
overrides: merged,
});
} else {
expect(url.searchParams.get("db")).toBe("dev");
expect(url.searchParams.get("table")).toBe("test");
expect(url.searchParams.getAll("namespace")).toEqual(namespacePath);
}
}
},
);
it.each([{}, { custom: { keep: true } }])(
"only reads the snapshot %j for an empty update",
async (current) => {
const methods: string[] = [];
await withMockDatabase(
(req, res) => {
if (req.url?.includes("/describe/")) {
res
.writeHead(200)
.end(JSON.stringify({ version: 1, schema: { fields: [] } }));
return;
}
methods.push(req.method ?? "");
res
.writeHead(req.method === "GET" ? 200 : 400)
.end(JSON.stringify(current));
},
async (db) => {
const table = await db.openTable("test");
await expect(table.updateTableOverrides({})).resolves.toEqual(
current,
);
},
);
expect(methods).toEqual(["GET"]);
},
);
it.each([null, [], true, 1, "bad"])(
"rejects a non-object update %j before reading overrides",
async (value) => {
const requests: string[] = [];
await withMockDatabase(
(req, res) => {
requests.push(req.url ?? "");
res
.writeHead(200)
.end(JSON.stringify({ version: 1, schema: { fields: [] } }));
},
async (db) => {
const table = await db.openTable("test");
await expect(
table.updateTableOverrides(
value as unknown as Record<string, unknown>,
),
).rejects.toThrow(/must be a JSON object/);
},
);
expect(requests).toEqual(["/v1/table/test/describe/"]);
},
);
it.each([403, 404])(
"propagates GET failure %i without a PUT",
async (status) => {
const methods: string[] = [];
await withMockDatabase(
(req, res) => {
if (req.url?.includes("/describe/")) {
res
.writeHead(200)
.end(JSON.stringify({ version: 1, schema: { fields: [] } }));
} else {
methods.push(req.method ?? "");
res.writeHead(status).end("overrides unavailable");
}
},
async (db) => {
const table = await db.openTable("test");
await expect(
table.updateTableOverrides({ custom: true }),
).rejects.toThrow(/overrides unavailable/);
},
);
expect(methods).toEqual(["GET"]);
},
);
it("rejects writes on historical and closed handles before HTTP", async () => {
const requests: string[] = [];
await withMockDatabase(
(req, res) => {
requests.push(req.url ?? "");
res
.writeHead(200)
.end(JSON.stringify({ version: 1, schema: { fields: [] } }));
},
async (db) => {
const table = await db.openTable("test");
await table.checkout(1);
requests.length = 0;
await expect(
table.updateTableOverrides({ custom: true }),
).rejects.toThrow(/fixed at version 1/);
await expect(table.resetTableOverrides()).rejects.toThrow(
/fixed at version 1/,
);
table.close();
await expect(table.getTableOverrides()).rejects.toThrow(/closed/);
await expect(
table.updateTableOverrides({ custom: true }),
).rejects.toThrow(/closed/);
await expect(table.resetTableOverrides()).rejects.toThrow(/closed/);
},
);
expect(requests).toEqual([]);
});
});
+46
View File
@@ -5886,3 +5886,49 @@ describe("durable compaction validation", () => {
).rejects.toThrow("safe integer");
});
});
describe("Enterprise table overrides", () => {
it("keeps override methods optional for existing custom Table subclasses", async () => {
// Declare the old Table surface; only the new methods must be inherited.
// Keeping these override methods abstract must fail type checking here.
// biome-ignore lint/correctness/noUnusedVariables: declaration merging supplies the legacy members
interface LegacyTable
extends Omit<
Table,
"getTableOverrides" | "updateTableOverrides" | "resetTableOverrides"
> {}
class LegacyTable extends Table {}
const table = new LegacyTable();
await expect(table.getTableOverrides()).rejects.toThrow(
"getTableOverrides is not supported on this table type",
);
await expect(table.updateTableOverrides({ custom: true })).rejects.toThrow(
"updateTableOverrides is not supported on this table type",
);
await expect(table.resetTableOverrides()).rejects.toThrow(
"resetTableOverrides is not supported on this table type",
);
});
it("rejects get, update, and reset on local tables", async () => {
const tmpDir = tmp.dirSync({ unsafeCleanup: true });
const db = await connect(tmpDir.name);
const table = await db.createTable("items", [{ id: 1 }]);
try {
await expect(table.getTableOverrides()).rejects.toThrow(
/only on remote Enterprise tables/,
);
await expect(
table.updateTableOverrides({ custom: true }),
).rejects.toThrow(/only on remote Enterprise tables/);
await expect(table.resetTableOverrides()).rejects.toThrow(
/only on remote Enterprise tables/,
);
} finally {
table.close();
db.close();
tmpDir.removeCallback();
}
});
});
@@ -0,0 +1,166 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
import { randomUUID } from "node:crypto";
import { Connection, Table, connect } from "../lancedb";
// Run against an isolated Enterprise deployment:
// LANCEDB_TABLE_OVERRIDES_E2E=1 LANCEDB_URI=db://test \
// LANCEDB_HOST_OVERRIDE=http://localhost:10024 LANCEDB_API_KEY=... \
// pnpm test __test__/table_overrides_integration.test.ts --runInBand
const maybeDescribe = process.env.LANCEDB_TABLE_OVERRIDES_E2E
? describe
: describe.skip;
maybeDescribe("table overrides live integration", () => {
let db: Connection;
const namespace = [`overrides_${randomUUID().replaceAll("-", "_")}`];
const nested = [...namespace, "nested"];
const uri = process.env.LANCEDB_URI ?? "db://test";
const host = process.env.LANCEDB_HOST_OVERRIDE;
const apiKey = process.env.LANCEDB_API_KEY;
beforeAll(async () => {
if (!host || !apiKey) {
throw new Error(
"Set LANCEDB_HOST_OVERRIDE and LANCEDB_API_KEY for live tests",
);
}
db = await connect(uri, { apiKey, hostOverride: host });
await db.createNamespace(namespace);
await db.createNamespace(nested);
});
afterAll(async () => {
if (db) {
try {
await db.dropNamespace(nested);
await db.dropNamespace(namespace);
} finally {
db.close();
}
}
});
async function withTable(
namespacePath: string[],
run: (table: Table, name: string) => Promise<void>,
) {
const name = `items_${randomUUID().replaceAll("-", "_")}`;
const table = await db.createTable(name, [{ id: 1 }], namespacePath);
try {
await run(table, name);
} finally {
table.close();
await db.dropTable(name, namespacePath);
}
}
it.each([
{ label: "root", path: [] },
{ label: "nested", path: nested },
])(
"merges, replaces via REST, and resets in $label namespace",
async ({ path }) => {
await withTable(path, async (table, name) => {
await expect(table.getTableOverrides()).resolves.toEqual({});
await expect(table.updateTableOverrides({})).resolves.toEqual({});
const initial = {
// biome-ignore lint/style/useNamingConvention: server wire format
job_types: {
compaction: { enabled: false },
cleanup: { enabled: false },
},
custom: { keep: "測試", values: [1, 2], nullable: "old" },
};
await expect(table.updateTableOverrides(initial)).resolves.toEqual(
initial,
);
const patch = {
// biome-ignore lint/style/useNamingConvention: server wire format
job_types: { compaction: { enabled: true } },
custom: { values: [3], nullable: null },
};
const expected = {
// biome-ignore lint/style/useNamingConvention: server wire format
job_types: {
compaction: { enabled: true },
cleanup: { enabled: false },
},
custom: { keep: "測試", values: [3], nullable: null },
};
await expect(table.updateTableOverrides(patch)).resolves.toEqual(
expected,
);
await expect(table.getTableOverrides()).resolves.toEqual(expected);
await expect(table.updateTableOverrides({})).resolves.toEqual(expected);
const replacement = { custom: { replacement: true } };
const response = await fetch(`${host}/admin/table/overrides`, {
method: "PUT",
headers: { "x-api-key": apiKey!, "Content-Type": "application/json" },
body: JSON.stringify({
db: new URL(uri).hostname,
namespace: path,
table: name,
overrides: replacement,
}),
});
expect(response.status).toBe(200);
expect(await response.json()).toEqual(replacement);
await expect(table.getTableOverrides()).resolves.toEqual(replacement);
await expect(table.resetTableOverrides()).resolves.toEqual({});
await expect(table.getTableOverrides()).resolves.toEqual({});
await expect(table.countRows()).resolves.toBe(1);
});
},
);
it("isolates branch updates and resets from main", async () => {
await withTable(nested, async (table) => {
const initial = { custom: { main: true } };
await table.updateTableOverrides(initial);
const branch = await (await table.branches()).create("experiment");
try {
const expected = { custom: { main: true, branch: true } };
await expect(
branch.updateTableOverrides({ custom: { branch: true } }),
).resolves.toEqual(expected);
await expect(table.getTableOverrides()).resolves.toEqual(initial);
await expect(branch.resetTableOverrides()).resolves.toEqual({});
await expect(branch.getTableOverrides()).resolves.toEqual({});
await expect(table.getTableOverrides()).resolves.toEqual(initial);
} finally {
branch.close();
}
});
});
it("propagates server validation errors without changing stored overrides", async () => {
await withTable(nested, async (table) => {
const initial = { custom: { keep: true } };
await table.updateTableOverrides(initial);
await expect(
table.updateTableOverrides({
// biome-ignore lint/style/useNamingConvention: server wire format
auto_refresh_interval_seconds: -1,
}),
).rejects.toThrow();
await expect(table.getTableOverrides()).resolves.toEqual(initial);
});
});
it("rejects writes at a fixed version", async () => {
await withTable(nested, async (table) => {
await table.checkout(1);
await expect(
table.updateTableOverrides({ custom: true }),
).rejects.toThrow(/fixed at version/);
await expect(table.resetTableOverrides()).rejects.toThrow(
/fixed at version/,
);
await table.checkoutLatest();
await expect(table.getTableOverrides()).resolves.toEqual({});
});
});
});
+64
View File
@@ -1106,6 +1106,56 @@ export abstract class Table {
* @returns {Promise<RTEWriteSpec | undefined>}
*/
abstract getRTESpec(): Promise<RTEWriteSpec | undefined>;
/**
* Read the stored overrides for a remote Enterprise table.
*
* Overrides configure background behavior such as automatic compaction,
* cleanup, and reindex execution. Keys use the server's snake_case names.
* Returns an empty object when no overrides are set. Local tables are unsupported.
* Custom table implementations inherit a default rejection unless they override
* this method.
*/
async getTableOverrides(): Promise<Record<string, unknown>> {
throw new Error("getTableOverrides is not supported on this table type");
}
/**
* Recursively merge overrides into a remote Enterprise table's stored overrides.
*
* Fetches the current overrides, merges nested objects locally, then sends the
* complete replacement using REST PUT. Other values replace existing values;
* unrelated fields from the read snapshot are preserved. This read-modify-write
* is not atomic: concurrent edits can be overwritten, even to unrelated fields.
* Coordinate writers when concurrent edits must be preserved. An empty update
* only reads and returns the current overrides.
*
* Unlike this SDK method, CLI `set` and REST PUT replace the overrides object
* without merging. Use {@link Table.resetTableOverrides} to clear all overrides.
* Local tables and custom table implementations without override support reject
* this operation.
*
* @example
* ```ts
* await table.updateTableOverrides({
* job_types: { compaction: { enabled: false } },
* });
* ```
*/
async updateTableOverrides(
// biome-ignore lint/correctness/noUnusedVariables: retain the public parameter name in generated docs
overrides: Record<string, unknown>,
): Promise<Record<string, unknown>> {
throw new Error("updateTableOverrides is not supported on this table type");
}
/**
* Clear a remote Enterprise table's overrides and return an empty object.
* Local tables and custom table implementations without override support reject
* this operation.
*/
async resetTableOverrides(): Promise<Record<string, unknown>> {
throw new Error("resetTableOverrides is not supported on this table type");
}
/**
* Drain and close any cached RTE shard writers held for this table.
*
@@ -1916,6 +1966,20 @@ export class LocalTable extends Table {
| undefined;
}
async getTableOverrides(): Promise<Record<string, unknown>> {
return await this.inner.getTableOverrides();
}
async updateTableOverrides(
overrides: Record<string, unknown>,
): Promise<Record<string, unknown>> {
return await this.inner.updateTableOverrides(overrides);
}
async resetTableOverrides(): Promise<Record<string, unknown>> {
return await this.inner.resetTableOverrides();
}
async closeRTEWriters(): Promise<void> {
return await this.inner.closeRTEWriters();
}
+31
View File
@@ -821,6 +821,37 @@ impl Table {
Ok(spec.map(RTEWriteSpec::from))
}
#[napi(catch_unwind, ts_return_type = "Promise<Record<string, unknown>>")]
pub async fn get_table_overrides(&self) -> napi::Result<serde_json::Value> {
self.inner_ref()?
.get_table_overrides()
.await
.default_error()
}
#[napi(
catch_unwind,
ts_args_type = "overrides: Record<string, unknown>",
ts_return_type = "Promise<Record<string, unknown>>"
)]
pub async fn update_table_overrides(
&self,
overrides: serde_json::Value,
) -> napi::Result<serde_json::Value> {
self.inner_ref()?
.update_table_overrides(overrides)
.await
.default_error()
}
#[napi(catch_unwind, ts_return_type = "Promise<Record<string, unknown>>")]
pub async fn reset_table_overrides(&self) -> napi::Result<serde_json::Value> {
self.inner_ref()?
.reset_table_overrides()
.await
.default_error()
}
#[napi(catch_unwind, js_name = "closeRTEWriters")]
pub async fn close_rte_writers(&self) -> napi::Result<()> {
self.inner_ref()?.close_rte_writers().await.default_error()
+5 -1
View File
@@ -1380,7 +1380,11 @@ class RemoteTable(Table):
return LOOP.run(self._table.get_table_overrides())
def update_table_overrides(self, **overrides: Any) -> dict[str, Any]:
"""Merge Enterprise table overrides into the current table overrides."""
"""Merge Enterprise table overrides using a non-atomic read-modify-write.
See [the async method][lancedb.AsyncTable.update_table_overrides]
for merge behavior and concurrency limitations.
"""
return LOOP.run(self._table.update_table_overrides(**overrides))
def reset_table_overrides(self) -> dict[str, Any]:
+30 -6
View File
@@ -2115,8 +2115,16 @@ class Table(ABC):
def update_table_overrides(self, **overrides: Any) -> dict[str, Any]:
"""Merge Enterprise table overrides into the current table overrides.
Only fields supplied in ``overrides`` are changed; unrelated existing
overrides are preserved by the remote service update flow.
Fetches the current overrides, recursively merges nested objects locally,
then sends the complete replacement using REST PUT. Other values replace
existing values; unrelated fields from the read snapshot are preserved.
This read-modify-write is not atomic: concurrent edits can be overwritten,
even to unrelated fields. Coordinate writers when concurrent edits must
be preserved. An empty update only reads and returns the current overrides.
Unlike this SDK method, CLI ``set`` and REST PUT replace the overrides
object without merging. Use ``reset_table_overrides()`` to clear all
overrides. Supported only on remote Enterprise tables.
"""
raise NotImplementedError
@@ -6183,8 +6191,16 @@ class LanceTable(Table):
def update_table_overrides(self, **overrides: Any) -> dict[str, Any]:
"""Merge Enterprise table overrides into the current table overrides.
Only fields supplied in ``overrides`` are changed; unrelated overrides
from the current read snapshot are preserved.
Fetches the current overrides, recursively merges nested objects locally,
then sends the complete replacement using REST PUT. Other values replace
existing values; unrelated fields from the read snapshot are preserved.
This read-modify-write is not atomic: concurrent edits can be overwritten,
even to unrelated fields. Coordinate writers when concurrent edits must
be preserved. An empty update only reads and returns the current overrides.
Unlike this SDK method, CLI ``set`` and REST PUT replace the overrides
object without merging. Use ``reset_table_overrides()`` to clear all
overrides. Supported only on remote Enterprise tables.
Examples
--------
@@ -6962,8 +6978,16 @@ class AsyncTable:
async def update_table_overrides(self, **overrides: Any) -> dict[str, Any]:
"""Merge Enterprise table overrides into the current table overrides.
Only fields supplied in ``overrides`` are changed; unrelated overrides
from the current read snapshot are preserved.
Fetches the current overrides, recursively merges nested objects locally,
then sends the complete replacement using REST PUT. Other values replace
existing values; unrelated fields from the read snapshot are preserved.
This read-modify-write is not atomic: concurrent edits can be overwritten,
even to unrelated fields. Coordinate writers when concurrent edits must
be preserved. An empty update only reads and returns the current overrides.
Unlike this SDK method, CLI ``set`` and REST PUT replace the overrides
object without merging. Use ``reset_table_overrides()`` to clear all
overrides. Supported only on remote Enterprise tables.
Examples
--------
+17
View File
@@ -4016,6 +4016,23 @@ def test_update_table_overrides_sync_remote_table_merges_existing_fields():
assert calls == ["GET", "PUT"]
@pytest.mark.parametrize("current", [{}, {"custom": {"keep": True}}])
def test_empty_update_table_overrides_only_reads(current):
calls = []
def overrides_handler(request, parsed):
calls.append(request.command)
assert request.command == "GET"
assert parsed.path == "/admin/table/overrides"
assert_table_overrides_query(parsed)
send_json(request, current)
with table_overrides_test_table(overrides_handler) as table:
assert table.update_table_overrides() == current
assert calls == ["GET"]
def test_reset_table_overrides_sync_remote_table():
def overrides_handler(request, parsed):
assert request.command == "POST"
+28
View File
@@ -3984,6 +3984,9 @@ impl<S: HttpSend> BaseTable for RemoteTable<S> {
});
}
};
if patch.is_empty() {
return Ok(serde_json::Value::Object(current));
}
Self::merge_table_overrides(&mut current, patch);
let merged = serde_json::Value::Object(current);
let body = self.table_overrides_set_body(merged);
@@ -14158,6 +14161,31 @@ mod tests {
assert_eq!(calls.load(std::sync::atomic::Ordering::SeqCst), 2);
}
#[tokio::test]
async fn test_update_table_overrides_empty_patch_only_reads() {
for current in [
serde_json::json!({}),
serde_json::json!({"job_types": {"compaction": {"enabled": false}}}),
] {
let snapshot = current.clone();
let table = Table::new_with_handler("my_table", move |request| {
assert_eq!(request.method(), "GET");
assert_eq!(request.url().path(), "/admin/table/overrides");
http::Response::builder()
.status(200)
.body(snapshot.to_string())
.unwrap()
});
assert_eq!(
table
.update_table_overrides(serde_json::json!({}))
.await
.unwrap(),
current
);
}
}
#[tokio::test]
async fn test_reset_table_overrides() {
let table = Table::new_with_handler("my_table", |request| {
+10 -3
View File
@@ -2736,9 +2736,16 @@ impl Table {
/// Merge Enterprise table overrides into the current stored overrides.
///
/// This method uses patch semantics: fields present in `overrides` are
/// recursively merged into the existing table overrides and unrelated fields
/// are preserved.
/// Fetches the current overrides, recursively merges nested objects locally,
/// then sends the complete replacement using REST PUT. Other values replace
/// existing values; unrelated fields from the read snapshot are preserved.
/// This read-modify-write is not atomic: concurrent edits can be overwritten,
/// even to unrelated fields. Coordinate writers when concurrent edits must
/// be preserved. An empty update only reads and returns the current overrides.
///
/// Unlike this SDK method, CLI `set` and REST PUT replace the overrides object
/// without merging. Use [`Self::reset_table_overrides`] to clear all overrides.
/// Supported only on remote Enterprise tables.
pub async fn update_table_overrides(
&self,
overrides: TableOverrides,