2015-04-05 23 views
2

我一直在使用java和python測試table.put。確實happybase table.put接受無字符串值?

在java中,可以將int或float值寫入列。使用happybase

table.put(line_item_key, {'allinone:quantity': quantity}) 

它彈了與 類型錯誤:類型「詮釋」的對象沒有LEN()

難道這是真的happybase不支持寫出來的字符串以外什麼?

回答

4

在Hbase中,一切都是字節數組。沒有像int,string,float,double等任何花哨的數據類型。因此,無論何時想要插入到hbase表中,首先需要將其轉換爲字節數組。然後你可以插入。

+0

這在Happybase文檔中也很明顯提到:http://happybase.readthedocs.org/en/latest/user.html#manipulating-data – 2015-04-12 09:56:53

0

您還可以使用與python結構模塊的happybase插入字節數組到hbase。

import struct 

quantity = struct.pack(">i", 1) 
table.put(rowkey, {'allinone:quantity': quantity}) 

這將在HBase中插入二進制表示。