[Bug]: [YAML] Join transform rejects dataclass and schema PCollections due to missing _fields check in _validate_equalities
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
What happened?
In Beam YAML, the Join transform (apache_beam.yaml.yaml_join._validate_equalities) performs equality column validation against input PCollection element schemas.
However, _validate_equalities extracts column names by directly checking getattr(pcoll.element_type, '_fields', []):
# sdks/python/apache_beam/yaml/yaml_join.py:63-69
valid_cols = {
name: set(
dict(fields).keys() if fields and all(
isinstance(field, tuple) for field in fields) else fields)
for (name, pcoll) in pcolls.items()
for fields in [getattr(pcoll.element_type, '_fields', [])]
}
This implementation only works for typing.NamedTuple (where _fields is a tuple of column names) or RowTypeConstraint (where _fields is a tuple of (name, type) tuples). It fails for other first-class Beam schema types:
- Python
@dataclassSchemas: Dataclasses are officially supported first-class schema types in Apache Beam (seeapache_beam.typehints.schemas.match_dataclass_for_row). Dataclasses store field metadata in__dataclass_fields__rather than_fields. Consequently,getattr(pcoll.element_type, '_fields', [])returns[]. - Schemas with Leading Underscores (e.g., CDC metadata columns): In
apache_beam.typehints.schemas.SchemaTranslation.named_tuple_from_schema(schemas.py:681-685), when schema fields begin with an underscore (such as CDC metadata_change_typeor_metadata), Beam dynamically constructs adataclasses.make_dataclassuser type becauseNamedTuplerejects field names starting with an underscore. These schemas also do not have_fields.
When getattr(pcoll.element_type, '_fields', []) evaluates to [], valid_cols[name] evaluates to an empty set set(). Subsequent validation unconditionally raises a ValueError for any equality condition, even when the specified column is valid:
-
For string equalities (
equalities: "user_id"):# yaml_join.py:72-76 for cols in valid_cols.values(): if equalities not in cols: raise ValueError( f'{error_prefix} When "equalities" is a str, ' f'it must be a field name that exists in all the specified inputs.')Fails with:
ValueError: Invalid value "user_id" for "equalities". When "equalities" is a str, it must be a field name that exists in all the specified inputs. -
For mapping equalities (
equalities: [{u: user_id, o: user_id}]):# yaml_join.py:97-99 if col not in valid_cols[pcoll_tag]: raise ValueError( f'{error_prefix} "{col}" is not a valid field in "{pcoll_tag}".')Fails with:
ValueError: Invalid value "[{'u': 'user_id', 'o': 'user_id'}]" for "equalities". "user_id" is not a valid field in "u".
In contrast, other Beam YAML modules (yaml_combine.py:114, yaml_io.py:87, yaml_mapping.py:150, yaml_ml.py:571, yaml_provider.py:1044) consistently use apache_beam.typehints.schemas.named_fields_from_element_type(pcoll.element_type) to reliably extract schema field names across all Beam-supported schema representations.
Code Pointers
sdks/python/apache_beam/yaml/yaml_join.pylines 63–69:
https://github.com/apache/beam/blob/master/sdks/python/apache_beam/yaml/yaml_join.py#L63-L69sdks/python/apache_beam/yaml/yaml_join.pylines 97–99:
https://github.com/apache/beam/blob/master/sdks/python/apache_beam/yaml/yaml_join.py#L97-L99- Canonical schema field extractor:
https://github.com/apache/beam/blob/master/sdks/python/apache_beam/typehints/schemas.py#L761-L763
Steps to Reproduce
Run the following test case or Python reproduction:
import dataclasses
from unittest.mock import MagicMock
from apache_beam.yaml.yaml_join import _validate_equalities
@dataclasses.dataclass
class User:
user_id: int
name: str
@dataclasses.dataclass
class Order:
order_id: int
user_id: int
user_pcoll = MagicMock()
user_pcoll.element_type = User
order_pcoll = MagicMock()
order_pcoll.element_type = Order
pcolls = {'u': user_pcoll, 'o': order_pcoll}
equalities = [{'u': 'user_id', 'o': 'user_id'}]
# Raises ValueError: Invalid value "[{'u': 'user_id', 'o': 'user_id'}]" for "equalities". "user_id" is not a valid field in "u".
_validate_equalities(equalities, pcolls)
Similarly, in a YAML pipeline where upstream transforms yield @dataclass schema records or CDC records with leading underscores, Join fails during pipeline expansion.
Impact
Users cannot use Beam YAML's Join transform with PCollections typed using Python dataclasses or CDC schemas containing leading underscore fields, even though these are standard, supported schema representations in Beam. The pipeline fails at graph construction time with a misleading ValueError claiming the join column does not exist.
Proposed Solution
- In
sdks/python/apache_beam/yaml/yaml_join.py, importnamed_fields_from_element_typefromapache_beam.typehints.schemas:from apache_beam.typehints.schemas import named_fields_from_element_type - Update
_validate_equalitiesto extract column names using Beam's schema utilities, falling back gracefully if element types do not expose a static schema:def _get_fields(element_type): try: return {name for name, _ in named_fields_from_element_type(element_type)} except Exception: # Fall back to _fields attribute if present (e.g. namedtuple or RowTypeConstraint) raw_fields = getattr(element_type, '_fields', None) if raw_fields: if all(isinstance(f, tuple) for f in raw_fields): return dict(raw_fields).keys() return set(raw_fields) return None valid_cols = { name: _get_fields(pcoll.element_type) for (name, pcoll) in pcolls.items() } - When validating equality fields, only validate membership if
valid_cols[pcoll_tag]is known (is not None), preventing false rejections when schema fields cannot be determined statically at construction time.
Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
Issue Components
- Component: Python SDK
- Component: Beam YAML
- Ngôn ngữ chính
- Java
- Star
- 8.7k
- Fork
- 4.8k
- Merge trung bình
- 3 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 445
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/beam
-
awaiting triage java new feature P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug]: [Python] BigTableEnrichmentHandler coerces None lookup keys to literal b'None' and formats blank key name on KeyErrorCó thể đã có người làm @shikhabhadoria đã nhận 6 ngày trước. Đang mởio P2 python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
apache/beam#41346 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Release notes links wrongCó thể đã có người làm @schizophrenicmaniac đã nhận 20 ngày trước. Đang mởbug P3
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 67/100
apache/beam#41197 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
apache/beam#39624 · 2 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug]: PubsubIO used in batch incorrect batch cutoff sizeCó thể đã có người làm @1fanwang đã nhận 98 ngày trước. Đang mởbug io P3 pinned pubsub
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/beam#28011 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Issue tương tự
-
`ovsx verify` fails for a version older than the 100 newest of an extensionCó thể đã có người làm @trivikr đã nhận hôm nay. Đang mởcli
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 81/100
eclipse-openvsx/openvsx#2482 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
32x and 48x Item Model IssuesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Magic-team-jvav/confluence#281 ·
-
CVE-2026-139999 react-routerĐang mởarea/dependencies area/dependencies/js backport/26.6 backport/26.8 kind/cve severity/medium source/scan-dependencies status/triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[DEFECT] AsciiDoc builders write a stray ## before every schema member when the namespace prefixes file binds the schema's own namespaceCó thể đã có người làm @Beehtrix đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cimug-org/CIMTool#427 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
userRaised
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
eclipse-openj9/openj9#25285 ·
Maintainer thường phản hồi trong vòng 1 ngày