moomindani commented on code in PR #3474:
URL: https://github.com/apache/iceberg-python/pull/3474#discussion_r3386792795
##########
pyiceberg/table/puffin.py:
##########
@@ -114,3 +147,105 @@ def __init__(self, puffin: bytes) -> None:
def to_vector(self) -> dict[str, "pa.ChunkedArray"]:
return {path: _bitmaps_to_chunked_array(bitmaps) for path, bitmaps in
self._deletion_vectors.items()}
+
+
+class PuffinWriter:
+ _blobs: list[PuffinBlobMetadata]
+ _blob_payloads: list[bytes]
+ _created_by: str | None
+
+ def __init__(self, created_by: str | None = None) -> None:
+ self._blobs = []
+ self._blob_payloads = []
+ self._created_by = created_by
+
+ def set_blob(
+ self,
+ positions: Iterable[int],
+ referenced_data_file: str,
+ ) -> None:
+ # We only support one blob at the moment
+ self._blobs = []
+ self._blob_payloads = []
+
+ # 1. Create bitmaps from positions
Review Comment:
Removed the numbered prefixes in 4ecfd186.
##########
pyiceberg/table/puffin.py:
##########
@@ -114,3 +147,105 @@ def __init__(self, puffin: bytes) -> None:
def to_vector(self) -> dict[str, "pa.ChunkedArray"]:
return {path: _bitmaps_to_chunked_array(bitmaps) for path, bitmaps in
self._deletion_vectors.items()}
+
+
+class PuffinWriter:
+ _blobs: list[PuffinBlobMetadata]
+ _blob_payloads: list[bytes]
+ _created_by: str | None
+
+ def __init__(self, created_by: str | None = None) -> None:
+ self._blobs = []
+ self._blob_payloads = []
+ self._created_by = created_by
+
+ def set_blob(
+ self,
+ positions: Iterable[int],
+ referenced_data_file: str,
+ ) -> None:
+ # We only support one blob at the moment
+ self._blobs = []
+ self._blob_payloads = []
+
+ # 1. Create bitmaps from positions
+ bitmaps: dict[int, BitMap] = {}
+ for pos in positions:
+ key = pos >> 32
+ low_bits = pos & 0xFFFFFFFF
+ if key not in bitmaps:
+ bitmaps[key] = BitMap()
+ bitmaps[key].add(low_bits)
+
+ # Calculate the cardinality from the bitmaps
+ cardinality = sum(len(bm) for bm in bitmaps.values())
Review Comment:
Removed in 4ecfd186.
##########
tests/integration/test_puffin_spark_interop.py:
##########
@@ -0,0 +1,93 @@
+# 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 pytest
+from pyspark.sql import SparkSession
+
+from pyiceberg.catalog.rest import RestCatalog
+from pyiceberg.manifest import ManifestContent
+from pyiceberg.table.puffin import PuffinFile
+
+
+def run_spark_commands(spark: SparkSession, sqls: list[str]) -> None:
+ for sql in sqls:
+ spark.sql(sql)
+
+
[email protected]
+def test_read_spark_written_puffin_dv(spark: SparkSession, session_catalog:
RestCatalog) -> None:
+ """Verify pyiceberg can read Puffin DVs written by Spark."""
+ identifier = "default.spark_puffin_format_test"
Review Comment:
Exactly right, this PR is preparatory. PyIceberg does not yet have a write
path that commits DVs as delete files, so a Spark-reads-PyIceberg interop test
is not possible in isolation. As follow-ups, I plan to (1) extend PuffinWriter
to support one blob per referenced data file and expose per-blob offset/length
for `content_offset`/`content_size_in_bytes`, and (2) wire it into the
merge-on-read branch of `Transaction.delete()` for v3 tables (toward #1078),
where the Spark-reads-PyIceberg interop test will live.
##########
pyiceberg/table/puffin.py:
##########
@@ -114,3 +147,105 @@ def __init__(self, puffin: bytes) -> None:
def to_vector(self) -> dict[str, "pa.ChunkedArray"]:
return {path: _bitmaps_to_chunked_array(bitmaps) for path, bitmaps in
self._deletion_vectors.items()}
+
+
+class PuffinWriter:
+ _blobs: list[PuffinBlobMetadata]
+ _blob_payloads: list[bytes]
+ _created_by: str | None
Review Comment:
Good idea. Done in 4ecfd186, the default is now `PyIceberg version
{importlib.metadata.version("pyiceberg")}`.
##########
tests/integration/test_puffin_spark_interop.py:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
Extracted to #3476 and removed from this PR in 4ecfd186.
--
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]