-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor and cleanup yaml MapToFields. #28462
Conversation
* Avoid the use of MetaProviders, which was always kind of hacky. We may want to remove this infrastructure altogether as it does not play nicely with provider inference. * Split MapToFields into separate mapping, filtering, and exploding operations. * Allow MapToFields to act on non-schema'd PCollections. The various langauge flavors of these UDFs are now handled by a preprocessing step. This will make it easier to extend to other langauges, including in particular possible multiple (equivalent) implementations of javascript to minimize cross-langauge boundary crossings.
R: @Polber |
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control |
Codecov Report
@@ Coverage Diff @@
## master #28462 +/- ##
==========================================
+ Coverage 72.32% 72.33% +0.01%
==========================================
Files 683 683
Lines 100709 100915 +206
==========================================
+ Hits 72834 73001 +167
- Misses 26297 26336 +39
Partials 1578 1578
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 18 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
missing = set(fields.values()) - set(input_schema.keys()) | ||
if missing: | ||
raise ValueError( | ||
f"Missing language specification or unkown input fields: {missing}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f"Missing language specification or unkown input fields: {missing}") | |
f"Unknown input fields: {missing}") |
We've already dealt with the language specifications, right? (plus a typo)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The case above rejects callable and name/path specifications of the UDF. At this point we know that they are inline string expressions, but they could still be arbitrary expressions like "a+b" or even constants (though I suppose we could consider supporting some constants as well.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Unknown" is misspelled though for what it's worth...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly just had comments around error messages, otherwise this looks good to me
Co-authored-by: Danny McCormick <[email protected]>
missing = set(fields.values()) - set(input_schema.keys()) | ||
if missing: | ||
raise ValueError( | ||
f"Missing language specification or unkown input fields: {missing}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Unknown" is misspelled though for what it's worth...
print('yaml_provider.beam_jar', yaml_provider.beam_jar) | ||
sql_provider = yaml_provider.beam_jar( | ||
urns={'Sql': 'beam:external:java:sql:v1'}, | ||
gradle_target='sdks:java:extensions:sql:expansion-service:shadowJar') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have the version as well similar to what is defined in the standard_providers.yaml
? Also, can't the standard_providers.yaml
file be removed since there is now an explicit provider?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this is wrapped by the other provider. We could try to unify them, but there are circular reference issues trying to pull this out from the set of standard providers, which is why it's just re-defined here.
@maybe_with_exception_handling_transform_fn | ||
def _PyJsFilter( | ||
pcoll, keep: Union[str, Dict[str, str]], language: Optional[str] = None): | ||
|
||
if error_handling is None: | ||
error_handling_args = None | ||
input_schema = dict(named_fields_from_element_type(pcoll.element_type)) | ||
if isinstance(keep, str) and keep in input_schema: | ||
keep_fn = lambda row: getattr(row, keep) | ||
else: | ||
error_handling_args = { | ||
'dead_letter_tag' if k == 'output' else k: v | ||
for (k, v) in error_handling.items() | ||
} | ||
keep_fn = _as_callable(list(input_schema.keys()), keep, "keep", language) | ||
return pcoll | beam.Filter(keep_fn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these functions not map the input back to Row
? They used to run through beam.Select
when MapToFields
was 1 function, but with it separated out, why not carry the Select
transform over too or at least utilize the Map transform you included in the test file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filter returns the inputs as outputs. From the users point of view they don't care if they're Row objects or NamedTuple objects (though the equality semantics are a bit strict).
Avoid the use of MetaProviders, which was always kind of hacky. We may want to remove this infrastructure altogether as it does not play nicely with provider inference.
Split MapToFields into separate mapping, filtering, and exploding operations.
Allow MapToFields to act on non-schema'd PCollections.
The various langauge flavors of these UDFs are now handled by a preprocessing step. This will make it easier to extend to other langauges, including in particular possible multiple (equivalent) implementations of javascript to minimize cross-langauge boundary crossings.
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
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, commentfixes #<ISSUE NUMBER>
instead.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.