Class: Impala::Connection
- Inherits:
-
Object
- Object
- Impala::Connection
- Defined in:
- lib/impala/connection.rb
Constant Summary collapse
- SLEEP_INTERVAL =
0.1
Instance Method Summary collapse
- #close ⇒ Object
- #execute(raw_query) ⇒ Object
-
#initialize(host, port) ⇒ Connection
constructor
A new instance of Connection.
- #open ⇒ Object
- #open? ⇒ Boolean
- #query(raw_query) ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Connection
Returns a new instance of Connection.
5 6 7 8 9 10 |
# File 'lib/impala/connection.rb', line 5 def initialize(host, port) @host = host @port = port @connected = false open end |
Instance Method Details
#close ⇒ Object
25 26 27 28 |
# File 'lib/impala/connection.rb', line 25 def close @transport.close @connected = false end |
#execute(raw_query) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/impala/connection.rb', line 38 def execute(raw_query) raise ConnectionError.new("Connection closed") unless open? query = sanitize_query(raw_query) handle = send_query(query) wait_for_result(handle) Cursor.new(handle, @service) end |
#open ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/impala/connection.rb', line 12 def open return if @connected socket = Thrift::Socket.new(@host, @port) @transport = Thrift::BufferedTransport.new(socket) @transport.open proto = Thrift::BinaryProtocol.new(@transport) @service = Protocol::ImpalaService::Client.new(proto) @connected = true end |
#open? ⇒ Boolean
30 31 32 |
# File 'lib/impala/connection.rb', line 30 def open? @connected end |
#query(raw_query) ⇒ Object
34 35 36 |
# File 'lib/impala/connection.rb', line 34 def query(raw_query) execute(raw_query).fetch_all end |