Class: Presto::Client::Query
- Inherits:
-
Object
- Object
- Presto::Client::Query
- Defined in:
- lib/presto/client/query.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
- #cancel ⇒ Object
- #close ⇒ Object
- #columns ⇒ Object
- #each_row(&block) ⇒ Object
- #each_row_chunk(&block) ⇒ Object
-
#initialize(client) ⇒ Query
constructor
A new instance of Query.
- #rows ⇒ Object
Constructor Details
#initialize(client) ⇒ Query
Returns a new instance of Query.
39 40 41 |
# File 'lib/presto/client/query.rb', line 39 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
43 44 45 |
# File 'lib/presto/client/query.rb', line 43 def client @client end |
Class Method Details
.start(query, options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/presto/client/query.rb', line 24 def self.start(query, ) server = [:server] unless server raise ArgumentError, ":server option is required" end faraday = Faraday.new(url: "http://#{server}") do |faraday| #faraday.request :url_encoded faraday.response :logger if [:http_debug] faraday.adapter Faraday.default_adapter end new StatementClient.new(faraday, query, ) end |
Instance Method Details
#cancel ⇒ Object
92 93 94 |
# File 'lib/presto/client/query.rb', line 92 def cancel @client.cancel_leaf_stage end |
#close ⇒ Object
96 97 98 99 |
# File 'lib/presto/client/query.rb', line 96 def close @client.cancel_leaf_stage nil end |
#columns ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/presto/client/query.rb', line 53 def columns wait_for_data raise_error unless @client.query_succeeded? return @client.current_results.columns end |
#each_row(&block) ⇒ Object
69 70 71 72 73 |
# File 'lib/presto/client/query.rb', line 69 def each_row(&block) each_row_chunk {|chunk| chunk.each(&block) } end |
#each_row_chunk(&block) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/presto/client/query.rb', line 75 def each_row_chunk(&block) wait_for_data raise_error unless @client.query_succeeded? if self.columns == nil raise PrestoError, "Query #{@client.current_results.id} has no columns" end begin if data = @client.current_results.data block.call(data) end @client.advance end while @client.has_next? end |
#rows ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/presto/client/query.rb', line 61 def rows rows = [] each_row_chunk {|chunk| rows.concat(chunk) } return rows end |