mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-06 20:02:58 +00:00
docs: improve schema evolution api examples (#1929)
This commit is contained in:
@@ -804,12 +804,13 @@ a table:
|
|||||||
|
|
||||||
You can add new columns to the table with the `add_columns` method. New columns
|
You can add new columns to the table with the `add_columns` method. New columns
|
||||||
are filled with values based on a SQL expression. For example, you can add a new
|
are filled with values based on a SQL expression. For example, you can add a new
|
||||||
column `y` to the table and fill it with the value of `x + 1`.
|
column `y` to the table, fill it with the value of `x * 2` and set the expected
|
||||||
|
data type for it.
|
||||||
|
|
||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
```python
|
```python
|
||||||
table.add_columns({"double_price": "price * 2"})
|
--8<-- "python/python/tests/docs/test_basic.py:add_columns"
|
||||||
```
|
```
|
||||||
**API Reference:** [lancedb.table.Table.add_columns][]
|
**API Reference:** [lancedb.table.Table.add_columns][]
|
||||||
|
|
||||||
@@ -849,8 +850,7 @@ rewriting the column, which can be a heavy operation.
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
import pyarrow as pa
|
import pyarrow as pa
|
||||||
table.alter_column({"path": "double_price", "rename": "dbl_price",
|
--8<-- "python/python/tests/docs/test_basic.py:alter_columns"
|
||||||
"data_type": pa.float32(), "nullable": False})
|
|
||||||
```
|
```
|
||||||
**API Reference:** [lancedb.table.Table.alter_columns][]
|
**API Reference:** [lancedb.table.Table.alter_columns][]
|
||||||
|
|
||||||
@@ -873,7 +873,7 @@ will remove the column from the schema.
|
|||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
```python
|
```python
|
||||||
table.drop_columns(["dbl_price"])
|
--8<-- "python/python/tests/docs/test_basic.py:drop_columns"
|
||||||
```
|
```
|
||||||
**API Reference:** [lancedb.table.Table.drop_columns][]
|
**API Reference:** [lancedb.table.Table.drop_columns][]
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,9 @@ test("basic table examples", async () => {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// --8<-- [start:add_columns]
|
// --8<-- [start:add_columns]
|
||||||
await tbl.addColumns([{ name: "double_price", valueSql: "price * 2" }]);
|
await tbl.addColumns([
|
||||||
|
{ name: "double_price", valueSql: "cast((price * 2) as Float)" },
|
||||||
|
]);
|
||||||
// --8<-- [end:add_columns]
|
// --8<-- [end:add_columns]
|
||||||
// --8<-- [start:alter_columns]
|
// --8<-- [start:alter_columns]
|
||||||
await tbl.alterColumns([
|
await tbl.alterColumns([
|
||||||
|
|||||||
@@ -75,6 +75,22 @@ def test_quickstart():
|
|||||||
for _ in range(1000)
|
for _ in range(1000)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
# --8<-- [start:add_columns]
|
||||||
|
tbl.add_columns({"double_price": "cast((price * 2) as float)"})
|
||||||
|
# --8<-- [end:add_columns]
|
||||||
|
# --8<-- [start:alter_columns]
|
||||||
|
tbl.alter_columns(
|
||||||
|
{
|
||||||
|
"path": "double_price",
|
||||||
|
"rename": "dbl_price",
|
||||||
|
"data_type": pa.float64(),
|
||||||
|
"nullable": True,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# --8<-- [end:alter_columns]
|
||||||
|
# --8<-- [start:drop_columns]
|
||||||
|
tbl.drop_columns(["dbl_price"])
|
||||||
|
# --8<-- [end:drop_columns]
|
||||||
# --8<-- [start:create_index]
|
# --8<-- [start:create_index]
|
||||||
# Synchronous client
|
# Synchronous client
|
||||||
tbl.create_index(num_sub_vectors=1)
|
tbl.create_index(num_sub_vectors=1)
|
||||||
|
|||||||
Reference in New Issue
Block a user