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: add PROTO in streaming chunks #1213

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions google/cloud/spanner_v1/streamed.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ def _merge_struct(lhs, rhs, type_):
TypeCode.TIMESTAMP: _merge_string,
TypeCode.NUMERIC: _merge_string,
TypeCode.JSON: _merge_string,
TypeCode.PROTO: _merge_string,
TypeCode.ENUM: _merge_string,
}


Expand Down
40 changes: 40 additions & 0 deletions tests/unit/test_streamed.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,46 @@ def test__merge_chunk_string_w_bytes(self):
)
self.assertIsNone(streamed._pending_chunk)

def test__merge_chunk_proto(self):
from google.cloud.spanner_v1 import TypeCode

iterator = _MockCancellableIterator()
streamed = self._make_one(iterator)
FIELDS = [self._make_scalar_field("proto", TypeCode.PROTO)]
streamed._metadata = self._make_result_set_metadata(FIELDS)
streamed._pending_chunk = self._make_value(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA"
"6fptVAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA\n"
)
chunk = self._make_value(
"B3RJTUUH4QQGFwsBTL3HMwAAABJpVFh0Q29tbWVudAAAAAAAU0FNUExF"
"MG3E+AAAAApJREFUCNdj\nYAAAAAIAAeIhvDMAAAAASUVORK5CYII=\n"
)

merged = streamed._merge_chunk(chunk)

self.assertEqual(
merged.string_value,
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACXBIWXMAAAsTAAAL"
"EwEAmpwYAAAA\nB3RJTUUH4QQGFwsBTL3HMwAAABJpVFh0Q29tbWVudAAAAAAAU0"
"FNUExFMG3E+AAAAApJREFUCNdj\nYAAAAAIAAeIhvDMAAAAASUVORK5CYII=\n",
)
self.assertIsNone(streamed._pending_chunk)

def test__merge_chunk_enum(self):
from google.cloud.spanner_v1 import TypeCode

iterator = _MockCancellableIterator()
streamed = self._make_one(iterator)
FIELDS = [self._make_scalar_field("age", TypeCode.ENUM)]
streamed._metadata = self._make_result_set_metadata(FIELDS)
streamed._pending_chunk = self._make_value(42)
chunk = self._make_value(13)

merged = streamed._merge_chunk(chunk)
self.assertEqual(merged.string_value, "4213")
self.assertIsNone(streamed._pending_chunk)

def test__merge_chunk_array_of_bool(self):
from google.cloud.spanner_v1 import TypeCode

Expand Down