[Bug]: [Python] Type inference returns Any for attributes of NamedTuple-typed and nullable nested rows
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
Start in sdks/python/apache_beam/typehints/opcodes.py, where _getattr only resolves fields when the type is a RowTypeConstraint. Reproduce with trivial_inference.infer_return_type on the Person/Address NamedTuples from the issue, then extend _getattr to accept NamedTuple classes via RowTypeConstraint.from_user_type and unwrap Optional[row] while keeping the result nullable. Done when both lambdas infer str and Optional[str] in trivial_inference_test.
索引モデルが issue の本文から書いたものです。
説明
What happened?
Accessing a nested field of a schema-aware PCollection is inferred as Any. In Beam YAML this makes a common pipeline fail at construction: a MapToFields that projects a field of a Parquet struct column feeds WriteToParquet, which raises NotImplementedError: Beam logical types are not currently supported in arrow_type_compatibility (#23817) because the inferred field type is Any.
Reproducer (Parquet file with name: string, address: struct<city: string, zip: int64>):
pipeline:
type: chain
transforms:
- type: ReadFromParquet
config:
path: people_struct.parquet
- type: MapToFields
config:
language: python
fields:
name: name
city: address.city
- type: WriteToParquet
config:
path: out/people
ValueError: Error applying transform "WriteToParquet" at line 13: Beam logical types are not currently supported in arrow_type_compatibility.
The same happens with trivial_inference directly:
import typing
from apache_beam.typehints import trivial_inference
class Address(typing.NamedTuple):
city: str
class Person(typing.NamedTuple):
name: str
address: typing.Optional[Address]
trivial_inference.infer_return_type(lambda r: r.name, [Person]) # Any (expected str)
trivial_inference.infer_return_type(lambda r: r.address.city, [Person]) # Any (expected Optional[str])
Cause
opcodes._getattr (sdks/python/apache_beam/typehints/opcodes.py) resolves row.field only when the type is a RowTypeConstraint. Schema-aware PCollections are usually typed with the NamedTuple class generated for their schema (for example ReadFromParquet(as_rows=True) produces a BeamSchema_... class), and nested struct fields are Optional[Row] / Optional[NamedTuple], so both cases fall through to Any.
Resolving NamedTuple classes through RowTypeConstraint.from_user_type and unwrapping Optional[row] (keeping the result nullable) fixes inference. I have a small fix with tests in trivial_inference_test and can open a PR.
Note: with that fix the Parquet pipeline above builds, but then fails at runtime due to a separate issue where ReadFromParquet(as_rows=True) yields dicts for struct fields (filed separately).
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 が 2 日前に担当しました。 オープン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 が 79 日前に担当しました。 オープン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時間 初心者へのやさしさ 72/100
spAnser/reacharound#38 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 89/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
MovingBlocks/Terasology#5415 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100