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-10475] Add typehints for ShardedKeyCoder #13474

Merged
merged 2 commits into from Dec 4, 2020

Conversation

nehsyc
Copy link
Contributor

@nehsyc nehsyc commented Dec 3, 2020

Implement to_type_hint and from_type_hint for ShardedKeyCoder and add a TypeConstraint for ShardedKey so during the runner API translation the corresponding coder can be added.


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.

Post-Commit Tests Status (on master branch)

Lang SDK Dataflow Flink Samza Spark Twister2
Go 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
Python Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
--- Build Status ---
XLang 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 --- --- --- ---

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.

from apache_beam.utils.sharded_key import ShardedKey


class ShardedKeyTypeConstraint(typehints.TypeConstraint):
Copy link
Member

Choose a reason for hiding this comment

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

To verify: this type constraint is for Beam internal use only and users are not expected specify it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Users or dev may use it for specifying the output type of a transform to provide type hints.

Copy link
Member

Choose a reason for hiding this comment

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

If you do want to allow something like a ShardedKey type hint annotation in code, add it here:

Any = AnyTypeConstraint()

(doesn't have to be in this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Thanks for pointing it out. I will change that in a follow-up PR.

sdks/python/apache_beam/coders/coders.py Show resolved Hide resolved
sdks/python/apache_beam/coders/coders.py Show resolved Hide resolved
Copy link
Member

@udim udim left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the thorough tests!

LMK if I can merge this or if you have more changes to make

def test_type_check_not_sharded_key(self):
constraint = ShardedKeyTypeConstraint(int)
obj = 5
with self.assertRaises(TypeError) as e:
Copy link
Member

Choose a reason for hiding this comment

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

Note: self.assertRaisesRegex can also check exception messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know!

@nehsyc
Copy link
Contributor Author

nehsyc commented Dec 4, 2020

LGTM, thanks for the thorough tests!

LMK if I can merge this or if you have more changes to make

Thanks for the review! This is good to go.

@udim udim merged commit 44a2ac5 into apache:master Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants