SHARE
TWEET

hbase jruby

hivefans Aug 22nd, 2013 (edited) 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Operating hBase by JRuby script.
  2. # $ hbase org.jruby.Main a.rb
  3. # http://wiki.apache.org/hadoop/Hbase/JRuby
  4.  
  5. include Java
  6. import org.apache.hadoop.hbase.HBaseConfiguration
  7. import org.apache.hadoop.hbase.client.Put
  8. import org.apache.hadoop.hbase.client.Get
  9. import org.apache.hadoop.hbase.client.Scan
  10. import org.apache.hadoop.hbase.client.HTable
  11. import org.apache.hadoop.hbase.util.Bytes
  12.  
  13. # 設定情報の読み取り
  14. conf = HBaseConfiguration.create
  15. conf.add_resource "/etc/hbase/conf/hbase-default.xml"
  16. conf.add_resource "/etc/hbase/conf/hbase-site.xml"
  17.  
  18. # 操作対象の情報
  19. key = Bytes.toBytes("row-by-jruby-client")
  20. val = Bytes.toBytes("val")
  21.  
  22. # テーブル操作のためのクラス
  23. table = HTable.new(conf, "sample")
  24.  
  25. # データの挿入
  26. op_put = Put.new(key)
  27. family = Bytes.toBytes("data")
  28. column = Bytes.toBytes("column")
  29. op_put.add(family, column, val)
  30. table.put(op_put)
  31.  
  32. # データの取得
  33. op_get = Get.new(key)
  34. r = table.get(op_get)
  35. puts r.to_s
  36.  
  37. # データのスキャン
  38. scan = Scan.new
  39. scanner = table.get_scanner(scan)
  40. begin
  41.   while (row = scanner.next()) do
  42.     puts row.to_s
  43.   end
  44. ensure
  45.   scanner.close
  46. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top