How to connect to Impala + Kerberos with Ruby

Software Engineering 3532 views

This is a working example of how to connect to Impala via Kerberos using Ruby. It uses the impala gem.

gem 'impala'

require 'impala'

host     = ENV['IMPALA_HOST']
port     = 21000
database = ENV['IMPALA_DATABASE']
options  = {
  username: ENV['IMPALA_USERNAME'],
  password: ENV['IMPALA_PASSWORD'],
  kerberos: {
      host: ENV['IMPALA_KERBEROS_HOST'],
      principal: 'impala'
  }
}

Impala.connect(host, port, options) do |conn|
  result = conn.query("SELECT count(*) AS 'count' from #{database}.my_table")
  puts result[0][:count]
end
main.rb

Usage

ruby main.rb

On Windows

Note, on Windows, you'll need to install MIT's Kerberos Ticket Manager first. It will need to be properly configured (krb5.ini), and you'll need a valid keytab file. If you run the above Ruby script without first generating a new ticket, the MIT GUI will pop up: