Skip to content

Commit 1a04772

Browse files
authored
fix: Pass metadata location to StaticTable FileIO (#3592)
<!-- Thanks for opening a pull request! --> <!-- In the case this PR will resolve an issue, please replace ${GITHUB_ISSUE_ID} below with the actual Github issue id. --> <!-- Closes #${3591} --> # Rationale for this change See issue #3591 - bug fix. FileIO selection fails on StaticTable because the location is missing. ## Are these changes tested? Yes `make test` passes. Added a basic regression test. ## Are there any user-facing changes? No. <!-- In the case of user-facing changes, please add the changelog label. -->
1 parent 4223f4c commit 1a04772

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

pyiceberg/table/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ def from_metadata(cls, metadata_location: str, properties: Properties = EMPTY_DI
18201820
identifier=("static-table", metadata_location),
18211821
metadata_location=metadata_location,
18221822
metadata=metadata,
1823-
io=load_file_io({**properties, **metadata.properties}),
1823+
io=load_file_io({**properties, **metadata.properties}, location=metadata_location),
18241824
catalog=NoopCatalog("static-table"),
18251825
)
18261826

tests/table/test_init.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
In,
3434
)
3535
from pyiceberg.expressions.visitors import bind
36-
from pyiceberg.io import PY_IO_IMPL, load_file_io
36+
from pyiceberg.io import PY_IO_IMPL, FileIO, load_file_io
3737
from pyiceberg.partitioning import PartitionField, PartitionSpec
3838
from pyiceberg.schema import Schema
3939
from pyiceberg.table import (
@@ -1989,3 +1989,24 @@ def test_build_large_partition_predicate(table_v2: Table) -> None:
19891989
)
19901990

19911991
bind(table_v2.metadata.schema(), expr, case_sensitive=True)
1992+
1993+
1994+
def test_static_table_forwards_location_to_table_file_io(metadata_location: str, monkeypatch: pytest.MonkeyPatch) -> None:
1995+
seen_locations: list[str | None] = []
1996+
real_load_file_io = load_file_io
1997+
1998+
def _spy(*args: Any, **kwargs: Any) -> FileIO:
1999+
if "location" in kwargs:
2000+
seen_locations.append(kwargs["location"])
2001+
elif len(args) >= 2:
2002+
seen_locations.append(args[1])
2003+
else:
2004+
seen_locations.append(None)
2005+
return real_load_file_io(*args, **kwargs)
2006+
2007+
monkeypatch.setattr("pyiceberg.table.load_file_io", _spy)
2008+
2009+
StaticTable.from_metadata(metadata_location)
2010+
2011+
assert seen_locations, "expected at least one load_file_io call"
2012+
assert all(loc is not None for loc in seen_locations), f"load_file_io called without a location: {seen_locations}"

0 commit comments

Comments
 (0)