Skip to content
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

[YAML] Add JSON parsing to PubSub IO. #28754

Merged
merged 4 commits into from
Oct 6, 2023
Merged

Conversation

robertwb
Copy link
Contributor

This makes #28694 more useful.


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.

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)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@github-actions
Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control

@codecov
Copy link

codecov bot commented Sep 30, 2023

Codecov Report

Merging #28754 (22ae72b) into master (5d6dcee) will decrease coverage by 0.02%.
Report is 63 commits behind head on master.
The diff coverage is 69.52%.

@@            Coverage Diff             @@
##           master   #28754      +/-   ##
==========================================
- Coverage   72.21%   72.20%   -0.02%     
==========================================
  Files         684      685       +1     
  Lines      101241   101338      +97     
==========================================
+ Hits        73116    73171      +55     
- Misses      26546    26588      +42     
  Partials     1579     1579              
Flag Coverage Δ
python 82.72% <69.52%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
sdks/python/apache_beam/yaml/yaml_io.py 71.09% <100.00%> (+1.92%) ⬆️
sdks/python/apache_beam/transforms/ptransform.py 92.50% <81.81%> (-0.23%) ⬇️
sdks/python/apache_beam/yaml/json_utils.py 64.28% <64.28%> (ø)

... and 19 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@robertwb
Copy link
Contributor Author

robertwb commented Oct 6, 2023

R: @liferoad

# limitations under the License.
#

"""Utilities for converting between JSON and Beam Schema'd data.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect these functions will be used internally? If so, can we document this as the internal utilities and no backward compatibility guaranteed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These may be fine to expose, but added a disclaimer just in case.

raise ValueError(f"Unrecognized type_info: {type_info!r}")


def json_parser(beam_schema: schema_pb2.Schema) -> Callable[[bytes], beam.Row]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like only json_parser and json_formatter are used by other modules. I think it would be better to document these clearly. Docstrings will be good at least for these two functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added basic docstrings to all of these methods. Hopefully the name and signatures should make them clear as well.

b'{"generator": {"x": 0, "y": 0}, "rank": 1}',
{'weierstrass': 'y^2+y=x^3-x', 'label': '37a'})
])):
result = p | YamlTransform(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have some error case tests here to improve the coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. This actually uncovered a bug when transforms are explicitly named in some cases. Thanks.

@liferoad
Copy link
Collaborator

liferoad commented Oct 6, 2023

LGTM. Just some minor comments.

@github-actions github-actions bot added the yaml label Oct 6, 2023
@robertwb robertwb merged commit d26a782 into apache:master Oct 6, 2023
84 of 88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants