[Bug]: [Python] ReadFromAvro(as_rows=True) fails on Avro logical types (timestamp, date, decimal, uuid)

Đang mở
#41,700 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@Viranshul-P đang làm issue này rồi.

Từ ngày 26/11/2026.

  • #41701 của @Viranshul-P — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

io P2 python
What happened?

ReadFromAvro(..., as_rows=True) fails on any Avro field that has a logical type. BigQuery Avro exports hit this: every TIMESTAMP column is written as {"type": "long", "logicalType": "timestamp-micros"}.

This was reported in #31656 (timestamp-millis), which the stale bot closed. It still fails on master (38eed1e5da0) and 2.78.0, and it affects every logical type, not only timestamps:

Avro logical type Error with as_rows=True
timestamp-millis, timestamp-micros, date, time-millis, local-timestamp-millis TypeError: an integer is required
uuid AttributeError: 'UUID' object has no attribute 'encode'
decimal TypeError: Expected bytes, got decimal.Decimal

Reading the same file without as_rows works. Beam YAML's ReadFromAvro sets as_rows: True by default (standard_io.yaml), so a YAML pipeline can't read any Avro file with such a column.

Cause: avro_type_to_beam_type ignores logicalType and maps the field to its primitive (INT64, INT32, BYTES, STRING), but fastavro decodes logical types to Python objects (datetime, date, Decimal, UUID), so the RowCoder gets a value that doesn't match the schema.

Repro:

import datetime, tempfile, os, fastavro
import apache_beam as beam

schema = {"type": "record", "name": "T", "fields": [
    {"name": "ts", "type": {"type": "long", "logicalType": "timestamp-micros"}}]}
path = os.path.join(tempfile.mkdtemp(), "t.avro")
with open(path, "wb") as f:
  fastavro.writer(f, fastavro.parse_schema(schema),
                  [{"ts": datetime.datetime.now(datetime.timezone.utc)}])

with beam.Pipeline() as p:
  p | beam.io.ReadFromAvro(path, as_rows=True) | beam.Map(print)
# TypeError: an integer is required [while running 'ReadFromAvro/Map(<lambda at avroio.py:676>)']

Proposed fix (I have it ready with a test): map logical types to the Beam types the Java SDK's AvroUtils uses, through the existing Python logical types: timestamp-millis/micros → Timestamp (micros_instant), date → datetime.date, decimal → decimal.Decimal, uuid → str. Logical types with no Beam equivalent in Python (time-, local-timestamp-) fall back to Any, as unions already do in this file.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components
  • Component: Python SDK
  • Component: IO connector

Found, reproduced and drafted with Claude Code (Claude Opus 5.5).

Ngôn ngữ chính
Java
Star
8.7k
Fork
4.8k
Merge trung bình
3 ngày 16 giờ
Pull request đã merge (30 ngày)
445

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/beam

Tất cả issue của apache/beam

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.