[Bug]: [Python] ReadFromJson stores nested JSON objects and arrays as Python repr strings
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 半天
- 新手友好度
- 70/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- pandas, python
调研方向
Start in sdks/python/apache_beam/dataframe/io.py, in ReadViaPandas.expand, where object-dtype columns are cast with astype(pd.StringDtype()). Run the reproducer from the issue to see the nested dict and list values come out as Python repr. Done when nested objects and arrays read from JSON are stored as valid JSON strings, and a regression test in textio_test.JsonTest covers this.
由索引模型根据 Issue 内容生成。
描述
What happened?
beam.io.ReadFromJson (and therefore Beam YAML ReadFromJson) reads nested JSON objects and arrays as strings holding their Python repr instead of JSON. For the line {"id": 1, "user": {"name": "a"}, "tags": ["x", "y"]} the element is id=1, user="{'name': 'a'}", tags="['x', 'y']". The single-quoted repr is not valid JSON, so downstream steps can't recover the nested values, and the schema reports the field as Optional[str].
Minimal reproducer:
import json, os, tempfile
import apache_beam as beam
with tempfile.TemporaryDirectory() as d:
path = os.path.join(d, 'nested.jsonl')
with open(path, 'w') as f:
f.write('{"id": 1, "user": {"name": "a"}, "tags": ["x", "y"]}\n')
with beam.Pipeline() as p:
(p
| beam.io.ReadFromJson(path)
| beam.Map(lambda r: print(repr(r.user), json.loads(r.user))))
# prints "{'name': 'a'}" and then fails with json.decoder.JSONDecodeError
Cause
ReadFromJson delegates to apache_beam.dataframe.io.ReadViaPandas('json', ...). With the default objects_as_strings=True, ReadViaPandas.expand (sdks/python/apache_beam/dataframe/io.py) casts every object-dtype column with df[col].astype(pd.StringDtype()). For JSON input, pandas keeps nested objects and arrays as dict / list values in object-dtype columns, so the cast stores str(dict).
Encoding dict / list values with json.dumps before the cast (JSON format only) keeps the column a string but makes it valid JSON. I have a small fix with a regression test in textio_test.JsonTest and can open a PR.
Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
Issue Components
- Component: Python SDK
- Component: Java SDK
- Component: Go SDK
- Component: Typescript SDK
- Component: IO connector
- Component: Beam YAML
- Component: Beam examples
- Component: Beam playground
- Component: Beam katas
- Component: Website
- Component: Infrastructure
- Component: Spark Runner
- Component: Flink Runner
- Component: Prism Runner
- Component: Hazelcast Jet Runner
- Component: Google Cloud Dataflow Runner
- 主要语言
- Java
- 星标
- 8.7k
- 派生
- 4.8k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 371
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/beam 的其他 Issue
-
awaiting triage bug P3
难度 1/5 1 小时以内 新手友好度 67/100
维护者通常 1 天内回复
-
[Bug]: [Python] WriteToJson silently rounds floats to 10 decimal places可能已有人在做 @Abhi2939 于 1 天前认领。 未关闭io P2 python yaml
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
apache/beam#39624 · 2 个 reaction ·
维护者通常 1 天内回复
-
[Bug]: PubsubIO used in batch incorrect batch cutoff size可能已有人在做 @1fanwang 于 78 天前认领。 未关闭bug io P3 pinned pubsub
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
build P3 sub-task
难度 1/5 1 小时以内 新手友好度 68/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
SasanLabs/VulnerableApp#912 ·
维护者通常 1 天内回复
-
area/build area/events area/storage area/storage/kafkasql area/storage/sql
难度 2/5 1-3 小时 新手友好度 78/100
Apicurio/apicurio-registry#11079 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
OpenAEV-Platform/openaev#9139 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
desktop edt not responding
难度 2/5 1-3 小时 新手友好度 78/100