1
我使用下面的代碼試圖將數據存儲在HBase的在HBase的存儲數據:使用星火
val x = Seq((1, ("a", "A")), (1, ("a", "AA")), (2, ("d", "D")), (2, ("d", "DD")))
val f = sc.parallelize(x)
val z = f.groupByKey()
z.collectAsMap().foreach(elem => {
var rowKey = elem._1.toString()
var p = new Put(rowKey.getBytes())
elem._2.foreach(innerElem => {
var col = innerElem._1
var value = innerElem._2
p.add("cf".getBytes(), new String(col).getBytes(), new String(value).getBytes())
table.put(p)
})
})
table.flushCommits()
我正在從HBase的外殼下面的輸出:
ROW COLUMN+CELL
1 column=cf:a, timestamp=14879172, value=AA
2 column=cf:d, timestamp=1487917201226, value=DD
但我想得到:
ROW COLUMN+CELL
1 column=cf:a, timestamp=14879172, value=A
1 column=cf:a, timestamp=148791720123X, value=AA
2 column=cf:d, timestamp=1487917201226, value=D
2 column=cf:d, timestamp=148791720122X, value=DD
我的代碼覆蓋特定列的第一個值,並只存儲該列的最後一個值。我想存儲特定列的每個值。
當我移動到var p = new Put(rowKey.getBytes())
斯卡拉殼第二foreach循環我有以下幾點:
scala>
| z.collectAsMap().foreach(elem => {
| val rowKey = elem._1.toString()
|
| elem._2.foreach(innerElem => {
| Display all 620 possibilities? (y or n)
| ew Put(rowKey.getBytes())
| var col = innerElem._1
| var value = innerElem._2
| p.add("cf".getBytes(), new String(col).getBytes(), new String(value).getBytes())
| table.put(p)
| })
| })
<console>:49: error: not found: value ew
ew Put(rowKey.getBytes())
^
<console>:52: error: not found: value p
p.add("cf".getBytes(), new String(col).getBytes(), new String(value).getBytes())
^
<console>:53: error: not found: value p
table.put(p)
^
請你指導我創建單獨的Put對象。我在編碼方面很幼稚。提前致謝。 –
將var p = new Put(rowKey.getBytes())移入第二個foreach循環,但顯示錯誤:not found:value:new Put(rowKey.getBytes())。 –
你能告訴我一個片段嗎? – greenshade