kevinjqliu commented on code in PR #1246: URL: https://github.com/apache/iceberg-python/pull/1246#discussion_r1819883002
########## tests/integration/test_writes/test_writes.py: ########## @@ -1448,3 +1448,26 @@ def test_rewrite_manifest_after_partition_evolution(session_catalog: Catalog) -> EqualTo("category", "A"), ), ) + + +@pytest.mark.integration +@pytest.mark.parametrize("format_version", [1, 2]) +def test_abort_table_transaction_on_exception( + spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int +) -> None: + identifier = "default.table_test_abort_table_transaction_on_exception" + tbl = _create_table(session_catalog, identifier, properties={"format-version": format_version}) + + # Pre-populate some data + tbl.append(arrow_table_with_null) + assert len(tbl.scan().to_pandas()) == 3 + + # try to commit a transaction that raises exception at the middle + with pytest.raises(ValueError): + with tbl.transaction() as txn: + txn.append(arrow_table_with_null) + raise ValueError + txn.append(arrow_table_with_null) # type: ignore + + # Validate the transaction is aborted + assert len(tbl.scan().to_pandas()) == 3 # type: ignore Review Comment: nit: show that we're checking its still the same table size ```suggestion # Validate the transaction is aborted and no partial update is applied assert len(tbl.scan().to_pandas()) == table_size ``` ########## tests/integration/test_writes/test_writes.py: ########## @@ -1448,3 +1448,26 @@ def test_rewrite_manifest_after_partition_evolution(session_catalog: Catalog) -> EqualTo("category", "A"), ), ) + + +@pytest.mark.integration +@pytest.mark.parametrize("format_version", [1, 2]) +def test_abort_table_transaction_on_exception( + spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int +) -> None: + identifier = "default.table_test_abort_table_transaction_on_exception" + tbl = _create_table(session_catalog, identifier, properties={"format-version": format_version}) + + # Pre-populate some data + tbl.append(arrow_table_with_null) + assert len(tbl.scan().to_pandas()) == 3 Review Comment: nit: in case `arrow_table_with_null` size changes later ```suggestion table_size = len(arrow_table_with_null) assert len(tbl.scan().to_pandas()) == table_size ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org