2014-04-23 20 views
0

我試圖篩選從HBase的表(我用HappyBase)行,具體我試圖讓行,其「身份證」小於1000:過濾整數與HBase的+ Python的

for key, data in graph_table.scan(filter="SingleColumnValueFilter('cf', 'id', <, 'binary:1000')"): 
    print key, data 

的結果如下的:

<http://ieee.rkbexplorer.com/id/publication-d2a6837e67d808b41ffe6092db50f7cc> {'cf:type': 'v', 'cf:id': '100', 'cf:label': '<http://www.aktors.org/ontology/portal#Proceedings-Paper-Reference>'} 
<http://www.aktors.org/ontology/date#1976> {'cf:type': 'v', 'cf:id': '1', 'cf:label': '<http://www.aktors.org/ontology/support#Calendar-Date>'} 
<http://www.aktors.org/ontology/date#1985> {'cf:type': 'v', 'cf:id': '10', 'cf:label': '<http://www.aktors.org/ontology/support#Calendar-Date>'} 

在表中不存在與從1「身份證」到1000如果我使用HBase的Java庫,它工作正常,解析與Byte.toBytes整數值在Java代碼中的各行( )功能。

謝謝。

+0

您能澄清一下:您只使用此搜索來獲得id = 1 | 10 | 100的結果,而表中的值爲1-1000? – Suman

+0

是的,我的數值從1到超過7000,在之前的文章中我想說的是996個結果不見了。 –

+0

SO是一個Q&A網站,因此如果您可以將問題和答案都帶入適當的格式,這將非常有幫助。你可以發佈一個答案給你自己的問題,這很完美。如果這是不可能的,請考慮完全刪除問題。 – JensG

回答

3

好了,問題是,我是節約整數作爲字符串,而正確的做法是將其保存爲字節:

table.put(key, {'cf:id': struct.pack(">q", value)}) 

當查詢數據庫,從過濾器的值必須得裝:

for key, data in graph_table.scan(filter="SingleColumnValueFilter('cf', 'id', <, 'binary:%s', true, false)" % struct.pack(">q", 1000)): 
    print key, data 

最後,拆包結果:

value = struct.unpack(">q", data['cf:id'])[0] 

非常感謝你米UCH。