[Bug]: [Python] ReadFromAvro(as_rows=True) fails on Avro logical types (timestamp, date, decimal, uuid)
维护者通常 2 天内回复
评估
这个 Issue 还没有评估数据。
描述
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).
- 主要语言
- Java
- 星标
- 8.7k
- 派生
- 4.8k
- 平均合并
- 3 天 16 小时
- 30 天内合并 PR
- 445
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/beam 的其他 Issue
-
awaiting triage java new feature P2
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
[Bug]: [Python] BigTableEnrichmentHandler coerces None lookup keys to literal b'None' and formats blank key name on KeyError可能已有人在做 @shikhabhadoria 于 6 天前认领。 未关闭io P2 python
难度 2/5 1-3 小时 新手友好度 82/100
apache/beam#41346 · 4 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
Release notes links wrong可能已有人在做 @schizophrenicmaniac 于 20 天前认领。 未关闭bug P3
难度 1/5 1 小时以内 新手友好度 67/100
apache/beam#41197 · 3 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
apache/beam#39624 · 2 个 reaction ·
维护者通常 2 天内回复
-
[Bug]: PubsubIO used in batch incorrect batch cutoff size可能已有人在做 @1fanwang 于 98 天前认领。 未关闭bug io P3 pinned pubsub
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
相似的 Issue
-
`ovsx verify` fails for a version older than the 100 newest of an extension可能已有人在做 @trivikr 今天认领。 未关闭cli
难度 2/5 1-3 小时 新手友好度 81/100
eclipse-openvsx/openvsx#2482 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
Magic-team-jvav/confluence#281 ·
-
area/dependencies area/dependencies/js backport/26.6 backport/26.8 kind/cve severity/medium source/scan-dependencies status/triage
难度 1/5 1 小时以内 新手友好度 67/100
维护者通常 2 天内回复
-
[DEFECT] AsciiDoc builders write a stray ## before every schema member when the namespace prefixes file binds the schema's own namespace可能已有人在做 @Beehtrix 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
cimug-org/CIMTool#427 · 1 条评论 ·
维护者通常 1 天内回复
-
userRaised
难度 2/5 1-3 小时 新手友好度 76/100
eclipse-openj9/openj9#25285 ·
维护者通常 1 天内回复