sungwy commented on code in PR #3491: URL: https://github.com/apache/iceberg-python/pull/3491#discussion_r3454347608
########## pyiceberg/table/deletion_vector.py: ########## @@ -0,0 +1,79 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import math +from typing import TYPE_CHECKING + +from pyroaring import BitMap, FrozenBitMap + +from pyiceberg.table.puffin import PuffinFile + +if TYPE_CHECKING: + import pyarrow as pa + +EMPTY_BITMAP = FrozenBitMap() +MAX_JAVA_SIGNED = int(math.pow(2, 31)) - 1 +PROPERTY_REFERENCED_DATA_FILE = "referenced-data-file" + + +class DeletionVector: + _deletion_vectors: dict[str, list[BitMap]] + + def __init__(self, puffin: bytes) -> None: + puffin_file = PuffinFile(puffin) + self._deletion_vectors = { + blob.properties[PROPERTY_REFERENCED_DATA_FILE]: self._deserialize_bitmap(puffin_file.get_blob_payload(blob)) + for blob in puffin_file.footer.blobs + } Review Comment: It looks like we are always expecting a `PuffinFile` to be the container format for a DV. Are we keeping the input parameter as `bytes` instead of using a puffin file directly to allow it to remain container format (Puffin vs some other future format) agnostic? I'm wondering if splitting out the container specific construction to a separate factory method may make more sense: ```suggestion def __init__(self, deletion_vectors: dict[str, list[BitMap]]) -> None: self._deletion_vectors = deletion_vectors @classmethod def from_puffin_file(cls, puffin_file: PuffinFile) -> "DeletionVector": return cls({ blob.properties[PROPERTY_REFERENCED_DATA_FILE]: cls._deserialize_bitmap(puffin_file.get_blob_payload(blob)) for blob in puffin_file.footer.blobs }) ``` ########## pyiceberg/table/puffin.py: ########## @@ -105,12 +64,7 @@ def __init__(self, puffin: bytes) -> None: footer_payload_size_int = int.from_bytes(puffin[-12:-8], byteorder="little") self.footer = Footer.model_validate_json(puffin[-(footer_payload_size_int + 12) : -12]) - puffin = puffin[8:] - - self._deletion_vectors = { - blob.properties[PROPERTY_REFERENCED_DATA_FILE]: _deserialize_bitmap(puffin[blob.offset : blob.offset + blob.length]) - for blob in self.footer.blobs - } + self._payload = puffin[8:] - def to_vector(self) -> dict[str, "pa.ChunkedArray"]: - return {path: _bitmaps_to_chunked_array(bitmaps) for path, bitmaps in self._deletion_vectors.items()} Review Comment: This is a public method, so we'll need to deprecate this. What do you think about having this method call the new `DeletionVector` class's `to_vector()` method instead over the deprecation period? ``` @deprecated(deprecated_in="0.12.0", removed_in="0.13.0", help_message="Use DeletionVector.from_bytes(...).to_vector() instead") def to_vector(self) -> dict[str, "pa.ChunkedArray"]: from pyiceberg.table.deletion_vector import DeletionVector # local import avoids the cycle return DeletionVector.from_puffin_file(self).to_vector() ``` -- 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]
