我在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")
PS:@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
问题是我想格式化结果以生成表格的clojure地图:
{
:Pepsi {:A {:USA "upc-a" :Canada "upc-b"}}
:Wallmart {:A {:USA "upc-c" :Canada "upc-d"}}
}
我迷失了如何实现这一点。请帮助我实现这个实现
谢谢!