sakshammalik260-cse opened a new pull request, #41845:
URL: https://github.com/apache/beam/pull/41845
## Description
Addresses #41223.
This PR introduces a native `Expect` PTransform for the Python SDK and Beam
YAML to simplify data quality validation in Beam pipelines.
The goal is to provide a declarative approach to defining data quality rules
and handling invalid records without requiring custom DoFns and manual
filtering logic.
## Changes
- Added a schema-aware Expect PTransform.
- Implemented restricted SQL-style Boolean expression evaluation.
- Added support for dlq, drop, and fail violation actions.
- Added configurable tagged dead-letter outputs.
- Added structured violation metadata.
- Integrated Expect with Beam YAML.
- Added per-rule pass and quarantine metrics.
- Preserved input schemas, timestamps, and windows.
- Added documentation and regression tests.
- Updated CHANGES.md.
No new production dependencies were introduced.
## Python Example
```python
from apache_beam.transforms.expect import Expect
outputs = records | Expect(
rules=[
{
"name": "positive_amount",
"expression": "amount > 0.0",
"on_violation": "dlq",
}
],
dlq_output="InvalidRecords",
)
valid = outputs["good"]
invalid = outputs["InvalidRecords"]
```
## YAML Example
```yaml
- name: CheckQuality
type: Expect
input: SomeInput
config:
rules:
- name: positive_amount
expression: "amount > 0.0"
on_violation: dlq
dlq_output: InvalidRecords
```
## Testing
Local verification was performed against upstream commit
`ee3077724abbc6bbedc82ae30266bc15bedc68b1`.
| Check | Result |
|---|---|
| Tests passed | 2,088 |
| Tests failed | 0 |
| Tests skipped | 20 |
| Passing subtests | 38 |
| DirectRunner | Passed |
| Embedded FnApiRunner | Passed |
| Threaded workers | Passed |
| Subprocess workers | Passed |
| Ruff | Passed |
| YAPF | Passed |
| Pyrefly | 0 errors |
| Gradle validateChanges | Passed |
| Apache RAT | Passed |
Python and YAML documentation examples were also executed successfully.
## Design Considerations
I am opening this as a draft to gather maintainer feedback before finalizing
the implementation.
I would appreciate feedback on:
- SQL-style expression evaluator and supported dialect.
- Routing precedence and UNKNOWN handling.
- DLQ schema and reserved output names.
- Metric naming and diagnostic counters.
- Aggregate resource limits.
- DLQ consumption requirements.
## Known Limitations
- The evaluator supports a restricted SQL-style dialect.
- Aggregate resource limits remain undecided.
- Remote cloud runners have not been verified.
- Existing YAML inline windowing limitations affect multi-output transforms.
- Metrics follow runner retry semantics.
## Checklist
- [x] Referenced the corresponding issue.
- [x] Added unit and regression tests.
- [x] Updated documentation.
- [x] Updated CHANGES.md.
- [x] Passed local formatting and license checks.
- [ ] ICLA status to be confirmed.
Feedback and suggestions are welcome. Thank you for reviewing
this contribution!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]