You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request]: [Python/YAML] Add native Expect / data quality PTransform with tagged DLQ outputs #41223
In production data pipelines (e.g. Bronze -> Silver -> Gold), validating records against declarative data quality rules is a fundamental requirement.
Currently in Apache Beam, implementing validation requires writing custom multi-output DoFns and branching logic. In Beam YAML, there is no declarative way to specify data quality rules with automated quarantine actions.
Proposed Architecture
Add an Expect Schema-Aware PTransform in apache_beam.transforms.expect (and register type: Expect in Beam YAML):
I've completed the initial investigation of the Python SDK and YAML infrastructure for this feature. I've also established a local regression baseline of 911 passing tests, 0 failures, and 8 skipped tests.
I'm proposing a schema-aware Expect PTransform implemented using a single native Python ParDo, reusing Beam's existing tagged outputs, schema infrastructure, and Metrics API. A thin YAML adapter would expose the transform as type: Expect.
Before proceeding with implementation, I'd appreciate feedback on a few design decisions:
1. Expression evaluation
The existing generic YAML expression infrastructure does not directly support all the proposed SQL-style predicates, particularly IS NOT NULL and LIKE.
Would a restricted, documented native Python SQL-style predicate evaluator be acceptable, or should this feature reuse Beam SQL through its existing cross-language infrastructure?
The native approach would avoid arbitrary code execution and additional dependencies.
2. Multiple rule violations
I propose evaluating all rules and applying deterministic action precedence:
fail > dlq > drop
A rejected record routed to the DLQ would contain metadata for all violated rules.
3. NULL semantics
I propose SQL three-valued logic, where only TRUE passes a rule and both FALSE and UNKNOWN are treated as violations.
4. Output contracts
Valid records would preserve their original schema. The configurable DLQ output would contain the original record and structured violation metadata.
For YAML, I propose following the existing conventions for default main-output resolution and ensuring that DLQ outputs are consumed or exported.
Please let me know whether these approaches align with the intended scope, particularly regarding expression evaluation and DLQ semantics.
No implementation changes have been made yet. I'm happy to adjust the design based on feedback before proceeding.
I've been working on a provisional implementation of the native Python/YAML Expect transform for this issue.
The current implementation supports:
Schema-aware SQL-style Boolean expectations.
Per-rule dlq, drop, and fail actions.
Configurable tagged dead-letter outputs.
Preservation of the valid input schema.
Structured violation metadata.
Per-rule pass and quarantine counters using Beam's standard Metrics API.
Native Beam YAML integration.
Before opening a PR, I'd appreciate feedback on a few design decisions:
Expression evaluation: Would a restricted, dependency-free Python SQL-style predicate evaluator be acceptable, or would you prefer integration with existing Beam SQL or YAML expression infrastructure?
Multiple violations:The prototype evaluates all rules and applies fail > dlq > drop precedence. Does this match the intended behavior?
DLQ schema: The prototype emits one record containing the original element, structured violation details, a summary message, and an empty stack field for compatibility with existing YAML error conventions.
Metrics: The prototype uses the standard Beam Metrics API with the namespace apache_beam.transforms.expect and counter names expectation_passed:{rule} and expectation_quarantined:{rule}. Additional diagnostic and record-routing counters are currently included.
YAML output handling: The valid output is named good, with a configurable DLQ tag. The names good and output are reserved to avoid conflicts with YAML main-output resolution.
Resource limits: Individual expressions have bounded parsing and evaluation costs. Would maintainers prefer fixed aggregate rule-count and configuration limits, configurable limits, or documented pipeline-author responsibility?
The prototype has passed targeted regression tests and local execution checks, including embedded, threaded, and subprocess worker modes.
I'd be happy to adjust or simplify the implementation based on your feedback before submitting it for formal review.
Activity
sakshammalik260-cse commentedon Nov 30, 2026
.take-issue
sakshammalik260-cse commentedon Dec 1, 2026
Hi @jk-shah,
I've completed the initial investigation of the Python SDK and YAML infrastructure for this feature. I've also established a local regression baseline of 911 passing tests, 0 failures, and 8 skipped tests.
I'm proposing a schema-aware
ExpectPTransform implemented using a single native PythonParDo, reusing Beam's existing tagged outputs, schema infrastructure, and Metrics API. A thin YAML adapter would expose the transform astype: Expect.Before proceeding with implementation, I'd appreciate feedback on a few design decisions:
1. Expression evaluation
The existing generic YAML expression infrastructure does not directly support all the proposed SQL-style predicates, particularly
IS NOT NULLandLIKE.Would a restricted, documented native Python SQL-style predicate evaluator be acceptable, or should this feature reuse Beam SQL through its existing cross-language infrastructure?
The native approach would avoid arbitrary code execution and additional dependencies.
2. Multiple rule violations
I propose evaluating all rules and applying deterministic action precedence:
fail > dlq > dropA rejected record routed to the DLQ would contain metadata for all violated rules.
3. NULL semantics
I propose SQL three-valued logic, where only TRUE passes a rule and both FALSE and UNKNOWN are treated as violations.
4. Output contracts
Valid records would preserve their original schema. The configurable DLQ output would contain the original record and structured violation metadata.
For YAML, I propose following the existing conventions for default main-output resolution and ensuring that DLQ outputs are consumed or exported.
Please let me know whether these approaches align with the intended scope, particularly regarding expression evaluation and DLQ semantics.
No implementation changes have been made yet. I'm happy to adjust the design based on feedback before proceeding.
Thanks!
sakshammalik260-cse commentedon Dec 1, 2026
Hi maintainers,
I've been working on a provisional implementation of the native Python/YAML
Expecttransform for this issue.The current implementation supports:
dlq,drop, andfailactions.Before opening a PR, I'd appreciate feedback on a few design decisions:
Expression evaluation: Would a restricted, dependency-free Python SQL-style predicate evaluator be acceptable, or would you prefer integration with existing Beam SQL or YAML expression infrastructure?
Multiple violations:The prototype evaluates all rules and applies
fail > dlq > dropprecedence. Does this match the intended behavior?DLQ schema: The prototype emits one record containing the original element, structured violation details, a summary message, and an empty stack field for compatibility with existing YAML error conventions.
Metrics: The prototype uses the standard Beam Metrics API with the namespace
apache_beam.transforms.expectand counter namesexpectation_passed:{rule}andexpectation_quarantined:{rule}. Additional diagnostic and record-routing counters are currently included.YAML output handling: The valid output is named
good, with a configurable DLQ tag. The namesgoodandoutputare reserved to avoid conflicts with YAML main-output resolution.Resource limits: Individual expressions have bounded parsing and evaluation costs. Would maintainers prefer fixed aggregate rule-count and configuration limits, configurable limits, or documented pipeline-author responsibility?
The prototype has passed targeted regression tests and local execution checks, including embedded, threaded, and subprocess worker modes.
I'd be happy to adjust or simplify the implementation based on your feedback before submitting it for formal review.
Thank you!
sakshammalik260-cse commentedon Dec 5, 2026
.free-issue