Class: Presto::Client::StatementClient
- Inherits:
-
Object
- Object
- Presto::Client::StatementClient
- Defined in:
- lib/presto/client/statement_client.rb
Constant Summary collapse
- HEADERS =
{ "User-Agent" => "presto-ruby/#{VERSION}" }
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #advance ⇒ Object
- #cancel_leaf_stage ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #current_results ⇒ Object
- #debug? ⇒ Boolean
- #exception? ⇒ Boolean
- #has_next? ⇒ Boolean
-
#initialize(faraday, query, options) ⇒ StatementClient
constructor
A new instance of StatementClient.
- #query_failed? ⇒ Boolean
- #query_succeeded? ⇒ Boolean
Constructor Details
#initialize(faraday, query, options) ⇒ StatementClient
Returns a new instance of StatementClient.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/presto/client/statement_client.rb', line 39 def initialize(faraday, query, ) @faraday = faraday @faraday.headers.merge!(HEADERS) = @query = query @closed = false @exception = nil post_query_request! end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
99 100 101 |
# File 'lib/presto/client/statement_client.rb', line 99 def exception @exception end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
89 90 91 |
# File 'lib/presto/client/statement_client.rb', line 89 def query @query end |
Instance Method Details
#advance ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/presto/client/statement_client.rb', line 121 def advance if closed? || !has_next? return false end uri = @results.next_uri start = Time.now attempts = 0 begin begin response = @faraday.get do |req| req.url uri end rescue => e @exception = e raise @exception end if response.status == 200 && !response.body.to_s.empty? @results = QueryResults.decode_hash(MultiJson.load(response.body)) return true end if response.status != 503 # retry on 503 Service Unavailable # deterministic error @exception = PrestoHttpError.new(response.status, "Error fetching next at #{uri} returned #{response.status}: #{response.body}") raise @exception end attempts += 1 sleep attempts * 0.1 end while (Time.now - start) < 2*60*60 && !@closed @exception = PrestoHttpError.new(408, "Error fetching next due to timeout") raise @exception end |
#cancel_leaf_stage ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/presto/client/statement_client.rb', line 159 def cancel_leaf_stage if uri = @results.next_uri response = @faraday.delete do |req| req.url uri end return response.status / 100 == 2 end return false end |
#close ⇒ Object
169 170 171 172 173 174 175 176 177 178 |
# File 'lib/presto/client/statement_client.rb', line 169 def close return if @closed # cancel running statement # TODO make async reqeust and ignore response? cancel_leaf_stage @closed = true nil end |
#closed? ⇒ Boolean
95 96 97 |
# File 'lib/presto/client/statement_client.rb', line 95 def closed? @closed end |
#current_results ⇒ Object
113 114 115 |
# File 'lib/presto/client/statement_client.rb', line 113 def current_results @results end |
#debug? ⇒ Boolean
91 92 93 |
# File 'lib/presto/client/statement_client.rb', line 91 def debug? !![:debug] end |
#exception? ⇒ Boolean
101 102 103 |
# File 'lib/presto/client/statement_client.rb', line 101 def exception? @exception end |
#has_next? ⇒ Boolean
117 118 119 |
# File 'lib/presto/client/statement_client.rb', line 117 def has_next? !!@results.next_uri end |
#query_failed? ⇒ Boolean
105 106 107 |
# File 'lib/presto/client/statement_client.rb', line 105 def query_failed? @results.error != nil end |
#query_succeeded? ⇒ Boolean
109 110 111 |
# File 'lib/presto/client/statement_client.rb', line 109 def query_succeeded? @results.error == nil && !@exception && !@closed end |