feat(node): parse arrow types in alterColumns() (#2208)

Previously, users could only specify new data types in `alterColumns` as
strings:

```ts
await tbl.alterColumns([
  path: "price",
  dataType: "float"
]);
```

But this has some problems:

1. It wasn't clear what were valid types
2. It was impossible to specify nested types, like lists and vector
columns.

This PR changes it to take an Arrow data type, similar to how the Python
API works. This allows casting vector types:

```ts
await tbl.alterColumns([
  {
    path: "vector",
    dataType: new arrow.FixedSizeList(
      2,
      new arrow.Field("item", new arrow.Float16(), false),
    ),
  },
]);
```

Closes #2185
This commit is contained in:
Will Jones
2025-03-12 09:57:36 -07:00
committed by GitHub
parent c9d6fc43a6
commit 7747c9bcbf
10 changed files with 365 additions and 12 deletions

View File

@@ -942,6 +942,28 @@ rewriting the column, which can be a heavy operation.
```
**API Reference:** [lancedb.Table.alterColumns](../js/classes/Table.md/#altercolumns)
You can even cast the a vector column to a different dimension:
=== "Python"
=== "Sync API"
```python
--8<-- "python/python/tests/docs/test_guide_tables.py:import-pyarrow"
--8<-- "python/python/tests/docs/test_basic.py:alter_columns_vector"
```
=== "Async API"
```python
--8<-- "python/python/tests/docs/test_guide_tables.py:import-pyarrow"
--8<-- "python/python/tests/docs/test_basic.py:alter_columns_async_vector"
```
=== "Typescript"
```typescript
--8<-- "nodejs/examples/basic.test.ts:alter_columns_vector"
```
### Dropping columns
You can drop columns from the table with the `drop_columns` method. This will

View File

@@ -16,7 +16,7 @@ must be provided.
### dataType?
```ts
optional dataType: string;
optional dataType: string | DataType<Type, any>;
```
A new data type for the column. If not provided then the data type will not be changed.