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
- #close ⇒ Object
- #closed? ⇒ Boolean
- #current_results ⇒ Object
- #debug? ⇒ Boolean
- #exception? ⇒ Boolean
- #has_next? ⇒ Boolean
-
#initialize(faraday, session, query) ⇒ StatementClient
constructor
A new instance of StatementClient.
- #query_failed? ⇒ Boolean
- #query_succeeded? ⇒ Boolean
Constructor Details
#initialize(faraday, session, query) ⇒ StatementClient
Returns a new instance of StatementClient.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/presto/client/statement_client.rb', line 38 def initialize(faraday, session, query) @faraday = faraday @faraday.headers.merge!(HEADERS) @session = session @query = query @closed = false @exception = nil post_query_request! end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
91 92 93 |
# File 'lib/presto/client/statement_client.rb', line 91 def exception @exception end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
81 82 83 |
# File 'lib/presto/client/statement_client.rb', line 81 def query @query end |
Instance Method Details
#advance ⇒ Object
113 114 115 116 117 118 119 120 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 |
# File 'lib/presto/client/statement_client.rb', line 113 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 = StandardError.new("Error fetching next at #{uri} returned #{response.status}: #{response.body}") # TODO error class raise @exception end attempts += 1 sleep attempts * 0.1 end while (Time.now - start) < 2*60*60 && !@closed @exception = StandardError.new("Error fetching next") # TODO error class raise @exception end |
#close ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/presto/client/statement_client.rb', line 151 def close return if @closed # cancel running statement if uri = @results.next_uri # TODO error handling # TODO make async reqeust and ignore response @faraday.delete do |req| req.url uri end end @closed = true nil end |
#closed? ⇒ Boolean
87 88 89 |
# File 'lib/presto/client/statement_client.rb', line 87 def closed? @closed end |
#current_results ⇒ Object
105 106 107 |
# File 'lib/presto/client/statement_client.rb', line 105 def current_results @results end |
#debug? ⇒ Boolean
83 84 85 |
# File 'lib/presto/client/statement_client.rb', line 83 def debug? @session.debug? end |
#exception? ⇒ Boolean
93 94 95 |
# File 'lib/presto/client/statement_client.rb', line 93 def exception? @exception end |
#has_next? ⇒ Boolean
109 110 111 |
# File 'lib/presto/client/statement_client.rb', line 109 def has_next? !!@results.next_uri end |
#query_failed? ⇒ Boolean
97 98 99 |
# File 'lib/presto/client/statement_client.rb', line 97 def query_failed? @results.error != nil end |
#query_succeeded? ⇒ Boolean
101 102 103 |
# File 'lib/presto/client/statement_client.rb', line 101 def query_succeeded? @results.error == nil && !@exception && !@closed end |