beam icon indicating copy to clipboard operation
beam copied to clipboard

[Bug]: [Python/YAML] Beam YAML generic Filter rejects >=, <=, ==, and != comparisons

Open jk-shah opened this issue 3 weeks ago • 0 comments

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:

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:

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:

  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

jk-shah avatar Nov 06 '26 17:11 jk-shah