mirror of
https://github.com/lancedb/lancedb.git
synced 2026-10-30 07:16:52 +00:00
fix(node): support specifying arrow field types by name (#2704)
The [`FieldLike` type in arrow.ts](https://github.com/lancedb/lancedb/blob/5ec12c99713e28a8fa550547cc9e7536da063f6e/nodejs/lancedb/arrow.ts#L71-L78) can have a `type: string` property, but before this change, actually trying to create a table that has a schema that specifies field types by name results in an error: ``` Error: Expected a Type but object was null/undefined ``` This change adds support for mapping some type name strings to arrow `DataType`s, so that passing `FieldLike`s with a `type: string` property to `sanitizeField` does not throw an error. The type names that can be passed are upper/lowercase variations of the keys of the `constructorsByTypeName` object. This does not support mapping types that need parameters, such as timestamps which need timezones. With this, it is possible to create empty tables from `SchemaLike` objects without instantiating arrow types, e.g.: ``` import { SchemaLike } from "../lancedb/arrow" // ... const schemaLike = { fields: [ { name: "id", type: "int64", nullable: true, }, { name: "vector", type: "float64", nullable: true, }, ], // ... } satisfies SchemaLike; const table = await con.createEmptyTable("test", schemaLike); ``` This change also makes `FieldLike.nullable` required since the `sanitizeField` function throws if it is undefined.
This commit is contained in:
@@ -73,7 +73,7 @@ export type FieldLike =
|
||||
| {
|
||||
type: string;
|
||||
name: string;
|
||||
nullable?: boolean;
|
||||
nullable: boolean;
|
||||
metadata?: Map<string, string>;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user