mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-10 13:52:58 +00:00
fix(nodejs): workaround for apache-arrow null vector issue (#2244)
Fixes #2240
This commit is contained in:
@@ -279,6 +279,15 @@ describe.each([arrow15, arrow16, arrow17, arrow18])(
|
||||
expect(res.getChild("y")?.toJSON()).toEqual([2, null, null, null]);
|
||||
expect(res.getChild("z")?.toJSON()).toEqual([null, null, 3n, 5n]);
|
||||
});
|
||||
|
||||
it("should handle null vectors at end of data", async () => {
|
||||
// https://github.com/lancedb/lancedb/issues/2240
|
||||
const data = [{ vector: [1, 2, 3] }, { vector: null }];
|
||||
const db = await connect("memory://");
|
||||
|
||||
const table = await db.createTable("my_table", data);
|
||||
expect(await table.countRows()).toEqual(2);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -37,10 +37,10 @@ import {
|
||||
Utf8,
|
||||
Vector,
|
||||
makeVector as arrowMakeVector,
|
||||
vectorFromArray as badVectorFromArray,
|
||||
makeBuilder,
|
||||
makeData,
|
||||
makeTable,
|
||||
vectorFromArray,
|
||||
} from "apache-arrow";
|
||||
import { Buffers } from "apache-arrow/data";
|
||||
import { type EmbeddingFunction } from "./embedding/embedding_function";
|
||||
@@ -186,6 +186,21 @@ export class VectorColumnOptions {
|
||||
}
|
||||
}
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: skip
|
||||
function vectorFromArray(data: any, type?: DataType) {
|
||||
// Workaround for: https://github.com/apache/arrow/issues/45862
|
||||
// If FSL type with float
|
||||
if (DataType.isFixedSizeList(type) && DataType.isFloat(type.valueType)) {
|
||||
const extendedData = [...data, new Array(type.listSize).fill(0.0)];
|
||||
const array = badVectorFromArray(extendedData, type);
|
||||
return array.slice(0, data.length);
|
||||
} else if (type === undefined) {
|
||||
return badVectorFromArray(data);
|
||||
} else {
|
||||
return badVectorFromArray(data, type);
|
||||
}
|
||||
}
|
||||
|
||||
/** Options to control the makeArrowTable call. */
|
||||
export class MakeArrowTableOptions {
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user