@@ -50,6 +50,43 @@ You will need to provide a :py:class:`pyarrow.Schema` for the dataset in this ca
50
50
:py:meth: `lance.write_dataset ` supports writing :py:class: `pyarrow.Table `, :py:class: `pandas.DataFrame `,
51
51
:py:class: `pyarrow.dataset.Dataset `, and ``Iterator[pyarrow.RecordBatch] ``.
52
52
53
+ Adding Rows
54
+ -----------
55
+
56
+ To insert data into your dataset, you can use either :py:meth: `LanceDataset.insert <lance.LanceDataset.insert> `
57
+ or :py:meth: `~lance.write_dataset ` with ``mode=append ``.
58
+
59
+ .. testsetup ::
60
+
61
+ shutil.rmtree("./insert_example.lance", ignore_errors=True)
62
+
63
+ .. doctest ::
64
+
65
+ >>> import lance
66
+ >>> import pyarrow as pa
67
+
68
+ >>> table = pa.Table.from_pylist([{" name" : " Alice" , " age" : 20 },
69
+ ... {" name" : " Bob" , " age" : 30 }])
70
+ >>> ds = lance.write_dataset(table, " ./insert_example.lance" )
71
+
72
+ >>> new_table = pa.Table.from_pylist([{" name" : " Carla" , " age" : 37 }])
73
+ >>> ds.insert(new_table)
74
+ >>> ds.to_table().to_pandas()
75
+ name age
76
+ 0 Alice 20
77
+ 1 Bob 30
78
+ 2 Carla 37
79
+
80
+ >>> new_table2 = pa.Table.from_pylist([{" name" : " David" , " age" : 42 }])
81
+ >>> ds = lance.write_dataset(new_table2, ds, mode = " append" )
82
+ >>> ds.to_table().to_pandas()
83
+ name age
84
+ 0 Alice 20
85
+ 1 Bob 30
86
+ 2 Carla 37
87
+ 3 David 42
88
+
89
+
53
90
Deleting rows
54
91
-------------
55
92
@@ -123,7 +160,7 @@ more efficient to use the merge insert operation described below.
123
160
dataset.update({" age" : new_age}, where = f " name=' { name} ' " )
124
161
125
162
Merge Insert
126
- ~~~~~~~~~~~~
163
+ ------------
127
164
128
165
Lance supports a merge insert operation. This can be used to add new data in bulk
129
166
while also (potentially) matching against existing data. This operation can be used
0 commit comments