Skip to content

Commit

Permalink
adopt review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sungwy committed Mar 4, 2024
1 parent f4a302b commit 130b3cc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pyiceberg/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from pyiceberg.io import InputFile, InputStream, OutputFile
from pyiceberg.table.metadata import TableMetadata, TableMetadataUtil
from pyiceberg.typedef import UTF8
from pyiceberg.utils.config import Config

GZIP = "gzip"

Expand Down Expand Up @@ -127,6 +128,9 @@ def table_metadata(metadata: TableMetadata, output_file: OutputFile, overwrite:
overwrite (bool): Where to overwrite the file if it already exists. Defaults to `False`.
"""
with output_file.create(overwrite=overwrite) as output_stream:
json_bytes = metadata.model_dump_json(exclude_none=False).encode(UTF8)
# We need to serialize None values, in order to dump `None` current-snapshot-id as `-1`
exclude_none = False if Config().get_bool("legacy-current-snapshot-id") else True

json_bytes = metadata.model_dump_json(exclude_none=exclude_none).encode(UTF8)
json_bytes = Compressor.get_compressor(output_file.location).bytes_compressor()(json_bytes)
output_stream.write(json_bytes)

0 comments on commit 130b3cc

Please sign in to comment.