|
22 | 22 | import tempfile |
23 | 23 | import unittest |
24 | 24 |
|
| 25 | +import pyarrow as pa |
| 26 | + |
25 | 27 | from pypaimon import CatalogFactory, Schema |
26 | 28 | from pypaimon.catalog.catalog_exception import ( |
27 | 29 | DatabaseAlreadyExistException, |
@@ -190,6 +192,30 @@ def fail_insert_table_properties(identifier, properties): |
190 | 192 | self.assertEqual(table_count, 0) |
191 | 193 | self.assertFalse(os.path.exists(os.path.join(self.warehouse, "test_db.db", "test_table"))) |
192 | 194 |
|
| 195 | + def test_drop_main_branch_preserves_table(self): |
| 196 | + with CatalogFactory.create(self.options) as catalog: |
| 197 | + catalog.create_database("test_db", False) |
| 198 | + data = pa.table({"id": [1]}) |
| 199 | + catalog.create_table("test_db.test_table", Schema.from_pyarrow_schema(data.schema), False) |
| 200 | + table = catalog.get_table("test_db.test_table") |
| 201 | + builder = table.new_batch_write_builder() |
| 202 | + writer = builder.new_write() |
| 203 | + try: |
| 204 | + writer.write_arrow(data) |
| 205 | + builder.new_commit().commit(writer.prepare_commit()) |
| 206 | + finally: |
| 207 | + writer.close() |
| 208 | + |
| 209 | + with self.assertRaisesRegex(ValueError, r"^The main branch cannot be deleted\.$"): |
| 210 | + table.branch_manager().drop_branch("main") |
| 211 | + self.assertTrue(os.path.isdir(table.table_path)) |
| 212 | + table = catalog.get_table("test_db.test_table") |
| 213 | + reader = table.new_read_builder() |
| 214 | + self.assertEqual( |
| 215 | + reader.new_read().to_arrow(reader.new_scan().plan().splits()).to_pydict(), |
| 216 | + {"id": [1]}, |
| 217 | + ) |
| 218 | + |
193 | 219 | def test_rename_table_keeps_metadata_when_file_move_fails(self): |
194 | 220 | fields = [DataField.from_dict({"id": 1, "name": "f0", "type": "INT"})] |
195 | 221 | catalog = CatalogFactory.create(self.options) |
|
0 commit comments