jk-shah opened a new issue, #41043:
URL: https://github.com/apache/beam/issues/41043
### What happened?
In Beam YAML, `Filter` with `language: generic` documents support for `==`,
`<=`, `>=`, `<`, `>`, and `!=` comparisons (`validate_generic_expression` in
`sdks/python/apache_beam/yaml/yaml_mapping.py` checks `cmp in {'==', '<=',
'>=', '<', '>', '!='}`), but any two-character comparison operator (`>=`, `<=`,
`==`, `!=`) is rejected at pipeline validation time with `ValueError`:
```yaml
pipeline:
type: chain
transforms:
- type: Create
config:
elements:
- {id: 1, name: Ada, age: 36}
- {id: 2, name: Linus, age: 17}
- type: Filter
config:
language: generic
keep: "age >= 21"
- type: LogForTesting
```
Running this pipeline fails with:
```text
ValueError: Missing language specification, unknown input fields, or invalid
generic expression: age >= 21. The given input fields are ['id', 'name',
'age']. See https://beam.apache.org/documentation/sdks/yaml-udf/#generic
```
Only single-character operators (`<` and `>`) succeed.
### Cause
In `sdks/python/apache_beam/yaml/yaml_mapping.py`,
`validate_generic_expression` splits comparison expressions using a greedy left
group:
```python
if allow_cmp:
maybe_cmp = re.fullmatch('(.*)([<>=!]+)(.*)', expr)
if maybe_cmp:
left, cmp, right = maybe_cmp.groups()
if (is_atomic(left.strip()) and is_atomic(right.strip()) and
cmp in {'==', '<=', '>=', '<', '>', '!='}):
return
```
Because `(.*)` is greedy and `[<>=!]+` only requires at least one character,
`'age >= 21'` is split into:
- `left = 'age >'` (which fails `is_atomic(left.strip())`)
- `cmp = '='` (which is not in `{'==', '<=', '>=', '<', '>', '!='}`)
- `right = ' 21'`
Making the left group non-greedy (`(.*?)`) keeps multi-character operators
intact.
### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [x] 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
--
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]