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

Fix writing raw messages to pubsub #32342

Merged
merged 5 commits into from
Oct 1, 2024
Merged

Conversation

Polber
Copy link
Contributor

@Polber Polber commented Aug 27, 2024

Writing raw messages to pubsub in Beam YAML writes a string object instead of encoded bytes (which is the expected type) - this PR fixes raw messages to instead be converted to bytes format


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.

Signed-off-by: Jeffrey Kinard <jeff@thekinards.com>
@@ -259,7 +259,7 @@ def _create_formatter(
field_names = [field.name for field in beam_schema.fields]
if len(field_names) != 1:
raise ValueError(f'Expecting exactly one field, found {field_names}')
return lambda row: getattr(row, field_names[0])
return lambda row: getattr(row, field_names[0]).encode('utf-8')
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 only do this for string types? (E.g. if it's already bytes, should we leave it alone?)

Should we provide a good error for non-string-bytes fields? (Ideally checked at construction time when possible?)

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 point, let me add those cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@robertwb I went a different direction and instead try to cast object to string, failing if it cannot be done.

Not sure how to best check input type - and what would be considered not compatible? Should we fail a pipeline that is trying to write an integer which can easily be cast to string?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can check the input type by querying beam_schema.fields just like we do to ensure there's exactly one field and we know its name (though we should ensure we properly handle the Any (aka "I don't know") type.

I can see that it could be convenient in some cases to turn things like integers into decimal stringified bytes, but that's not always desirable and feels a bit untypesafe. I'd prefer to err on the side of caution and reject non-string-or-bytes (it'd be backwards compatible to allow that in the future if we need, but not the other way around).

Copy link
Contributor

Choose a reason for hiding this comment

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

Any thoughts on this?

Signed-off-by: Jeffrey Kinard <jeff@thekinards.com>
Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @shunping for label python.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Copy link
Contributor

Reminder, please take a look at this pr: @shunping

Copy link
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @damccorm for label python.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

Copy link
Contributor

Reminder, please take a look at this pr: @damccorm

@damccorm
Copy link
Contributor

@Polber @robertwb what are next steps on this one?

@robertwb
Copy link
Contributor

I updated to make str/bytes required. We should try to get this in the cut.

robertwb and others added 2 commits September 30, 2024 18:33
Signed-off-by: Jeffrey Kinard <jeff@thekinards.com>
@Polber Polber requested a review from robertwb October 1, 2024 20:16
@Polber
Copy link
Contributor Author

Polber commented Oct 1, 2024

@robertwb LGTM

@robertwb robertwb merged commit 0ca3f19 into apache:master Oct 1, 2024
90 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.

3 participants