Skip to content

Bigtable and float values #2614

@dmitry-saritasa

Description

@dmitry-saritasa

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

TypeError: 0.67 could not be converted to bytes

Trace

/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

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