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-5612] [BEAM-5315] Python 3 port gcs related io modules. #7650

Merged
merged 2 commits into from
Jan 30, 2019

Conversation

RobbeSneyders
Copy link
Contributor

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)

Lang SDK Apex Dataflow Flink Gearpump Samza Spark
Go Build Status --- --- --- --- --- ---
Java 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
--- --- --- ---

@RobbeSneyders
Copy link
Contributor Author

R: @tvalentyn @markflyhigh @aaltay

@tvalentyn
Copy link
Contributor

R: @markflyhigh

lines.append(line)

contents = ''.join(lines)
contents = b''.join(lines)
Copy link
Contributor

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?

Copy link
Contributor Author

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')))
Copy link
Contributor

@markflyhigh markflyhigh Jan 29, 2019

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@aaltay aaltay merged commit aeee77b into apache:master Jan 30, 2019
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.

4 participants