Skip to content

Instantly share code, notes, and snippets.

@clarksun
Last active December 24, 2017 08:54
Show Gist options
  • Save clarksun/13b661cb554d8b6464b7dc322c647a85 to your computer and use it in GitHub Desktop.
Save clarksun/13b661cb554d8b6464b7dc322c647a85 to your computer and use it in GitHub Desktop.
happybase write hbase
# frontera hbase backend _schedule()
table = self.connection.table(self.table_name)
with table.batch(transaction=True) as b:
for rk, tuples in six.iteritems(data):
obj = dict()
for score, item in tuples:
column = 'f:%0.3f_%0.3f' % get_interval(score, 0.001)
obj.setdefault(column, []).append(item)
final = dict()
from msgpack import Packer
packer = Packer()
for column, items in six.iteritems(obj):
from io import BytesIO
stream = BytesIO()
for item in items:
stream.write(packer.pack(item))
final[column] = stream.getvalue()
final[b'f:t'] = str(timestamp)
b.put(rk, final)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment