jk-shah opened a new issue, #41350:
URL: https://github.com/apache/beam/issues/41350

   ### What happened?
   
   In `apache_beam.yaml.yaml_combine` 
(`sdks/python/apache_beam/yaml/yaml_combine.py`, lines `35-45` and `135-172`), 
`PyJsYamlCombine` infers `typing.Any` as the output field type for builtin 
`CombineFn` instances (`count`, `mean`, `group`, `concat`):
   
   ```python
   import apache_beam as beam
   from apache_beam.runners.portability import fn_api_runner
   from apache_beam.yaml import yaml_combine
   
   p = beam.Pipeline(runner=fn_api_runner.FnApiRunner())
   pc = p | beam.Create([beam.Row(dept='eng', amount=10.0)])
   out = pc | yaml_combine.PyJsYamlCombine(
       group_by=['dept'],
       combine={
           'cnt': {'value': 'amount', 'fn': {'type': 'count'}},
           'avg': {'value': 'amount', 'fn': {'type': 'mean'}},
       },
       language='python',
   )
   print(out.element_type)
   # Row(dept=<class 'str'>, cnt=typing.Any, avg=typing.Any)
   ```
   
   When chained into `WriteToParquet` (or any sink requiring concrete Beam 
schema field types via `arrow_type_compatibility`), pipeline construction or 
execution fails because `typing.Any` cannot be converted to an Arrow schema 
type.
   
   ### Cause
   
   In `PyJsYamlCombine.expand` (lines `159-163`):
   - `BUILTIN_COMBINE_FNS['count']` is `CountCombineFn()` and `'mean'` is 
`MeanCombineFn()`.
   - `isinstance(fn, beam.CombineFn)` calls `extract_return_type(fn)` (lines 
`135-145`).
   - `get_type_hints(fn).has_simple_output_type()` is `False` on 
`CountCombineFn()` / `MeanCombineFn()`, and `callable(fn)` is `False` on 
`CombineFn` instances (which implement `extract_output`, not `__call__`), so 
`extract_return_type(fn)` falls through to `return Any`.
   - Using `fn.get_output_type()` (and/or `@with_output_types(int)` on 
`CountCombineFn`, `Optional[float]` on `MeanCombineFn`, `list[expr_type]` on 
`ToListCombineFn`) resolves concrete output types cleanly.
   
   ### 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
   - [x] Component: Beam YAML
   - [ ] Component: Beam ML
   - [ ] 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]

Reply via email to