[Bug]: [Python] Type inference returns Any for attributes of NamedTuple-typed and nullable nested rows
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- data-engineering
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Java
- Estrellas
- 8.7k
- Forks
- 4.8k
- Merge medio
- 2 d 12 h
- PR fusionados (30 d)
- 371
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/beam
-
Release notes links wrongAbiertoawaiting triage bug P3
Dificultad 1/5 Menos de una hora Aptitud para principiantes 67/100
apache/beam#41197 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Bug]: [Python] WriteToJson silently rounds floats to 10 decimal placesPosiblemente ocupada @Abhi2939 la tomó hace 2 días. Abiertoio P2 python yaml
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
apache/beam#41102 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
apache/beam#39624 · 2 reacciones ·
Los mantenedores suelen responder en 1 día
-
[Bug]: PubsubIO used in batch incorrect batch cutoff sizePosiblemente ocupada @1fanwang la tomó hace 79 días. Abiertobug io P3 pinned pubsub
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
apache/beam#28011 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
build P3 sub-task
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
Todos los issues de apache/beam
Issues similares
-
[Bug] RemotingHelper.connect swaps the socket send and receive buffer configurationPosiblemente ocupada @amalsaidov la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
area/ai area/backend component/zeebe kind/task
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
spAnser/reacharound#38 ·
-
status: Ready
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
MobilityData/gtfs-validator#2254 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 89/100
Los mantenedores suelen responder en 1 día