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

[BEAM-13052] Implement ProtoPlusCoder and add it to the default options #15817

Merged
merged 6 commits into from
Nov 12, 2021

Conversation

dpcollins-google
Copy link
Contributor

Google cloud python client libraries use proto-plus for their protocol message wrappers, this coder enables them to be used in beam pipelines


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • 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.

ValidatesRunner compliance status (on master branch)

Lang ULR Dataflow Flink Samza Spark Twister2
Go --- Build Status Build Status Build Status Build Status ---
Java Build Status Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Python --- Build Status
Build Status
Build Status
Build Status
Build Status
Build Status Build Status ---
XLang Build Status Build Status Build Status Build Status Build Status ---

Examples testing status on various runners

Lang ULR Dataflow Flink Samza Spark Twister2
Go --- --- --- --- --- --- ---
Java --- Build Status
Build Status
Build Status
--- --- --- --- ---
Python --- --- --- --- --- --- ---
XLang --- --- --- --- --- --- ---

Post-Commit SDK/Transform Integration Tests Status (on master branch)

Go Java Python
Build Status Build Status Build Status
Build Status
Build Status

Pre-Commit Tests Status (on master branch)

--- Java Python Go Website Whitespace Typescript
Non-portable Build Status
Build Status
Build Status
Build Status
Build Status
Build Status Build Status Build Status Build Status
Portable --- Build Status Build Status --- --- ---

See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests

See CI.md for more information about GitHub Actions CI.

@dpcollins-google
Copy link
Contributor Author

R: @chamikaramj

@chamikaramj
Copy link
Contributor

cc: @robertwb

@codecov
Copy link

codecov bot commented Oct 27, 2021

Codecov Report

Merging #15817 (5e21f43) into master (03d4e42) will increase coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15817      +/-   ##
==========================================
+ Coverage   83.53%   83.61%   +0.07%     
==========================================
  Files         445      445              
  Lines       61385    61356      -29     
==========================================
+ Hits        51279    51301      +22     
+ Misses      10106    10055      -51     
Impacted Files Coverage Δ
sdks/python/apache_beam/utils/interactive_utils.py 90.24% <0.00%> (-4.88%) ⬇️
...eam/portability/api/beam_expansion_api_pb2_grpc.py 57.89% <0.00%> (-4.02%) ⬇️
...eam/portability/api/beam_provision_api_pb2_grpc.py 73.68% <0.00%> (-2.51%) ⬇️
...hon/apache_beam/runners/direct/test_stream_impl.py 94.02% <0.00%> (-2.24%) ⬇️
...e_beam/portability/api/beam_runner_api_pb2_grpc.py 78.94% <0.00%> (-2.01%) ⬇️
sdks/python/apache_beam/internal/metrics/metric.py 90.00% <0.00%> (-1.00%) ⬇️
...pache_beam/runners/interactive/interactive_beam.py 75.60% <0.00%> (-0.98%) ⬇️
...ache_beam/portability/api/beam_job_api_pb2_grpc.py 56.04% <0.00%> (-0.95%) ⬇️
...beam/portability/api/beam_artifact_api_pb2_grpc.py 56.04% <0.00%> (-0.95%) ⬇️
sdks/python/apache_beam/io/textio.py 96.78% <0.00%> (-0.57%) ⬇️
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10d9594...5e21f43. Read the comment docs.

Copy link
Contributor

@chamikaramj chamikaramj left a comment

Choose a reason for hiding this comment

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

Thanks!

return value._pb.SerializePartialToString(deterministic=True)

def decode(self, value):
return self.proto_plus_type.deserialize(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

To confirm, the API to be used here is different from ProtoCoder above (which uses 'ParseFromString') ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the preferred way to deserialize proto plus types. I can't use the serialize method on line 321 because it is not deterministic, so must drop down to the protobuf interface to do so.

@@ -310,6 +311,19 @@ def encode(self, value):
return value.SerializePartialToString(deterministic=True)


class ProtoPlusCoderImpl(SimpleCoderImpl):
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think this could affect the performance characteristics of existing Python GCP connectors ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't- either they're currently not resolving a coder (and broken) or theyre already registering a custom coder (and this is ignored) or they're not using proto-plus types in their interfaces.

sdks/python/apache_beam/coders/coders.py Show resolved Hide resolved

@classmethod
def from_type_hint(cls, typehint, unused_registry):
if issubclass(typehint, proto.Message):
Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify, currently such messages get encoded using the default coder ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Currently they fall back to picklecoder and fail to serialize the state.



class ProtoPlusCoderTest(unittest.TestCase):
def test_proto_plus_coder(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also add tests that include more complex field types (for example, maps) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See line 140, this is tested.

@chamikaramj
Copy link
Contributor

Run PythonDocker PreCommit

@chamikaramj
Copy link
Contributor

Run Portable_Python PreCommit

1 similar comment
@chamikaramj
Copy link
Contributor

Run Portable_Python PreCommit

@chamikaramj
Copy link
Contributor

Run PythonDocker PreCommit

@chamikaramj
Copy link
Contributor

Run Portable_Python PreCommit

@chamikaramj
Copy link
Contributor

Run PythonDocker PreCommit

1 similar comment
@chamikaramj
Copy link
Contributor

Run PythonDocker PreCommit

@chamikaramj
Copy link
Contributor

Seems like this is blocked by a dependency update ?

16:45:43 ERROR: Cannot install -r /tmp/base_image_requirements.txt (line 37) and protobuf==3.17.3 because these package versions have conflicting dependencies.
16:45:43
16:45:43 The conflict is caused by:
16:45:43 The user requested protobuf==3.17.3
16:45:43 proto-plus 1.19.7 depends on protobuf>=3.19.0
16:45:43

Google cloud python client libraries use proto-plus for their protocol message wrappers, this coder enables them to be used in beam pipelines
Google cloud python client libraries use proto-plus for their protocol message wrappers, this coder enables them to be used in beam pipelines
Google cloud python client libraries use proto-plus for their protocol message wrappers, this coder enables them to be used in beam pipelines
Google cloud python client libraries use proto-plus for their protocol message wrappers, this coder enables them to be used in beam pipelines
Google cloud python client libraries use proto-plus for their protocol message wrappers, this coder enables them to be used in beam pipelines
Copy link
Contributor

@chamikaramj chamikaramj left a comment

Choose a reason for hiding this comment

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

Thanks.

sdks/python/apache_beam/coders/typecoders.py Show resolved Hide resolved
sdks/python/apache_beam/coders/typecoders.py Outdated Show resolved Hide resolved
@chamikaramj
Copy link
Contributor

Thanks. LGTM.

@chamikaramj
Copy link
Contributor

cc: @tvalentyn

@chamikaramj
Copy link
Contributor

Run Python PostCommit 3.8

@chamikaramj
Copy link
Contributor

Run Python 3.8 PostCommit

@chamikaramj
Copy link
Contributor

PostCommit failure is unrelated (https://issues.apache.org/jira/browse/BEAM-13218)

@chamikaramj chamikaramj merged commit be22467 into apache:master Nov 12, 2021
tvalentyn added a commit to tvalentyn/beam that referenced this pull request Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants