Skip to content

Commit 962c771

Browse files
committed
explicit decl of expected schemas, lint
1 parent 3ddef45 commit 962c771

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

mkdocs/docs/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ Expert Iceberg users may choose to commit existing parquet files to the Iceberg
10311031
### Example
10321032

10331033
Add files to Iceberg table:
1034+
10341035
```python
10351036
# Given that these parquet files have schema consistent with the Iceberg table
10361037
@@ -1047,6 +1048,7 @@ tbl.add_files(file_paths=file_paths)
10471048
```
10481049

10491050
Add files to Iceberg table with custom snapshot properties:
1051+
10501052
```python
10511053
# Assume an existing Iceberg table object `tbl`
10521054

tests/integration/test_catalog.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
TableAlreadyExistsError,
3535
)
3636
from pyiceberg.io import WAREHOUSE
37-
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec
37+
from pyiceberg.partitioning import PartitionField, PartitionSpec
3838
from pyiceberg.schema import INITIAL_SCHEMA_ID, Schema
3939
from pyiceberg.table.metadata import INITIAL_SPEC_ID
4040
from pyiceberg.table.sorting import INITIAL_SORT_ORDER_ID, SortField, SortOrder
41-
from pyiceberg.transforms import IdentityTransform
42-
from pyiceberg.types import IntegerType, LongType, UUIDType
41+
from pyiceberg.transforms import DayTransform, IdentityTransform
42+
from pyiceberg.types import IntegerType, LongType, NestedField, TimestampType, UUIDType
4343
from tests.conftest import clean_up
4444

4545

@@ -233,17 +233,20 @@ def test_update_table_transaction(test_catalog: Catalog, test_schema: Schema, ta
233233
table = test_catalog.create_table(identifier, test_schema)
234234
assert test_catalog.table_exists(identifier)
235235

236-
expected_schema: Schema = Schema()
237-
expected_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC
236+
expected_schema = Schema(
237+
NestedField(1, "VendorID", IntegerType(), False),
238+
NestedField(2, "tpep_pickup_datetime", TimestampType(), False),
239+
NestedField(3, "new_col", IntegerType(), False),
240+
)
241+
242+
expected_spec = PartitionSpec(PartitionField(3, 1000, IdentityTransform(), "new_col"))
238243

239244
with table.transaction() as transaction:
240245
with transaction.update_schema() as update_schema:
241246
update_schema.add_column("new_col", IntegerType())
242-
expected_schema = update_schema._apply()
243247

244248
with transaction.update_spec() as update_spec:
245249
update_spec.add_field("new_col", IdentityTransform())
246-
expected_spec = update_spec._apply()
247250

248251
table = test_catalog.load_table(identifier)
249252
assert table.schema().as_struct() == expected_schema.as_struct()
@@ -266,9 +269,10 @@ def test_update_schema_conflict(test_catalog: Catalog, test_schema: Schema, tabl
266269

267270
# Update schema concurrently so that the original update fails
268271
concurrent_update = test_catalog.load_table(identifier).update_schema().delete_column("VendorID")
269-
expected_schema = concurrent_update._apply()
270272
concurrent_update.commit()
271273

274+
expected_schema = Schema(NestedField(2, "tpep_pickup_datetime", TimestampType(), False))
275+
272276
with pytest.raises(CommitFailedException):
273277
original_update.commit()
274278

@@ -322,8 +326,18 @@ def test_create_table_transaction_multiple_schemas(
322326

323327
# TODO: test replace sort order when available
324328

325-
expected_schema = table_transaction.update_schema()._apply()
326-
expected_spec = table_transaction.update_spec()._apply()
329+
expected_schema = Schema(
330+
NestedField(1, "VendorID", IntegerType(), False),
331+
NestedField(2, "tpep_pickup_datetime", TimestampType(), False),
332+
NestedField(3, "new_col", IntegerType(), False),
333+
NestedField(4, "new_col_1", UUIDType(), False),
334+
)
335+
336+
expected_spec = PartitionSpec(
337+
PartitionField(1, 1000, IdentityTransform(), "VendorID"),
338+
PartitionField(2, 1001, DayTransform(), "tpep_pickup_day"),
339+
PartitionField(3, 1002, IdentityTransform(), "new_col"),
340+
)
327341

328342
table_transaction.commit_transaction()
329343
assert test_catalog.table_exists(identifier)

0 commit comments

Comments
 (0)