通过jruby脚本从hbase获取列数据

qvk1mo1f  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(276)

我可以得到中某列的值 HBase 表via 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?

从中获取列值的正确方法是什么 HBase 表via JRuby ?

oaxa6hgo

oaxa6hgo1#

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))

相关问题