[Bug]: [Python] ReadFromJson stores nested JSON objects and arrays as Python repr strings
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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時間
- マージ済み PR(30日)
- 371
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/beam のほかの issue
-
awaiting triage bug P3
難易度 1/5 1時間未満 初心者へのやさしさ 67/100
apache/beam#41197 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: [Python] WriteToJson silently rounds floats to 10 decimal places対応中かも @Abhi2939 が 1 日前に担当しました。 オープンio P2 python yaml
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
apache/beam#41102 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
apache/beam#39624 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: PubsubIO used in batch incorrect batch cutoff size対応中かも @1fanwang が 78 日前に担当しました。 オープンbug io P3 pinned pubsub
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/beam#28011 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
build P3 sub-task
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
SasanLabs/VulnerableApp#912 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
desktop edt not responding
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
datafusion-contrib/StreamFusion#653 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] Absolute row/column index 0 is ignored for images, hyperlinks and comments対応中かも @fanOfSunny が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信