gpt4 book ai didi

hadoop - 通过JRuby脚本从HBase获取列数据

转载 作者:行者123 更新时间:2023-12-02 21:38:54 31 4
gpt4 key购买 nike

我可以通过HBase获取hbase shell表中某些列的值:

hbase(main):002:0> scan 'some_table', {STARTROW => '7af02800f4c6478cde0f55e8bce34f4a2efa48f2', LIMIT => 1, COLUMNS => ['foo:bar']}
ROW COLUMN+CELL
7af02800f4c6478cde0f55e8bce34f4a2efa48f2 column=foo:bar, timestamp=0, value=http://someurl.com/some/path
1 row(s) in 0.4430 seconds

我想用 jruby脚本重现相同的内容。以下是我的方法。
include Java
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.client.Get

tableName = 'some_table'
conf = HBaseConfiguration.create
ht = HTable.new(conf, tableName)
key = '7af02800f4c6478cde0f55e8bce34f4a2efa48f2'
my_get = Get.new(key.to_java_bytes)
result = ht.get(my_get)

# And what to do now?

通过 HBaseJRuby表中获取列值的正确方法是什么?

最佳答案

include Java
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.client.Get
import org.apache.hadoop.hbase.util.Bytes

tableName = 'some_table'
conf = HBaseConfiguration.create
ht = HTable.new(conf, tableName)
key = '7af02800f4c6478cde0f55e8bce34f4a2efa48f2'
my_get = Get.new(key.to_java_bytes)
result = ht.get(my_get)

# This
puts Bytes.toStringBinary(result.getValue('foo'.to_java_bytes, 'bar'.to_java_bytes))

关于hadoop - 通过JRuby脚本从HBase获取列数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30193739/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com