Class: Presto::Client::Client
- Inherits:
-
Object
- Object
- Presto::Client::Client
- Defined in:
- lib/presto/client/client.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #kill(query_id) ⇒ Object
- #query(query, &block) ⇒ Object
- #resume_query(next_uri) ⇒ Object
- #run(query) ⇒ Object
-
#run_with_names(query) ⇒ Object
Accepts the raw response from the Presto Client and returns an array of hashes where you can access the data in each row using the output name specified in the query with AS: SELECT expression AS output_name.
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
22 23 24 |
# File 'lib/presto/client/client.rb', line 22 def initialize() @options = end |
Instance Method Details
#kill(query_id) ⇒ Object
43 44 45 |
# File 'lib/presto/client/client.rb', line 43 def kill(query_id) return Query.kill(query_id, @options) end |
#query(query, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/presto/client/client.rb', line 26 def query(query, &block) q = Query.start(query, @options) if block begin yield q ensure q.close end else return q end end |
#resume_query(next_uri) ⇒ Object
39 40 41 |
# File 'lib/presto/client/client.rb', line 39 def resume_query(next_uri) return Query.resume(next_uri, @options) end |
#run(query) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/presto/client/client.rb', line 47 def run(query) q = Query.start(query, @options) begin columns = q.columns if columns.empty? return [], [] end return columns, q.rows ensure q.close end end |
#run_with_names(query) ⇒ Object
Accepts the raw response from the Presto Client and returns an array of hashes where you can access the data in each row using the output name specified in the query with AS:
SELECT expression AS output_name
64 65 66 67 68 69 70 71 72 |
# File 'lib/presto/client/client.rb', line 64 def run_with_names(query) columns, rows = run(query) column_names = columns.map(&:name) rows.map do |row| Hash[column_names.zip(row)] end end |