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 missing BYTES merger #3271

Merged
merged 2 commits into from
Apr 18, 2017
Merged

Fix missing BYTES merger #3271

merged 2 commits into from
Apr 18, 2017

Conversation

samizuh
Copy link
Contributor

@samizuh samizuh commented Apr 4, 2017

Client needs to know which merger to use when merging column type BYTES that is consumed in chunks as part of a read. Without this fix, client gives a traceback:

.../venv/lib/python2.7/site-packages/google/cloud/spanner/streamed.py", line 262, in _merge_by_type
    merger = _MERGE_BY_TYPE[type_.code]
KeyError: 7

Type 7 is BYTES from the proto definition
The error condition will arise if you write an image (a few MB in size) as base64 encoded in a bytes column. When trying to read the column back using the client, the above traceback will be given. With this fix, the client will use the string merger (treating bytes as a string) and allow the row to be consumed. The test is to read the entire column (with this fix) and write the bytes back to a file (base64 decoded).

Client needs to know which merger to use when merging column type BYTES that is consumed in chunks as part of a read. Without this fix, client gives a traceback:
.../venv/lib/python2.7/site-packages/google/cloud/spanner/streamed.py", line 262, in _merge_by_type
    merger = _MERGE_BY_TYPE[type_.code]
KeyError: 7
Type 7 is BYTES from the proto definition (https://github.com/googleapis/googleapis/blob/master/google/spanner/v1/type.proto)
The error condition will arise if you write an image (a few MB in size) as base64 encoded in a bytes column. When trying to read the column back using the client, the above traceback will be given. With this fix, the client will use the string merger (treating bytes as a string) and allow the row to be consumed. The test is to read the entire column (with this fix) and write the bytes back to a file (base64 decoded).
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 4, 2017
Copy link
Contributor

@lukesneeringer lukesneeringer left a comment

Choose a reason for hiding this comment

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

This looks probably right to me, but sanity checking with @tseaver.

@tseaver tseaver added the api: spanner Issues related to the Spanner API. label Apr 6, 2017
Copy link
Contributor

@tseaver tseaver left a comment

Choose a reason for hiding this comment

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

Needs to add a unit test for _merge_chunk in spanner/tests/unit/test_streamed.py (start from TestStreamedResultSet.test__merge_chunk_string).

related to fix in streamed.py to allow BYTES merger
@samizuh
Copy link
Contributor Author

samizuh commented Apr 6, 2017

Added test case, please let me know if that's sufficient coverage.

@tseaver tseaver merged commit 7100b84 into googleapis:master Apr 18, 2017
@tseaver
Copy link
Contributor

tseaver commented Apr 18, 2017

Thank you for the patch!

@samizuh
Copy link
Contributor Author

samizuh commented Apr 19, 2017

Awesome, thanks!

@samizuh samizuh deleted the patch-1 branch April 19, 2017 00:04
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants