我在clojure开发了一个函数 scan
hbase表:
(defn- ^Scan make-scan []
(Scan. ))
(defn hscan [hbase tbl]
(let [htbl (.getTable (:connection hbase) (. TableName valueOf tbl))
scanner (.getScanner htbl (make-scan))
results (mapv (fn preprocess-result [result]
result)
scanner)]
(println "Results: " results)))
对于给定的hbase表名,我这样调用函数 lookup
:
(hscan @hbase "lookup")
附言:是的 @hbase
保存hbase配置
我把它作为输出:
Results: [
#object[org.apache.hadoop.hbase.client.Result 0x16cf8438 keyvalues={Pepsi/A:Canada/1443095322877/Put/vlen=5/seqid=0, Pepsi/A:USA/1443095303916/Put/vlen=5/seqid=0}]
#object[org.apache.hadoop.hbase.client.Result 0x3e5beab5 keyvalues={Wallmart/A:Canada/1443095361758/Put/vlen=5/seqid=0, Wallmart/A:USA/1443095349956/Put/vlen=5/seqid=0}]
]
实际上,hbase表中有两行:
hbase(main):007:0> scan 'lookup'
ROW COLUMN+CELL
Pepsi column=A:Canada, timestamp=1443095322877, value=upc-b
Pepsi column=A:USA, timestamp=1443095303916, value=upc-a
Wallmart column=A:Canada, timestamp=1443095361758, value=upc-d
Wallmart column=A:USA, timestamp=1443095349956, value=upc-c
2 row(s) in 0.0790 seconds
问题是我想格式化结果以生成表单的clojureMap:
{
:Pepsi {:A {:USA "upc-a" :Canada "upc-b"}}
:Wallmart {:A {:USA "upc-c" :Canada "upc-d"}}
}
我不知道该怎么实现。请帮我完成这个任务
谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!