[Bug]: Beam YAML `Explode` transform crashes on `None`/null collections and fails on non-standard field names
Los mantenedores suelen responder en 2 días
Evaluación
Este issue todavía no se ha evaluado.
Descripción
What happened?
In Beam YAML, the Explode transform (apache_beam.yaml.yaml_mapping._Explode in the Python SDK and org.apache.beam.sdk.schemas.transforms.providers.JavaExplodeTransformProvider in the Java SDK) is designed to unnest/flatten iterable fields into individual rows.
However, both the Python and Java implementations contain critical edge-case and schema flaws when processing real-world data:
1. Unhandled TypeError: 'NoneType' object is not iterable on NULL/missing array fields in Python (yaml_mapping.py)
In sdks/python/apache_beam/yaml/yaml_mapping.py (lines 612–628), explode_cross_product and explode_zip directly iterate over the target field values without checking if the field value is None (standard for nullable array/list columns where no elements exist):
# sdks/python/apache_beam/yaml/yaml_mapping.py:612-628
def explode_cross_product(base, fields):
if fields:
copy = dict(base)
for value in base[fields[0]]: # <--- CRASH if base[fields[0]] is None
copy[fields[0]] = value
yield from explode_cross_product(copy, fields[1:])
else:
yield beam.Row(**base)
def explode_zip(base, fields):
to_zip = [base[field] for field in fields]
copy = dict(base)
for values in itertools.zip_longest(*to_zip, fillvalue=None): # <--- CRASH if to_zip contains None
for ix, field in enumerate(fields):
copy[field] = values[ix]
yield beam.Row(**copy)
- When
cross_product: true: If a record hastags: None(or missing nullable field),for value in base[fields[0]]:evaluates asfor value in None:, throwing an unhandledTypeError: 'NoneType' object is not iterable. - When
cross_product: false: If any field infieldsisNone,to_zipcontainsNone. PassingNoneas a positional argument toitertools.zip_longest(*to_zip)throws an unhandledTypeError: 'NoneType' object is not iterable.
In standard relational/ETL semantics (such as SQL UNNEST, BigQuery UNNEST, and PySpark explode), an inner explode on an empty list ([]) or a NULL list yields 0 rows. In Beam YAML, while an empty list [] yields 0 rows, a None/null value crashes the entire pipeline.
2. Unhandled NullPointerException on null array fields in Java (JavaExplodeTransformProvider.java)
The cross-language Java provider (sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/providers/JavaExplodeTransformProvider.java, lines 182–203) suffers from the exact same failure mode:
- For cross-product (
crossProduct == true, line 183):
Iffor (Object value : inputRow.getIterable(index)) { // <--- Throws NullPointerException if field is null current[index] = value; emitCrossProduct(inputRow, index + 1, current, out); }inputRow.getValue(index)isnull,inputRow.getIterable(index)returnsnull, causing an immediateNullPointerException. - For zip (
crossProduct == false, line 201):
Callingiterators[i] = inputRow.getIterable(i).iterator(); // <--- Throws NullPointerException if field is null.iterator()on a null iterable throws an immediateNullPointerException.
Furthermore, in JavaExplodeTransformProvider.expand (lines 128–131):
outputSchemaBuilder =
outputSchemaBuilder.addField(
field.getName(), field.getType().getCollectionElementType());
The newly created output field does not mark the field as nullable. When crossProduct == false and input arrays have unequal lengths, line 212 attempts builder.addValue(null). If field.getType().getCollectionElementType() is not nullable, Row.Builder.build() throws IllegalArgumentException: Field ... is not nullable.
3. Field Access Failure via getattr(row, name) in Python (yaml_mapping.py)
In sdks/python/apache_beam/yaml/yaml_mapping.py (lines 634–637):
(explode_cross_product if cross_product else explode_zip)({
name: getattr(row, name)
for name in all_fields
}, to_explode)
- If an input record has field names that are not valid Python identifiers (such as kebab-case
user-tagsororder-id, common in JSON, YAML, and BigQuery data),getattr(row, name)raisesAttributeError: 'Row' object has no attribute 'user-tags', becausebeam.Rowdoes not set non-identifier names as Python object attributes. - If a schema field collides with built-in
Rowmethods (such asvalues,items,get,copy, or_asdict),getattr(row, name)retrieves the built-in method rather than the field value.
Record fields should be accessed via mapping syntax (row[name]orrow._asdict()[name]).
4. Type Inference Degradation to Any for Nullable Collections
In sdks/python/apache_beam/yaml/yaml_mapping.py (lines 639–644):
def infer_output_type(self, input_type):
return row_type.RowTypeConstraint.from_fields([(
name,
trivial_inference.element_type(typ) if name in self._fields else
typ) for (name, typ) in named_fields_from_element_type(input_type)])
When an array column is nullable in Beam (Optional[Sequence[T]] / Union[Sequence[T], None]), trivial_inference.element_type does not unwrap UnionConstraint and falls through to return typing.Any (trivial_inference.py:238). As a result, the exploded output schema degrades to Any, losing type safety for downstream transforms.
Code Pointers / Steps to Reproduce
Python Minimal Reproduction
import apache_beam as beam
from apache_beam.yaml.yaml_transform import YamlTransform
# Scenario 1: Null collection crashes Explode with TypeError
with beam.Pipeline() as p:
_ = (
p
| beam.Create([
beam.Row(id=1, tags=['beam', 'yaml']),
beam.Row(id=2, tags=None), # Null array
])
| YamlTransform('''
type: Explode
config:
fields: [tags]
cross_product: true
''')
)
# Raises: TypeError: 'NoneType' object is not iterable
# (In explode_cross_product: for value in base[fields[0]])
# Scenario 2: Zip mode with unequal / null collections
with beam.Pipeline() as p:
_ = (
p
| beam.Create([
beam.Row(id=1, tags=['a', 'b'], meta=None),
])
| YamlTransform('''
type: Explode
config:
fields: [tags, meta]
cross_product: false
''')
)
# Raises: TypeError: 'NoneType' object is not iterable
# (In explode_zip: itertools.zip_longest(*to_zip))
# Scenario 3: Non-identifier field name (e.g. kebab-case)
with beam.Pipeline() as p:
_ = (
p
| beam.Create([
beam.Row(**{'item-id': 1, 'user-tags': ['x', 'y']}),
])
| YamlTransform('''
type: Explode
config:
fields: ['user-tags']
''')
)
# Raises: AttributeError: 'Row' object has no attribute 'user-tags'
Impact
- Pipeline Crashes on Production Data: Any real-world dataset containing optional or missing array fields (e.g., ingested from JSON, Kafka, Pub/Sub, or database tables where list columns can be
NULL) immediately crashes the pipeline with unhandledTypeError(Python) orNullPointerException(Java), rather than cleanly omitting or handling rows with empty/null arrays. - Inability to Explode Hyphenated / Non-Identifier Fields: Real-world schemas often feature kebab-case (
event-tags,item-id), causingAttributeErrorduring field extraction. - Loss of Schema Type Safety: Downstream transforms receive degraded
Anytypes rather than the underlying scalar element type for nullable collection schemas.
Proposed Solution
-
In
sdks/python/apache_beam/yaml/yaml_mapping.py(_Explode.expand):- Safely extract row fields using
row._asdict()orrow[name]instead ofgetattr(row, name). - In
explode_cross_product: treatNonevalues identically to empty collections (base[fields[0]] or ()), yielding 0 rows for that record. - In
explode_zip: guardto_zipinputs withbase[field] or ()soitertools.zip_longestreceives valid iterables. - In
infer_output_type: strip optionality /NoneTypebefore delegating totrivial_inference.element_type, and preserve nullability on the resulting element type.
- Safely extract row fields using
-
In
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/providers/JavaExplodeTransformProvider.java:- Check if
inputRow.getIterable(index) == nullbefore iterating in both cross-product and zip execution paths. - Ensure the generated output field preserves nullable status or allows
nullvalues produced during zip alignment.
- Check if
Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
Issue Components
- Component: Python SDK
- Component: Java SDK
- Component: Beam YAML
- Lenguaje dominante
- Java
- Estrellas
- 8.7k
- Forks
- 4.8k
- Merge medio
- 3 d 16 h
- PR fusionados (30 d)
- 445
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
-
awaiting triage java new feature P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
[Bug]: [Python] BigTableEnrichmentHandler coerces None lookup keys to literal b'None' and formats blank key name on KeyErrorPosiblemente ocupada @shikhabhadoria la tomó hace 6 días. Abiertoio P2 python
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
apache/beam#41346 · 4 comentarios · 1 asignado ·
Los mantenedores suelen responder en 2 días
-
Release notes links wrongPosiblemente ocupada @schizophrenicmaniac la tomó hace 20 días. Abiertobug P3
Dificultad 1/5 Menos de una hora Aptitud para principiantes 67/100
apache/beam#41197 · 3 comentarios · 1 asignado ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
apache/beam#39624 · 2 reacciones ·
Los mantenedores suelen responder en 2 días
-
[Bug]: PubsubIO used in batch incorrect batch cutoff sizePosiblemente ocupada @1fanwang la tomó hace 98 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 2 días
Todos los issues de apache/beam
Issues similares
-
`ovsx verify` fails for a version older than the 100 newest of an extensionPosiblemente ocupada @trivikr la tomó hoy. Abiertocli
Dificultad 2/5 1-3 horas Aptitud para principiantes 81/100
eclipse-openvsx/openvsx#2482 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
32x and 48x Item Model IssuesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Magic-team-jvav/confluence#281 ·
-
CVE-2026-139999 react-routerAbiertoarea/dependencies area/dependencies/js backport/26.6 backport/26.8 kind/cve severity/medium source/scan-dependencies status/triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 67/100
Los mantenedores suelen responder en 2 días
-
[DEFECT] AsciiDoc builders write a stray ## before every schema member when the namespace prefixes file binds the schema's own namespacePosiblemente ocupada @Beehtrix la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
cimug-org/CIMTool#427 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
userRaised
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
eclipse-openj9/openj9#25285 ·
Los mantenedores suelen responder en 1 día