@@ -50,6 +50,44 @@ 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 data to an existing dataset
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
+ >>> tbl = lance.dataset(" ./insert_example.lance" ).to_table()
75
+ >>> tbl.to_pandas()
76
+ name age
77
+ 0 Alice 20
78
+ 1 Bob 30
79
+ 2 Carla 37
80
+
81
+ >>> new_table2 = pa.Table.from_pylist([{" name" : " David" , " age" : 42 }])
82
+ >>> ds2 = lance.write_dataset(new_table2, " ./insert_example.lance" , mode = " append" )
83
+ >>> ds2.to_table().to_pandas()
84
+ name age
85
+ 0 Alice 20
86
+ 1 Bob 30
87
+ 2 Carla 37
88
+ 3 David 42
89
+
90
+
53
91
Deleting rows
54
92
-------------
55
93
0 commit comments