|
19 | 19 | import shutil |
20 | 20 | import tempfile |
21 | 21 | import unittest |
| 22 | +from unittest.mock import patch |
22 | 23 |
|
23 | 24 | import pyarrow as pa |
24 | 25 |
|
@@ -591,6 +592,65 @@ def test_read_projection(self): |
591 | 592 | % actual_columns |
592 | 593 | ) |
593 | 594 |
|
| 595 | + def test_shard_update_passes_allow_rollback_true(self): |
| 596 | + table_schema = pa.schema([ |
| 597 | + ('a', pa.int32()), |
| 598 | + ('b', pa.int32()), |
| 599 | + ]) |
| 600 | + schema = Schema.from_pyarrow_schema( |
| 601 | + table_schema, |
| 602 | + options={'row-tracking.enabled': 'true', 'data-evolution.enabled': 'true'} |
| 603 | + ) |
| 604 | + name = self._create_unique_table_name('rollback') |
| 605 | + self.catalog.create_table(name, schema, False) |
| 606 | + table = self.catalog.get_table(name) |
| 607 | + |
| 608 | + write_builder = table.new_batch_write_builder() |
| 609 | + tw = write_builder.new_write().with_write_type(['a', 'b']) |
| 610 | + tc = write_builder.new_commit() |
| 611 | + tw.write_arrow(pa.Table.from_pydict( |
| 612 | + {'a': [1, 2], 'b': [10, 20]}, |
| 613 | + schema=table_schema, |
| 614 | + )) |
| 615 | + tc.commit(tw.prepare_commit()) |
| 616 | + tw.close() |
| 617 | + tc.close() |
| 618 | + |
| 619 | + upd = write_builder.new_update() |
| 620 | + upd.with_read_projection(['a']) |
| 621 | + upd.with_update_type(['b']) |
| 622 | + shard = upd.new_shard_updator(0, 1) |
| 623 | + reader = shard.arrow_reader() |
| 624 | + for batch in iter(reader.read_next_batch, None): |
| 625 | + shard.update_by_arrow_batch(pa.RecordBatch.from_pydict( |
| 626 | + {'b': [99] * batch.num_rows}, |
| 627 | + schema=pa.schema([('b', pa.int32())]), |
| 628 | + )) |
| 629 | + commit_messages = shard.prepare_commit() |
| 630 | + |
| 631 | + from pypaimon.write.file_store_commit import FileStoreCommit |
| 632 | + original_try_commit = FileStoreCommit._try_commit |
| 633 | + captured_args = {} |
| 634 | + |
| 635 | + def spy_try_commit(self_inner, **kwargs): |
| 636 | + captured_args.update(kwargs) |
| 637 | + return original_try_commit(self_inner, **kwargs) |
| 638 | + |
| 639 | + with patch.object(FileStoreCommit, '_try_commit', spy_try_commit): |
| 640 | + tc2 = write_builder.new_commit() |
| 641 | + tc2.commit(commit_messages) |
| 642 | + tc2.close() |
| 643 | + |
| 644 | + self.assertTrue( |
| 645 | + captured_args.get('allow_rollback', False), |
| 646 | + "Row-id-check commits must pass allow_rollback=True so that " |
| 647 | + "concurrent COMPACT snapshots can be rolled back on conflict." |
| 648 | + ) |
| 649 | + self.assertTrue( |
| 650 | + captured_args.get('detect_conflicts', False), |
| 651 | + "Row-id-check commits must enable conflict detection." |
| 652 | + ) |
| 653 | + |
594 | 654 |
|
595 | 655 | if __name__ == '__main__': |
596 | 656 | unittest.main() |
0 commit comments