Skip to content

Bigtable and float values #2614

Description

@dmitry-saritasa

tried to store 0.73 as numeric value in bigtable cell and got this error:

TypeError: 0.67couldnotbeconvertedtobytes

Trace

/home/dmitry/Projects/demo/storm/libs/db/models.pyinsave(self, record, instance_id)
205forcolincolumns:
206row.set_cell(
-->207column_family, col, getattr(record, col, None)
208 )
209row.commit()
/home/dmitry/Projects/experiments/storm/petrel/chapter3/example1/petrel/lib/python2.7/site-packages/gcloud/bigtable/row.pycinset_cell(self, column_family_id, column, value, timestamp)
300 """
301self._set_cell(column_family_id, column, value, timestamp=timestamp,
-->302state=None)
303304defdelete(self):
/home/dmitry/Projects/experiments/storm/petrel/chapter3/example1/petrel/lib/python2.7/site-packages/gcloud/bigtable/row.pycin_set_cell(self, column_family_id, column, value, timestamp, state)
126ifisinstance(value, six.integer_types):
127value=_PACK_I64(value)
-->128value=_to_bytes(value)
129iftimestampisNone:
130# Use -1 for current Bigtable server time./home/dmitry/Projects/experiments/storm/petrel/chapter3/example1/petrel/lib/python2.7/site-packages/gcloud/_helpers.pycin_to_bytes(value, encoding)
457returnresult458else:
-->459raiseTypeError('%r could not be converted to bytes'% (value,))
460461

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

Metadata

Metadata

Labels

api: bigtableIssues related to the Bigtable API.priority: p2Moderately-important priority. Fix may not be included in next release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions