Last active
December 24, 2017 08:54
-
-
Save clarksun/13b661cb554d8b6464b7dc322c647a85 to your computer and use it in GitHub Desktop.
happybase write hbase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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