因为工作中使用fluentd采集日志,需要使用ruby通过thrift接口插入数据到hbase中,网上搜索了一下,发现很多都是插入单个数据,没办法只好参考python语言写的批量插入修改了代码,终于搞定。$:.unshift File.expand_path("gen-rb", File.dirname(__FILE__))
require "thrift"
require File.expand_path("gen-rb/hbase", File.dirname(__FILE__))
transport = Thrift::BufferedTransport.new(Thrift::Socket.new("localhost", "9090"))
transport.open
client = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(Thrift::BinaryProtocol.new(transport))## Get Table meta datadef newpass( len )
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
newpass = ""
1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
return newpass
end
columnvalue = "v"*10
batchmutations = []
starttime=Time.now
1000.times do |x| mutations=[]
rowkey ="RK_" << Time.now.strftime("%Y%m%d_"<< newpass(15))
5.times do |i|
mutations << Apache::Hadoop::Hbase::Thrift::Mutation.new(:column => "f1:" << i.to_s,:value => columnvalue)
end
batchmutations << Apache::Hadoop::Hbase::Thrift::BatchMutation.new(:row => rowkey,:mutations => mutations)
end
client.mutateRows("testdb2", batchmutations)Hive中添加自定义udf udaf udtf等函数的jar文件的三种方法Oracle OWI 等待事件视图(v$session_wait/v$session_event/v$system_event)相关资讯 Ruby Hbase HBase Thrift
- HBase 参考文档翻译之 Getting (08月15日)
- 如何在Mac OS X上安装 Ruby运行环 (02月13日)
- HBase表数据分页处理 (01月10日)
| - 为啥HBase需要搭建SQL引擎层 (02月19日)
- HBase应用开发回顾与总结系列 (01月10日)
- Apache HBase 2015年发展回顾与未 (01月04日)
|
本文评论 查看全部评论 (0)