Heim >Datenbank >MySQL-Tutorial >利用ruby通过Thrift接口批量插入HBase

利用ruby通过Thrift接口批量插入HBase

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:28:15914Durchsuche

因为工作中使用fluentd采集日志,需要使用ruby通过thrift接口插入数据到hbase中,网上搜索了一下,发现很多都是插入单个数据,没

因为工作中使用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 data

def newpass( len )
    chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
    newpass = ""
    1.upto(len) { |i| newpass     return newpass
end
columnvalue = "v"*10
batchmutations = []
starttime=Time.now
1000.times do |x|

  mutations=[]
  rowkey ="RK_"     5.times do |i|
        mutations "f1:" columnvalue)
    end
    batchmutations rowkey,:mutations => mutations)
end
client.mutateRows("testdb2", batchmutations)

linux

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn