Fokko commented on code in PR #4398:
URL: https://github.com/apache/iceberg-python/pull/4398#discussion_r4600090198


##########
pyiceberg/table/locations.py:
##########
@@ -80,12 +80,19 @@ def new_table_metadata_file_location(self, new_version: int 
= 0) -> str:
             str: fully-qualified URI for the new table metadata file.
 
         Raises:
-            ValueError: If the version is negative.
+            ValueError: If the version is negative, or the metadata 
compression codec is not supported.
         """
+        from pyiceberg.table import TableProperties
+
         if new_version < 0:
             raise ValueError(f"Table metadata version: `{new_version}` must be 
a non-negative integer")
 
-        file_name = f"{new_version:05d}-{uuid.uuid4()}.metadata.json"
+        codec = 
self.table_properties.get(TableProperties.METADATA_COMPRESSION, 
TableProperties.METADATA_COMPRESSION_DEFAULT)
+        extension = {"none": "", "gzip": ".gz"}.get(codec.lower())

Review Comment:
   **nit (non-blocking):** This mapping is the write-side counterpart of 
`Compressor.get_compressor` in `serializers.py`, which picks gzip from the 
`.gz.metadata.json` suffix. Should it live there, next to the existing `GZIP = 
"gzip"` constant? Then the codec names and the `.gz` suffix are defined once, 
and anyone who adds a codec later finds both directions in one place. Something 
like:
   
   ```python
   # serializers.py
   GZIP = "gzip"
   NONE = "none"
   
   METADATA_FILE_EXTENSIONS = {NONE: "", GZIP: ".gz"}
   ```
   
   ```python
   # locations.py
   from pyiceberg.serializers import METADATA_FILE_EXTENSIONS
   
   extension = METADATA_FILE_EXTENSIONS.get(codec.lower())
   if extension is None:
       raise ValueError(
           f"Invalid {TableProperties.METADATA_COMPRESSION}: {codec}, expected 
one of {', '.join(METADATA_FILE_EXTENSIONS)}"
       )
   ```
   
   This also builds the error message from the mapping instead of hard-coding 
"none or gzip".
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to