You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "Polber (via GitHub)" <gi...@apache.org> on 2024/05/28 21:29:03 UTC
[PR] [YAML] Fix simple YAML mappings type hinting [beam]
Polber opened a new pull request, #31427:
URL: https://github.com/apache/beam/pull/31427
There have been type inferencing issues with Beam YAML `MapToFields` where the type(s) from the upstream pcollection are dropped when the `beam.Select` is used on unmapped fields in the `MapToFields` expansion (i.e. when using `append: true`, the unmapped fields are mapped to AnyType).
The fix is to register type hints for the implicitly appended fields.
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [YAML] Fix simple YAML mappings type hinting [beam]
Posted by "robertwb (via GitHub)" <gi...@apache.org>.
robertwb commented on code in PR #31427:
URL: https://github.com/apache/beam/pull/31427#discussion_r1617930991
##########
sdks/python/apache_beam/yaml/yaml_mapping.py:
##########
@@ -276,12 +277,19 @@ def _as_callable_for_pcoll(
if isinstance(fn_spec, str) and fn_spec in input_schema:
return lambda row: getattr(row, fn_spec)
else:
- return _as_callable(list(input_schema.keys()), fn_spec, msg, language)
+ return _as_callable(
+ list(input_schema.keys()), fn_spec, msg, language, input_schema)
-def _as_callable(original_fields, expr, transform_name, language):
+def _as_callable(
+ original_fields, expr, transform_name, language, input_schema=None):
+
+ # Extract original type from upstream pcoll when doing simple mappings
+ if input_schema is None:
+ input_schema = {}
+ original_type = input_schema.get(transform_name, None)
Review Comment:
I'm not quite understanding why you want to use `transform_name` as a key in the input schema here.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [YAML] Fix simple YAML mappings type hinting [beam]
Posted by "Polber (via GitHub)" <gi...@apache.org>.
Polber commented on code in PR #31427:
URL: https://github.com/apache/beam/pull/31427#discussion_r1617945021
##########
sdks/python/apache_beam/yaml/yaml_mapping.py:
##########
@@ -276,12 +277,19 @@ def _as_callable_for_pcoll(
if isinstance(fn_spec, str) and fn_spec in input_schema:
return lambda row: getattr(row, fn_spec)
else:
- return _as_callable(list(input_schema.keys()), fn_spec, msg, language)
+ return _as_callable(
+ list(input_schema.keys()), fn_spec, msg, language, input_schema)
-def _as_callable(original_fields, expr, transform_name, language):
+def _as_callable(
+ original_fields, expr, transform_name, language, input_schema=None):
+
+ # Extract original type from upstream pcoll when doing simple mappings
+ if input_schema is None:
+ input_schema = {}
+ original_type = input_schema.get(transform_name, None)
Review Comment:
There is no good reason, I think that was the result of an earlier null issue that no longer applies. Removed a couple lines related to obsolete cases
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [YAML] Fix simple YAML mappings type hinting [beam]
Posted by "Polber (via GitHub)" <gi...@apache.org>.
Polber commented on PR #31427:
URL: https://github.com/apache/beam/pull/31427#issuecomment-2136274529
> It'd be good to add a test if it's not that hard.
@robertwb
Added a test.
Interestingly, if I remove the following from the test, it correctly inferences the types...
```
elements.element_type = schemas.named_tuple_from_schema(
schema_pb2.Schema(
fields=[
schemas.schema_field('label', str),
schemas.schema_field('conductor', int),
schemas.schema_field('rank', int)
]))
```
i.e. if exactly what is done in the ReadFromPubSub
https://github.com/apache/beam/blob/df067dba5dc509135e857596224759e485d47a0b/sdks/python/apache_beam/yaml/yaml_io.py#L325-L326
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [YAML] Fix simple YAML mappings type hinting [beam]
Posted by "Polber (via GitHub)" <gi...@apache.org>.
Polber commented on PR #31427:
URL: https://github.com/apache/beam/pull/31427#issuecomment-2136472252
Fixes #31434
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [YAML] Fix simple YAML mappings type hinting [beam]
Posted by "Polber (via GitHub)" <gi...@apache.org>.
Polber commented on PR #31427:
URL: https://github.com/apache/beam/pull/31427#issuecomment-2136141861
R: @robertwb
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [YAML] Fix simple YAML mappings type hinting [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #31427:
URL: https://github.com/apache/beam/pull/31427#issuecomment-2136143340
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [YAML] Fix simple YAML mappings type hinting [beam]
Posted by "robertwb (via GitHub)" <gi...@apache.org>.
robertwb merged PR #31427:
URL: https://github.com/apache/beam/pull/31427
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org