Created
December 31, 2010 16:30
-
-
Save kzk/761129 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Operating hBase by JRuby script. | |
# $ hbase org.jruby.Main a.rb | |
# http://wiki.apache.org/hadoop/Hbase/JRuby | |
include Java | |
import org.apache.hadoop.hbase.HBaseConfiguration | |
import org.apache.hadoop.hbase.client.Put | |
import org.apache.hadoop.hbase.client.Get | |
import org.apache.hadoop.hbase.client.Scan | |
import org.apache.hadoop.hbase.client.HTable | |
import org.apache.hadoop.hbase.util.Bytes | |
# 設定情報の読み取り | |
conf = HBaseConfiguration.create | |
conf.add_resource "/etc/hbase/conf/hbase-default.xml" | |
conf.add_resource "/etc/hbase/conf/hbase-site.xml" | |
# 操作対象の情報 | |
key = Bytes.toBytes("row-by-jruby-client") | |
val = Bytes.toBytes("val") | |
# テーブル操作のためのクラス | |
table = HTable.new(conf, "sample") | |
# データの挿入 | |
op_put = Put.new(key) | |
family = Bytes.toBytes("data") | |
column = Bytes.toBytes("column") | |
op_put.add(family, column, val) | |
table.put(op_put) | |
# データの取得 | |
op_get = Get.new(key) | |
r = table.get(op_get) | |
puts r.to_s | |
# データのスキャン | |
scan = Scan.new | |
scanner = table.get_scanner(scan) | |
begin | |
while (row = scanner.next()) do | |
puts row.to_s | |
end | |
ensure | |
scanner.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment