-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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-5612] [BEAM-5315] Python 3 port gcs related io modules. #7650
Conversation
a3eb70f
to
5935d5b
Compare
R: @markflyhigh |
lines.append(line) | ||
|
||
contents = ''.join(lines) | ||
contents = b''.join(lines) |
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.
Why converting to bytes works here? Can you explain a little more about the problem?
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.
os.urandom
returns a bytestring
. On Python 2, this worked using string
, since a Python 2 string
is actually a bytestring
('' = b''
), while on Python 3 a string
is actually a unicode
string ('' = u''
). By defining b''
, we get the same behavior on both Python versions.
@@ -512,7 +512,8 @@ def create_job(self, job): | |||
if job_location: | |||
gcs_or_local_path = os.path.dirname(job_location) | |||
file_name = os.path.basename(job_location) | |||
self.stage_file(gcs_or_local_path, file_name, io.BytesIO(job.json())) | |||
self.stage_file(gcs_or_local_path, file_name, | |||
io.BytesIO(job.json().encode('utf-8'))) |
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.
Pipeline works well to me without this change. Wondering what problem you want to fix here?
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.
io.BytesIO()
expects bytes
, while job.json()
returns a string
. Is this code path executed when running your pipeline?
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.
I don't think we hit this codepath before, the change makes sense to me.
This is is part of a series of PRs with goal to make Apache Beam PY3 compatible. The proposal with the outlined approach has been documented here: https://s.apache.org/beam-python-3.
This PR adds a py3-gcp test suite to tox and ports the gcs related io modules.
Post-Commit Tests Status (on master branch)