Avro EnumReader.skip() does not advance the decoder
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 92/100
Hướng nghiên cứu
Bắt đầu tại pyiceberg/avro/resolver.py, ở EnumReader.skip(), và theo dõi đường dẫn projection của Avro đối với các trường enum bị bỏ qua. Tái hiện việc đọc manifest với status bị loại khỏi projection, sau đó xác minh rằng snapshot_id tiếp theo được giải mã chính xác thay vì được giải mã như giá trị enum. Hoàn thành khi decoder tiến qua trường enum bị bỏ qua.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Apache Iceberg version
main (development)
Please describe the bug 🐞
Description
EnumReader.skip() in pyiceberg/avro/resolver.py currently does nothing:
def skip(self, decoder: BinaryDecoder) -> None:
pass
When an enum field is omitted from the requested read schema, the Avro reader calls skip() for that field. Because the decoder is not advanced, the next field is read from the enum field's bytes.
This causes incorrect values when reading selected Avro records, including Iceberg manifest files.
Reproduction
Create an Iceberg table, append one row, and read its manifest with the status enum field projected out:
from tempfile import TemporaryDirectory
import pyarrow as pa
from pyiceberg.avro.file import AvroFile
from pyiceberg.catalog.memory import InMemoryCatalog
from pyiceberg.manifest import MANIFEST_ENTRY_SCHEMAS, ManifestEntryStatus
from pyiceberg.schema import Schema
from pyiceberg.types import IntegerType, NestedField
with TemporaryDirectory() as warehouse:
# Use a temporary local warehouse so the example does not modify external data.
catalog = InMemoryCatalog("bug-simulation", warehouse=warehouse)
catalog.create_namespace("demo")
# Create a simple Iceberg table with two required integer columns.
table = catalog.create_table(
"demo.events",
schema=Schema(
NestedField(1, "id", IntegerType(), required=True),
NestedField(2, "value", IntegerType(), required=True),
),
)
# Build a PyArrow table whose types and nullability match the Iceberg schema.
data = pa.Table.from_pylist(
[{"id": 1, "value": 123}],
schema=pa.schema(
[
pa.field("id", pa.int32(), nullable=False),
pa.field("value", pa.int32(), nullable=False),
]
),
)
# Write the data file and commit a snapshot containing a manifest.
table.append(data)
# Find the manifest generated by the append operation.
snapshot = table.current_snapshot()
manifest = snapshot.manifests(table.io)[0]
# The manifest schema starts with field ID 0, the status enum.
file_schema = MANIFEST_ENTRY_SCHEMAS[2]
# Build a projected schema that omits status but keeps the later fields.
# This makes the Avro reader skip status before reading snapshot_id.
projected_fields = []
for field in file_schema.fields:
if field.field_id != 0:
projected_fields.append(field)
projected_schema = Schema(*projected_fields)
with AvroFile(
table.io.new_input(manifest.manifest_path),
read_schema=projected_schema,
# Tell the resolver that field ID 0 should be converted to an enum.
# The field is projected out, so EnumReader.skip() handles it.
read_enums={0: ManifestEntryStatus},
) as reader:
entries = list(reader)
# Because status was projected out, the first returned field is snapshot_id.
decoded_snapshot_id = entries[0][0]
# the decoder is still positioned at status and returns 1.
if decoded_snapshot_id != snapshot.snapshot_id:
raise RuntimeError(
f"Expected snapshot_id {snapshot.snapshot_id}, "
f"got {decoded_snapshot_id}"
)
Actual behavior
The decoded snapshot_id is incorrectly read as 1.
1 is the encoded manifest status value. This shows that the decoder did not skip the enum value before reading snapshot_id.
Expected behavior
The decoder should skip the enum value and decode the following snapshot_id correctly.
Proposed fix
Delegate skipping to the wrapped reader:
def skip(self, decoder: BinaryDecoder) -> None:
self.reader.skip(decoder)
Willingness to contribute
- I can contribute a fix for this bug independently
- I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- I cannot contribute a fix for this bug at this time
- Ngôn ngữ chính
- Python
- Star
- 1.1k
- Fork
- 589
- Merge trung bình
- 2 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 70
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/iceberg-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/iceberg-python#3996 ·
-
Deletion vector bitmap count is read from the blob and used as a loop bound without validation Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/iceberg-python#3979 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/iceberg-python#3885 ·
-
[Bug] PyArrowFileIO fails to propagate s3.ssl.ca-cert to pyarrow.fs.S3FileSystem tls_ca_file_path Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
apache/iceberg-python#3866 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/iceberg-python#3836 · 1 bình luận ·
Tất cả issue của apache/iceberg-python
Issue tương tự
-
essnmx good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
[Feature] 奇物选择添加优先级 Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
syfoud/Simulated_Scepter#174 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Giskard-AI/giskard-oss#2840 · 1 bình luận ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Đang mởarea: repo bug perceived difficulty: 2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
yeti-platform/yeti#1380 ·