Skip to content

Commit fc8dc71

Browse files
committed
Fix iceberg lockfile update test failures
1 parent 187db86 commit fc8dc71

6 files changed

Lines changed: 37 additions & 43 deletions

File tree

libraries/dagster-iceberg/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ dev = [
152152
"dagit>=1.8.8",
153153
"dagster>=1.10.5",
154154
"dagster-polars[patito]>=0.26.1",
155+
# dagster-polars releases before the universal-pathlib 0.3 compatibility fix
156+
# still read UPath._kwargs via Dagster's UPathIOManager in the kitchen-sink tests.
157+
"universal-pathlib<0.3",
155158
"dagster-pyspark>=0.26.1",
156159
"docker",
157160
"fsspec[http]>=2025.2.0",

libraries/dagster-iceberg/src/dagster_iceberg/_utils/io.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ def table_writer(
118118
)
119119
partition_dimensions = table_slice.partition_dimensions
120120
logger.debug("Partition dimensions: %s", partition_dimensions)
121+
if partition_dimensions is not None:
122+
for partition_dimension in partition_dimensions:
123+
if partition_dimension.partition_expr not in data.schema.names:
124+
raise ValueError(
125+
f"Could not find field '{partition_dimension.partition_expr}' "
126+
"in data schema. Partition columns must be present in the data."
127+
)
128+
121129
if table_exists(catalog, table_path):
122130
logger.debug("Updating existing table")
123131
table = catalog.load_table(table_path)

libraries/dagster-iceberg/tests/_utils/test_io.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import datetime as dt
2-
import pathlib as plb
32
from uuid import uuid4
43

54
import pyarrow as pa
@@ -285,7 +284,6 @@ def test_table_writer_multi_partitioned_update(
285284

286285
def test_table_writer_multi_partitioned_update_partition_spec_change(
287286
namespace: str,
288-
warehouse_path: str,
289287
catalog: Catalog,
290288
data: pa.Table,
291289
):
@@ -334,23 +332,13 @@ def test_table_writer_multi_partitioned_update_partition_spec_change(
334332
partition_spec_update_mode="update",
335333
dagster_run_id="hfkghdgsh467374828",
336334
)
337-
path_to_dwh = (
338-
plb.Path(warehouse_path)
339-
/ f"{namespace}.db"
340-
/ table_
341-
/ "data"
342-
/ "part_timestamp=2023-01-01-00"
343-
)
344-
categories = sorted([p.name for p in path_to_dwh.glob("*") if p.is_dir()])
345-
assert categories == [
346-
"part_category=A",
347-
"part_category=B",
348-
"part_category=C",
335+
table = catalog.load_table(identifier_)
336+
assert [field.name for field in table.spec().fields] == [
337+
"part_timestamp",
338+
"part_category",
349339
]
350-
assert (
351-
len(catalog.load_table(identifier_).scan().to_arrow().to_pydict()["value"])
352-
== 1440
353-
)
340+
assert set(table.scan().to_arrow().to_pydict()["category"]) == {"A", "B", "C"}
341+
assert len(table.scan().to_arrow().to_pydict()["value"]) == 1440
354342

355343

356344
def test_table_writer_multi_partitioned_update_partition_spec_error(

libraries/dagster-iceberg/tests/_utils/test_partitions.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,26 +672,29 @@ def test_existing_table_partition_names_unchanged(
672672
schema=iceberg_table_schema,
673673
)
674674

675-
# Manually add a partition field with old-style naming (same as column name)
675+
# Manually add an identity partition field with old-style naming (same as column name).
676+
# PyIceberg no longer allows transformed partition field names to conflict with
677+
# schema column names, but identity partitions using the source column name are still
678+
# valid legacy specs.
676679
with table.update_spec() as update:
677680
update.add_field(
678-
source_column_name="timestamp",
679-
transform=transforms.HourTransform(),
680-
partition_field_name="timestamp", # Old style: same as column name
681+
source_column_name="category",
682+
transform=transforms.IdentityTransform(),
683+
partition_field_name="category", # Old style: same as column name
681684
)
682685

683686
table.refresh()
684687
original_field_name = table.spec().fields[0].name
685-
assert original_field_name == "timestamp"
688+
assert original_field_name == "category"
686689

687690
# Now run update with no actual changes (same partition dimensions)
688691
table_slice = TableSlice(
689692
table=table_name,
690693
schema=namespace,
691694
partition_dimensions=[
692695
TablePartitionDimension(
693-
"timestamp",
694-
TimeWindow(dt.datetime(2023, 1, 1), dt.datetime(2023, 1, 1, 1)),
696+
"category",
697+
["A"],
695698
),
696699
],
697700
)
@@ -709,7 +712,7 @@ def test_existing_table_partition_names_unchanged(
709712
assert len(table.spec().fields) == 1
710713
assert (
711714
table.spec().fields[0].name == original_field_name
712-
) # Should still be "timestamp"
715+
) # Should still be "category"
713716

714717

715718
def test_partition_field_naming_avoids_column_conflicts(

libraries/dagster-iceberg/tests/test_resource.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ def test_resource(
6363
@asset
6464
def read_table(pyiceberg_table: IcebergTableResource):
6565
table_ = pyiceberg_table.load().scan().to_arrow()
66-
assert (
67-
table_.schema.to_string()
68-
== "timestamp: timestamp[us]\ncategory: large_string\nvalue: double"
69-
)
66+
assert table_.schema.names == ["timestamp", "category", "value"]
67+
assert str(table_.schema.field("timestamp").type) == "timestamp[us]"
68+
assert str(table_.schema.field("category").type) in {"string", "large_string"}
69+
assert str(table_.schema.field("value").type) == "double"
7070
assert table_.shape == (1440, 3)
7171

7272
materialize(

libraries/dagster-iceberg/uv.lock

Lines changed: 5 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)