Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pyiceberg/table/update/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
)
from pyiceberg.partitioning import PartitionSpec
from pyiceberg.schema import Schema
from pyiceberg.table.locations import LocationProvider, load_location_provider
from pyiceberg.table.refs import MAIN_BRANCH, SnapshotRef, SnapshotRefType
from pyiceberg.table.snapshots import (
Operation,
Expand Down Expand Up @@ -344,8 +345,7 @@ def _commit(self) -> UpdatesAndRequirements:
attempt=0,
commit_uuid=self.commit_uuid,
)
location_provider = self._transaction._table.location_provider()
manifest_list_file_path = location_provider.new_metadata_location(file_name)
manifest_list_file_path = self._location_provider().new_metadata_location(file_name)
self._written_manifest_lists.append(manifest_list_file_path)

with write_manifest_list(
Expand Down Expand Up @@ -422,12 +422,16 @@ def new_manifest_writer(self, spec: PartitionSpec) -> ManifestWriter:
)

def new_manifest_output(self) -> OutputFile:
location_provider = self._transaction._table.location_provider()
file_name = _new_manifest_file_name(num=next(self._manifest_num_counter), commit_uuid=self.commit_uuid)
file_path = location_provider.new_metadata_location(file_name)
file_path = self._location_provider().new_metadata_location(file_name)
self._written_manifests.append(file_path)
return self._io.new_output(file_path)

def _location_provider(self) -> LocationProvider:
# Use the metadata of the transaction, as for data files, in case it changed the location or properties
table_metadata = self._transaction.table_metadata
return load_location_provider(table_location=table_metadata.location, table_properties=table_metadata.properties)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Note that self._transaction._table.location_provider() which we had previously in new_manifest_output calls load_location_provider, so this isn't a new load per-manifest)


def fetch_manifest_entry(self, manifest: ManifestFile, discard_deleted: bool = True) -> list[ManifestEntry]:
return manifest.fetch_manifest_entry(io=self._io, discard_deleted=discard_deleted)

Expand Down
26 changes: 26 additions & 0 deletions tests/catalog/test_catalog_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,32 @@ def test_union_by_name_case_insensitive_duplicates(catalog: Catalog) -> None:
assert catalog.load_table("default.nested_variants").schema() == nested_schema


def test_transaction_writes_manifests_to_staged_metadata_path(
catalog: Catalog,
test_table_identifier: Identifier,
table_schema_simple: Schema,
warehouse: Path,
) -> None:
namespace = Catalog.namespace_from(test_table_identifier)
catalog.create_namespace(namespace)
table = catalog.create_table(identifier=test_table_identifier, schema=table_schema_simple)
metadata_path = f"file://{warehouse}/custom/path"
df = pa.Table.from_pydict(
{"foo": ["a"], "bar": [1], "baz": [True]},
schema=schema_to_pyarrow(table_schema_simple),
)

with table.transaction() as txn:
txn.set_properties({TableProperties.WRITE_METADATA_PATH: metadata_path})
txn.append(df)

snapshot = table.current_snapshot()
assert snapshot is not None
assert snapshot.manifest_list.startswith(metadata_path)
assert all(manifest.manifest_path.startswith(metadata_path) for manifest in snapshot.manifests(table.io))
assert table.metadata_location.startswith(metadata_path)


@pytest.mark.parametrize("format_version", [1, 2])
def test_write_and_evolve(catalog: Catalog, format_version: int) -> None:
identifier = f"default.arrow_write_data_and_evolve_schema_v{format_version}"
Expand Down