Skip to content

Commit

Permalink
Implement StatementClient#query_id
Browse files Browse the repository at this point in the history
We need to know presto query id to kill the query then
providing `StatementClient#query_id` as shorthand of
`@results.id` will be useful.
  • Loading branch information
yui-knk committed Jan 22, 2020
1 parent 8450627 commit 2b692ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/presto/client/statement_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def current_results_headers
@results_headers
end

def query_id
@results.id
end

def has_next?
!!@results.next_uri
end
Expand Down
16 changes: 16 additions & 0 deletions spec/statement_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@
q.current_results_headers["X-Test-Header"].should == "123"
end

describe "#query_id" do
it "returns query_id" do
stub_request(:post, "localhost/v1/statement").
with(body: query).to_return(body: response_json2.to_json, headers: {"X-Test-Header" => "123"})

stub_request(:get, "localhost/v1/next_uri").
to_return(body: response_json.to_json, headers: {"X-Test-Header" => "123"})

sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1))
sc.query_id.should == "queryid"
sc.has_next?.should be_true
sc.advance.should be_true
sc.query_id.should == "queryid"
end
end

describe '#query_info' do
let :headers do
{
Expand Down

0 comments on commit 2b692ca

Please sign in to comment.