presto-client 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +35 -0
- data/README.md +10 -0
- data/lib/presto/client/query.rb +0 -1
- data/lib/presto/client/statement_client.rb +30 -13
- data/lib/presto/client/version.rb +1 -1
- data/presto-client.gemspec +1 -0
- data/spec/statement_client_spec.rb +34 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc11fc0cab121eb735018084081c77fa034847f6
|
4
|
+
data.tar.gz: 19812b673f76893200f7b691444176a06b995bf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4494d03f05cf329625eeeaca2762e8ce2bd75a3d1689ad0e7a7714f63d9efb9525f41cf42a18d66e15cdde4a798fb8b97ac55fe028c86b2f307959da8f794855
|
7
|
+
data.tar.gz: 9f069548587f6bb5a8beae83a654afae3ad97f91616be7fda724e5379d42ebde8e38a4574c743e2ef1f224e32cbffc9414a916ec9b1c1affa9757f65532f2b2f
|
data/ChangeLog
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
+
2017-05-15 version 0.5.4:
|
2
|
+
|
3
|
+
* Support "Content-Type: application/x-msgpack" for more efficient parsing of
|
4
|
+
HTTP response body.
|
5
|
+
* Added "enable_x_msgpack: true" option to send Accept header with
|
6
|
+
application/x-msgpack.
|
7
|
+
|
8
|
+
|
9
|
+
2017-04-26 version 0.5.3:
|
10
|
+
|
11
|
+
* Added support for model version 0.173.
|
12
|
+
* Changed the default latest model version to 0.173.
|
13
|
+
* Fixed compatibility with the new major version of Farady
|
14
|
+
* Require Faraday 0.12 or later
|
15
|
+
|
16
|
+
|
17
|
+
2017-02-01 version 0.5.2:
|
18
|
+
|
19
|
+
* Relax dependent version of Faraday to be able to use all 0.x versions.
|
20
|
+
* Fix build script that was broken due to new major version of rake.
|
21
|
+
|
22
|
+
|
23
|
+
2016-11-01 version 0.5.1:
|
24
|
+
|
25
|
+
* Assume ConnectorId as a primitive type to be able to decode "connectorId"
|
26
|
+
fields.
|
27
|
+
|
28
|
+
|
29
|
+
2016-10-28 version 0.5.0:
|
30
|
+
|
31
|
+
* Support multiple model versions
|
32
|
+
* Added support for model version 0.153.
|
33
|
+
* Changed the default latest model version to 0.513.
|
34
|
+
|
35
|
+
|
1
36
|
2016-08-09 version 0.4.17:
|
2
37
|
|
3
38
|
* Added support for :ssl option.
|
data/README.md
CHANGED
@@ -92,3 +92,13 @@ $ bundle exec rake modelgen:latest
|
|
92
92
|
|
93
93
|
See [RDoc](http://www.rubydoc.info/gems/presto-client/) for the full documentation.
|
94
94
|
|
95
|
+
## Development
|
96
|
+
|
97
|
+
### Releasing a new version
|
98
|
+
|
99
|
+
1. Update lib/presto/client/version.rb
|
100
|
+
2. Update ChangeLog
|
101
|
+
3. git commit -am "vX.Y.Z"
|
102
|
+
4. git tag "vX.Y.Z"
|
103
|
+
5. git push --tags
|
104
|
+
|
data/lib/presto/client/query.rb
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
module Presto::Client
|
17
17
|
|
18
18
|
require 'multi_json'
|
19
|
+
require 'msgpack'
|
19
20
|
require 'presto/client/models'
|
20
21
|
require 'presto/client/errors'
|
21
22
|
|
@@ -57,8 +58,8 @@ module Presto::Client
|
|
57
58
|
@faraday.headers.merge!(optional_headers)
|
58
59
|
|
59
60
|
if next_uri
|
60
|
-
|
61
|
-
@results = @models::QueryResults.decode(
|
61
|
+
response = faraday_get_with_retry(next_uri)
|
62
|
+
@results = @models::QueryResults.decode(parse_body(response))
|
62
63
|
else
|
63
64
|
post_query_request!
|
64
65
|
end
|
@@ -87,6 +88,13 @@ module Presto::Client
|
|
87
88
|
if v = @options[:properties]
|
88
89
|
headers[PrestoHeaders::PRESTO_SESSION] = encode_properties(v)
|
89
90
|
end
|
91
|
+
if @options[:enable_x_msgpack]
|
92
|
+
# option name is enable_"x"_msgpack because "Accept: application/x-msgpack" header is
|
93
|
+
# not officially supported by Presto. We can use this option only if a proxy server
|
94
|
+
# decodes & encodes response body. Once this option is supported by Presto, option
|
95
|
+
# name should be enable_msgpack, which might be slightly different behavior.
|
96
|
+
headers['Accept'] = 'application/x-msgpack,application/json'
|
97
|
+
end
|
90
98
|
headers
|
91
99
|
end
|
92
100
|
|
@@ -110,11 +118,10 @@ module Presto::Client
|
|
110
118
|
|
111
119
|
# TODO error handling
|
112
120
|
if response.status != 200
|
113
|
-
raise PrestoHttpError.new(response.status, "Failed to start query: #{response.body}")
|
121
|
+
raise PrestoHttpError.new(response.status, "Failed to start query: #{response.body} (#{response.status})")
|
114
122
|
end
|
115
123
|
|
116
|
-
|
117
|
-
@results = load_json(uri, body, @models::QueryResults)
|
124
|
+
@results = decode_model(uri, parse_body(response), @models::QueryResults)
|
118
125
|
end
|
119
126
|
|
120
127
|
private :post_query_request!
|
@@ -157,20 +164,19 @@ module Presto::Client
|
|
157
164
|
end
|
158
165
|
uri = @results.next_uri
|
159
166
|
|
160
|
-
|
161
|
-
@results =
|
167
|
+
response = faraday_get_with_retry(uri)
|
168
|
+
@results = decode_model(uri, parse_body(response), @models::QueryResults)
|
162
169
|
|
163
170
|
return true
|
164
171
|
end
|
165
172
|
|
166
173
|
def query_info
|
167
174
|
uri = "/v1/query/#{@results.id}"
|
168
|
-
|
169
|
-
|
175
|
+
response = faraday_get_with_retry(uri)
|
176
|
+
decode_model(uri, parse_body(response), @models::QueryInfo)
|
170
177
|
end
|
171
178
|
|
172
|
-
def
|
173
|
-
hash = MultiJson.load(body)
|
179
|
+
def decode_model(uri, hash, body_class)
|
174
180
|
begin
|
175
181
|
body_class.decode(hash)
|
176
182
|
rescue => e
|
@@ -182,7 +188,18 @@ module Presto::Client
|
|
182
188
|
end
|
183
189
|
end
|
184
190
|
|
185
|
-
private :
|
191
|
+
private :decode_model
|
192
|
+
|
193
|
+
def parse_body(response)
|
194
|
+
case response.headers['Content-Type']
|
195
|
+
when 'application/x-msgpack'
|
196
|
+
MessagePack.load(response.body)
|
197
|
+
else
|
198
|
+
MultiJson.load(response.body)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
private :parse_body
|
186
203
|
|
187
204
|
def faraday_get_with_retry(uri, &block)
|
188
205
|
start = Time.now
|
@@ -201,7 +218,7 @@ module Presto::Client
|
|
201
218
|
|
202
219
|
if response
|
203
220
|
if response.status == 200 && !response.body.to_s.empty?
|
204
|
-
return response
|
221
|
+
return response
|
205
222
|
end
|
206
223
|
|
207
224
|
if response.status != 503 # retry only if 503 Service Unavailable
|
data/presto-client.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
|
22
22
|
gem.add_dependency "faraday", ["~> 0.12"]
|
23
23
|
gem.add_dependency "multi_json", ["~> 1.0"]
|
24
|
+
gem.add_dependency "msgpack", [">= 0.7.0"]
|
24
25
|
|
25
26
|
gem.add_development_dependency "rake", [">= 0.9.2", "< 11.0"]
|
26
27
|
gem.add_development_dependency "rspec", ["~> 2.13.0"]
|
@@ -82,6 +82,40 @@ describe Presto::Client::StatementClient do
|
|
82
82
|
retry_p.should be_true
|
83
83
|
end
|
84
84
|
|
85
|
+
it "uses 'Accept: application/x-msgpack' if option is set" do
|
86
|
+
retry_p = false
|
87
|
+
stub_request(:post, "localhost/v1/statement").
|
88
|
+
with(body: query,
|
89
|
+
headers: {
|
90
|
+
"User-Agent" => "presto-ruby/#{VERSION}",
|
91
|
+
"X-Presto-Catalog" => options[:catalog],
|
92
|
+
"X-Presto-Schema" => options[:schema],
|
93
|
+
"X-Presto-User" => options[:user],
|
94
|
+
"X-Presto-Language" => options[:language],
|
95
|
+
"X-Presto-Time-Zone" => options[:time_zone],
|
96
|
+
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: "),
|
97
|
+
"Accept" => "application/x-msgpack,application/json"
|
98
|
+
}).to_return(body: MessagePack.dump(response_json2), headers: {"Content-Type" => "application/x-msgpack"})
|
99
|
+
|
100
|
+
stub_request(:get, "localhost/v1/next_uri").
|
101
|
+
with(headers: {
|
102
|
+
"User-Agent" => "presto-ruby/#{VERSION}",
|
103
|
+
"X-Presto-Catalog" => options[:catalog],
|
104
|
+
"X-Presto-Schema" => options[:schema],
|
105
|
+
"X-Presto-User" => options[:user],
|
106
|
+
"X-Presto-Language" => options[:language],
|
107
|
+
"X-Presto-Time-Zone" => options[:time_zone],
|
108
|
+
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: "),
|
109
|
+
"Accept" => "application/x-msgpack,application/json"
|
110
|
+
}).to_return(body: lambda{|req|if retry_p; MessagePack.dump(response_json); else; retry_p=true; raise Timeout::Error.new("execution expired"); end }, headers: {"Content-Type" => "application/x-msgpack"})
|
111
|
+
|
112
|
+
faraday = Faraday.new(url: "http://localhost")
|
113
|
+
sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1, enable_x_msgpack: "application/x-msgpack"))
|
114
|
+
sc.has_next?.should be_true
|
115
|
+
sc.advance.should be_true
|
116
|
+
retry_p.should be_true
|
117
|
+
end
|
118
|
+
|
85
119
|
it "decodes DeleteHandle" do
|
86
120
|
dh = Models::DeleteHandle.decode({
|
87
121
|
"handle" => {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: presto-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: msgpack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.7.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
181
|
version: '0'
|
168
182
|
requirements: []
|
169
183
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.6.8
|
171
185
|
signing_key:
|
172
186
|
specification_version: 4
|
173
187
|
summary: Presto client library
|