Skip to content

Fix missing BYTES merger - #3271

Merged
tseaver merged 2 commits into
googleapis:masterfrom
samizuh:patch-1
Apr 18, 2017
Merged

Fix missing BYTES merger#3271
tseaver merged 2 commits into
googleapis:masterfrom
samizuh:patch-1

Conversation

@samizuh

Copy link
Copy Markdown

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).
@googlebotgooglebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 4, 2017

@lukesneeringerlukesneeringer left a comment

Copy link
Copy Markdown
Contributor

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.

@tseavertseaver added the api: spanner Issues related to the Spanner API. label Apr 6, 2017

@tseavertseaver left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Author

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

@tseaver
tseaver merged commit 7100b84 into googleapis:masterApr 18, 2017
@tseaver

Copy link
Copy Markdown
Contributor

Thank you for the patch!

@samizuh

Copy link
Copy Markdown
Author

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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spannerIssues related to the Spanner API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@samizuh@tseaver@lukesneeringer@googlebot