Fix missing BYTES merger#3271
Merged
tseaver merged 2 commits intogoogleapis:masterfrom Apr 18, 2017
samizuh:patch-1
Merged
Conversation
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).
lukesneeringer
approved these changes
Apr 4, 2017
Contributor
lukesneeringer
left a comment
There was a problem hiding this comment.
This looks probably right to me, but sanity checking with @tseaver.
tseaver
suggested changes
Apr 6, 2017
Contributor
tseaver
left a comment
There was a problem hiding this comment.
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
Contributor
Author
|
Added test case, please let me know if that's sufficient coverage. |
Contributor
|
Thank you for the patch! |
Contributor
Author
|
Awesome, thanks! |
richkadel
pushed a commit
to richkadel/google-cloud-python
that referenced
this pull request
May 6, 2017
Fix missing BYTES merger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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).