Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use rbhive gem and query hive

I have a task to query in a hive db from ruby code. I am planning to use rbhive gem, but from it documentation, I am not able to get how to pass username, password, db name, etc when connecting to hive server.

Here is my code:

res = RBHive.connect('host_address', 10_000) do |connection|
  connection.fetch 'show databases;'
end

It just shows:

Connecting to host_server on port 10000
Executing Hive Query: show databases;

and it hangs there indefinitely.

like image 365
Saurabh Avatar asked May 21 '15 11:05

Saurabh


2 Answers

That may be surprising, but with Hive 1.0.0 I managed to connect using

RBHive.tcli_connect('host', 10000, {transport: :sasl, sasl_params:{}}) do |connection|
like image 174
Łukasz Gurdek Avatar answered Nov 19 '22 20:11

Łukasz Gurdek


Please use

options = { username: 'username', password: 'password' }
RBHive.tcli_connect('host', 'port', { transport: :sasl, sasl_params: options}) do |connection|
  results = connection.execute "SHOW DATABASES"
end
like image 2
Jyothu Avatar answered Nov 19 '22 19:11

Jyothu