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.
- #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
#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
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/presto/client/client.rb', line 43 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
60 61 62 63 64 65 66 67 68 |
# File 'lib/presto/client/client.rb', line 60 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 |