|
19 | 19 | from pathlib import Path |
20 | 20 | from typing import Generator, List |
21 | 21 |
|
| 22 | +import pyarrow as pa |
22 | 23 | import pytest |
23 | 24 | from pytest import TempPathFactory |
24 | 25 | from pytest_lazyfixture import lazy_fixture |
|
35 | 36 | NoSuchTableError, |
36 | 37 | TableAlreadyExistsError, |
37 | 38 | ) |
| 39 | +from pyiceberg.io.pyarrow import schema_to_pyarrow |
38 | 40 | from pyiceberg.schema import Schema |
| 41 | +from pyiceberg.table.snapshots import Operation |
39 | 42 | from pyiceberg.table.sorting import ( |
40 | 43 | NullOrder, |
41 | 44 | SortDirection, |
@@ -722,6 +725,46 @@ def test_commit_table(catalog: SqlCatalog, table_schema_nested: Schema, random_i |
722 | 725 | assert new_schema.find_field("b").field_type == IntegerType() |
723 | 726 |
|
724 | 727 |
|
| 728 | +@pytest.mark.parametrize( |
| 729 | + 'catalog', |
| 730 | + [ |
| 731 | + lazy_fixture('catalog_memory'), |
| 732 | + lazy_fixture('catalog_sqlite'), |
| 733 | + lazy_fixture('catalog_sqlite_without_rowcount'), |
| 734 | + ], |
| 735 | +) |
| 736 | +def test_append_table(catalog: SqlCatalog, table_schema_simple: Schema, random_identifier: Identifier) -> None: |
| 737 | + database_name, _table_name = random_identifier |
| 738 | + catalog.create_namespace(database_name) |
| 739 | + table = catalog.create_table(random_identifier, table_schema_simple) |
| 740 | + |
| 741 | + df = pa.Table.from_pydict( |
| 742 | + { |
| 743 | + "foo": ["a"], |
| 744 | + "bar": [1], |
| 745 | + "baz": [True], |
| 746 | + }, |
| 747 | + schema=schema_to_pyarrow(table_schema_simple), |
| 748 | + ) |
| 749 | + |
| 750 | + table.append(df) |
| 751 | + |
| 752 | + # new snapshot is written in APPEND mode |
| 753 | + assert len(table.metadata.snapshots) == 1 |
| 754 | + assert table.metadata.snapshots[0].snapshot_id == table.metadata.current_snapshot_id |
| 755 | + assert table.metadata.snapshots[0].parent_snapshot_id is None |
| 756 | + assert table.metadata.snapshots[0].sequence_number == 1 |
| 757 | + assert table.metadata.snapshots[0].summary is not None |
| 758 | + assert table.metadata.snapshots[0].summary.operation == Operation.APPEND |
| 759 | + assert table.metadata.snapshots[0].summary['added-data-files'] == '1' |
| 760 | + assert table.metadata.snapshots[0].summary['added-records'] == '1' |
| 761 | + assert table.metadata.snapshots[0].summary['total-data-files'] == '1' |
| 762 | + assert table.metadata.snapshots[0].summary['total-records'] == '1' |
| 763 | + |
| 764 | + # read back the data |
| 765 | + assert df == table.scan().to_arrow() |
| 766 | + |
| 767 | + |
725 | 768 | @pytest.mark.parametrize( |
726 | 769 | 'catalog', |
727 | 770 | [ |
|
0 commit comments