Saurabh
Saurabh

Reputation: 73649

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.

Upvotes: 5

Views: 1207

Answers (2)

Jyothu
Jyothu

Reputation: 3154

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

Upvotes: 2

Łukasz Gurdek
Łukasz Gurdek

Reputation: 41

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|

Upvotes: 4

Related Questions