Repository navigation
Bigtable and float values #2614
Copy link
Copy link
Closed
Labels
api: bigtableIssues related to the Bigtable API.Issues related to the Bigtable API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.
Description
tried to store 0.73 as numeric value in bigtable cell and got this error:
TypeError: 0.67 could not be converted to bytesTrace
/home/dmitry/Projects/demo/storm/libs/db/models.py in save(self, record, instance_id)
205 for col in columns:
206 row.set_cell(
--> 207 column_family, col, getattr(record, col, None)
208 )
209 row.commit()
/home/dmitry/Projects/experiments/storm/petrel/chapter3/example1/petrel/lib/python2.7/site-packages/gcloud/bigtable/row.pyc in set_cell(self, column_family_id, column, value, timestamp)
300 """
301 self._set_cell(column_family_id, column, value, timestamp=timestamp,
--> 302 state=None)
303
304 def delete(self):
/home/dmitry/Projects/experiments/storm/petrel/chapter3/example1/petrel/lib/python2.7/site-packages/gcloud/bigtable/row.pyc in _set_cell(self, column_family_id, column, value, timestamp, state)
126 if isinstance(value, six.integer_types):
127 value = _PACK_I64(value)
--> 128 value = _to_bytes(value)
129 if timestamp is None:
130 # Use -1 for current Bigtable server time.
/home/dmitry/Projects/experiments/storm/petrel/chapter3/example1/petrel/lib/python2.7/site-packages/gcloud/_helpers.pyc in _to_bytes(value, encoding)
457 return result
458 else:
--> 459 raise TypeError('%r could not be converted to bytes' % (value,))
460
461 Checked the source code and see that only int or bytes are allowed to be stored. Therefore I have to convert float value into INT *i.e. 0.63 *100 = 63 and store that as a value
Am I correct and why only ints/bytes are allowed?
thanks,
Dmitry
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: bigtableIssues related to the Bigtable API.Issues related to the Bigtable API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.
Activity
dhermes commentedon Oct 25, 2016
@dmitry-saritasa Thanks for filing.
bytesbut has special methods for counters, which are stored as>q(i.e. along long/ 64-bit signed integer in big-endian byte order).float(double), you'd need to convert tobytese.g.struct.pack('>d', 0.75)@jonparrott WDYT of supporting types other than bytes or integers? It'd be easy enough to do, but may go against the spirit of the API.
dmitry-saritasa commentedon Oct 25, 2016
clear - thanks @dhermes
theacodes commentedon Oct 26, 2016
@dhermes I think it affords discussion - Python's representation of other types may not work if the data is read in another language.
lukesneeringer commentedon Aug 11, 2017
I am going to declare bankruptcy on this issue.
automl: add vision object detection samples for atuoml ga [(#2614)](G…