-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix missing BYTES merger #3271
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).
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.
This looks probably right to me, but sanity checking with @tseaver.
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.
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
Added test case, please let me know if that's sufficient coverage. |
Thank you for the patch! |
Awesome, thanks! |
Fix missing BYTES merger
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).