|
42 | 42 | TableAlreadyExistsError, |
43 | 43 | ) |
44 | 44 | from pyiceberg.io import WAREHOUSE, load_file_io |
| 45 | +from pyiceberg.io.pyarrow import schema_to_pyarrow |
45 | 46 | from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionField, PartitionSpec |
46 | 47 | from pyiceberg.schema import Schema |
47 | 48 | from pyiceberg.table import ( |
@@ -105,7 +106,7 @@ def create_table( |
105 | 106 | location = f"{self._warehouse_location}/{'/'.join(identifier)}" |
106 | 107 | location = location.rstrip("/") |
107 | 108 |
|
108 | | - metadata_location = self._get_metadata_location(location=location) |
| 109 | + metadata_location = self._get_metadata_location(table_location=location, properties=properties) |
109 | 110 | metadata = new_table_metadata( |
110 | 111 | schema=schema, |
111 | 112 | partition_spec=partition_spec, |
@@ -147,7 +148,9 @@ def commit_table( |
147 | 148 |
|
148 | 149 | # write new metadata |
149 | 150 | new_metadata_version = self._parse_metadata_version(current_table.metadata_location) + 1 |
150 | | - new_metadata_location = self._get_metadata_location(current_table.metadata.location, new_metadata_version) |
| 151 | + new_metadata_location = self._get_metadata_location( |
| 152 | + current_table.metadata.location, new_metadata_version, updated_metadata.properties |
| 153 | + ) |
151 | 154 | self._write_metadata(updated_metadata, current_table.io, new_metadata_location) |
152 | 155 |
|
153 | 156 | # update table state |
@@ -769,3 +772,35 @@ def test_table_properties_raise_for_none_value(catalog: InMemoryCatalog) -> None |
769 | 772 | with pytest.raises(ValidationError) as exc_info: |
770 | 773 | _ = given_catalog_has_a_table(catalog, properties=property_with_none) |
771 | 774 | assert "None type is not a supported value in properties: property_name" in str(exc_info.value) |
| 775 | + |
| 776 | + |
| 777 | +def test_table_writes_metadata_to_custom_location(catalog: InMemoryCatalog) -> None: |
| 778 | + new_location = f"{catalog._warehouse_location}/custom/path" |
| 779 | + table = catalog.create_table( |
| 780 | + identifier=TEST_TABLE_IDENTIFIER, |
| 781 | + schema=TEST_TABLE_SCHEMA, |
| 782 | + partition_spec=TEST_TABLE_PARTITION_SPEC, |
| 783 | + properties={"write.metadata.path": new_location}, |
| 784 | + ) |
| 785 | + df = pa.Table.from_pylist([{"x": 123, "y": 456, "z": 789}], schema=schema_to_pyarrow(TEST_TABLE_SCHEMA)) |
| 786 | + table.append(df) |
| 787 | + manifests = table.current_snapshot().manifests(table.io) # type: ignore |
| 788 | + |
| 789 | + assert manifests[0].manifest_path.startswith(new_location) |
| 790 | + assert table.location() != new_location |
| 791 | + assert table.metadata_location.startswith(new_location) |
| 792 | + |
| 793 | + |
| 794 | +def test_table_writes_metadata_to_default_path(catalog: InMemoryCatalog) -> None: |
| 795 | + table = catalog.create_table( |
| 796 | + identifier=TEST_TABLE_IDENTIFIER, |
| 797 | + schema=TEST_TABLE_SCHEMA, |
| 798 | + partition_spec=TEST_TABLE_PARTITION_SPEC, |
| 799 | + properties=TEST_TABLE_PROPERTIES, |
| 800 | + ) |
| 801 | + df = pa.Table.from_pylist([{"x": 123, "y": 456, "z": 789}], schema=schema_to_pyarrow(TEST_TABLE_SCHEMA)) |
| 802 | + table.append(df) |
| 803 | + manifests = table.current_snapshot().manifests(table.io) # type: ignore |
| 804 | + |
| 805 | + assert "/metadata" in manifests[0].manifest_path |
| 806 | + assert "/metadata" in table.metadata_location |
0 commit comments