利用ruby通过Thrift接口批量插入HBase
因为工作中使用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)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the advent of the big data era, data processing and storage have become more and more important, and how to efficiently manage and analyze large amounts of data has become a challenge for enterprises. Hadoop and HBase, two projects of the Apache Foundation, provide a solution for big data storage and analysis. This article will introduce how to use Hadoop and HBase in Beego for big data storage and query. 1. Introduction to Hadoop and HBase Hadoop is an open source distributed storage and computing system that can

Many people may notice a phenomenon, that is, in some modern programming languages (of course, not referring to "recent" programming languages), the increment and decrement operators have been cancelled. In other words, there is no such expression as i++ or j-- in these languages, but only i+=1 or j-=1 Such an expression. This answer will explore the background and reasons for this phenomenon from the perspective of design philosophy. Strictly speaking, it may be biased to say "i++ is disappearing", because it seems that only Python, Rust and Swift among mainstream programming languages do not support the increment and decrement operators. When I first came into contact with Python, this was also

Ruby operates MySQL using mysql2 to connect to mysql and operate mysql. geminstallmysql2 connects to mysql to establish a connection: require'mysql2'conn=Mysql2::Client.new({host:'192.168.200.73',username:'root',password:'P@ssword1!'}) The accepted connection options include: Mysql2::Clie

The main difference between Go and Ruby is that Go is a statically typed compiled language that supports lightweight parallelism and efficient memory management, and is suitable for writing high-concurrency applications; Ruby is a dynamically typed interpreted language that supports true parallelism but memory management It requires manual control and is suitable for writing flexible web applications.

How to use MySQL and Ruby to implement a simple data analysis report function Introduction: In today's data-driven era, data analysis plays a crucial role in corporate decision-making and development. As an important part of data analysis, data analysis reports are of great significance for organizing, visualizing and interpreting data. This article will introduce how to use MySQL and Ruby to implement a simple data analysis report function, and provide corresponding code examples. 1. Database design and table creation must realize data analysis and reporting functions

How to use MySQL and Ruby to implement a simple data conversion function. In actual development work, data conversion is often required to convert one data format into another data format. This article will introduce how to use MySQL and Ruby to implement a simple data conversion function, and provide specific code examples. First, we need to install and configure the MySQL and Ruby environments. Make sure you have a MySQL database installed and can connect to the database via the command line or other tools. In addition, you need to install

How to use Redis and Ruby to develop real-time log analysis functions With the development of the Internet, more and more information is recorded in the form of logs. Analysis of these logs is very valuable and can help us understand the operation of the system, discover problems, optimize performance, etc. In this article, we will introduce how to develop a real-time log analysis function using Redis and Ruby. Install Redis and Ruby First, we need to install Redis and Ruby environments. Redis is an in-memory database

Dependency: org.springframework.dataspring-data-hadoop-hbase2.5.0.RELEASEorg.apache.hbasehbase-client1.1.2org.springframework.dataspring-data-hadoop2.5.0.RELEASE The official way to add configuration is through xml, which is simple After rewriting, it is as follows: @ConfigurationpublicclassHBaseConfiguration{@Value("${hbase.zooke
