<s> from random import random <EOL> from hbase import Hbase <EOL> from hbase . ttypes import * <EOL> from thrift import Thrift <EOL> from thrift . transport import TSocket <EOL> from thrift . transport import TTransport <EOL> from thrift . protocol import TBinaryProtocol <EOL> def setup_thrift_transport ( host ) : <EOL> transport = TSocket . TSocket ( host , <NUM_LIT> ) <EOL> transport = TTransport . TBufferedTransport ( transport ) <EOL> protocol = TBinaryProtocol . TBinaryProtocol ( transport ) <EOL> client = Hbase . Client ( protocol ) <EOL> transport . open ( ) <EOL> return client , transport <EOL> def write_data ( client , table , n ) : <EOL> """<STR_LIT>""" <EOL> rowkey_base = "<STR_LIT>" <EOL> ymd = '<STR_LIT>' <EOL> for trackid in range ( <NUM_LIT:0> , n + <NUM_LIT:1> ) : <EOL> trackid_padded = "<STR_LIT>" % trackid <EOL> rowkey = rowkey_base + trackid_padded + '<STR_LIT:->' + ymd <EOL> mutations = [ ] <EOL> m = { } <EOL> m [ '<STR_LIT>' ] = '<STR_LIT>' + '<STR_LIT>' <EOL> m [ '<STR_LIT:value>' ] = str ( int ( random ( ) * <NUM_LIT> ) ) <EOL> mutations . append ( Mutation ( m ) ) <EOL> if ( trackid % <NUM_LIT:1000> == <NUM_LIT:0> ) : <EOL> print '<STR_LIT>' + rowkey <EOL> client . mutateRow ( table , rowkey , mutations ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> client , transport = setup_thrift_transport ( '<STR_LIT:localhost>' ) <EOL> write_data ( client , '<STR_LIT>' , <NUM_LIT> ) <EOL> transport . close ( ) </s>
