mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
`Table.update({ values })` accepts `ArrayBufferLike` in TypeScript, but
passing a `SharedArrayBuffer` to update a binary column throws
`Unsupported value type: object value: ([object SharedArrayBuffer])`. An
ordinary `ArrayBuffer` created in another Node.js VM context also fails
the serializer's `instanceof ArrayBuffer` check.
Use Node's `isAnyArrayBuffer` to recognize both kinds of buffer across
contexts, then pass their bytes through the existing SQL binary literal
encoder.
The table regression writes `00 80 ff` from shared memory and reads the
bytes back on each supported Arrow major (15–21). A separate serializer
test covers an `ArrayBuffer` from another VM context. All eight cases
failed before the fix.
### Validation
- Node 22 on macOS arm64, using the upstream native build from
`0d735c9`: both complete Jest files passed (701 passed, 3 skipped).
- Node SDK Biome checks and strict TypeScript checks for the serializer
and its unit tests passed. The full SDK type check reported the same ten
diagnostics on the base commit and patched tree with this local setup
(optional embedding packages and older native reranker declarations).
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
|
|
import { runInNewContext } from "node:vm";
|
|
import { IntoSql, toSQL } from "../lancedb/util";
|
|
test.each([
|
|
["string", "'string'"],
|
|
[123, "123"],
|
|
[1.11, "1.11"],
|
|
[true, "TRUE"],
|
|
[false, "FALSE"],
|
|
[null, "NULL"],
|
|
[new Date("2021-01-01T00:00:00.000Z"), "'2021-01-01T00:00:00.000Z'"],
|
|
[[1, 2, 3], "[1, 2, 3]"],
|
|
[new ArrayBuffer(8), "X'0000000000000000'"],
|
|
[Buffer.from("hello"), "X'68656c6c6f'"],
|
|
["Hello 'world'", "'Hello ''world'''"],
|
|
[NaN, "CAST('NaN' AS DOUBLE)"],
|
|
[Infinity, "CAST('Infinity' AS DOUBLE)"],
|
|
[-Infinity, "CAST('-Infinity' AS DOUBLE)"],
|
|
])("toSQL(%p) === %p", (value, expected) => {
|
|
expect(toSQL(value)).toBe(expected);
|
|
});
|
|
|
|
test("toSQL serializes an ArrayBuffer from another realm", () => {
|
|
const buffer: ArrayBuffer = runInNewContext(
|
|
"Uint8Array.of(0, 128, 255).buffer",
|
|
);
|
|
expect(toSQL(buffer)).toBe("X'0080ff'");
|
|
});
|
|
|
|
test("toSQL({}) throws on unsupported value type", () => {
|
|
expect(() => toSQL({} as unknown as IntoSql)).toThrow(
|
|
"Unsupported value type: object value: ([object Object])",
|
|
);
|
|
});
|
|
test("toSQL() throws on unsupported value type", () => {
|
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
expect(() => (<any>toSQL)()).toThrow(
|
|
"Unsupported value type: undefined value: (undefined)",
|
|
);
|
|
});
|