presto-client 0.5.6 → 0.5.7
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 +5 -0
- data/README.md +2 -0
- data/lib/presto/client/query.rb +9 -0
- data/lib/presto/client/statement_client.rb +9 -4
- data/lib/presto/client/version.rb +1 -1
- data/presto-client.gemspec +2 -3
- data/spec/statement_client_spec.rb +62 -0
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c323f1555c8b8911022378e1b6b5c3ab32ea198
|
4
|
+
data.tar.gz: dad8f48273aa312ff3c89809698f6bf4955d54b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ef2fa5dd5e59a1d5a68f064bf3af0cabbae98b72ab9c64764297491c60de03f5ce7a7f00b527f5763b8eb92bdf2f5ffe2a9c01c4dc57a1da17b0f6c773d6368
|
7
|
+
data.tar.gz: fe6c1fc26dff277531c8334b6feaf299b66f4cebdfc9b752ceda5e26c5edd3a4b95888c0b4292f22d526a364f61c1f1bcfb18f55c28e82b78e1bae32d9f2c35e
|
data/ChangeLog
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
2017-08-28 version 0.5.7
|
2
|
+
* Support a password option with HTTP basic auth
|
3
|
+
* Changed retry timeout from hard coded 2h to configurable default 2min
|
4
|
+
* Fix too deep nested json failure
|
5
|
+
|
1
6
|
2017-07-03 version 0.5.6:
|
2
7
|
* Added missing inner class models for version 0.178
|
3
8
|
|
data/README.md
CHANGED
@@ -19,6 +19,7 @@ client = Presto::Client.new(
|
|
19
19
|
catalog: "native",
|
20
20
|
schema: "default",
|
21
21
|
user: "frsyuki",
|
22
|
+
password: "********",
|
22
23
|
time_zone: "US/Pacific",
|
23
24
|
language: "English",
|
24
25
|
properties: {
|
@@ -81,6 +82,7 @@ $ bundle exec rake modelgen:latest
|
|
81
82
|
* **schema** sets default schema name of Presto. You need to use qualified name like `FROM myschema.table1` to use non-default schemas.
|
82
83
|
* **source** sets source name to connect to a Presto. This name is shown on Presto web interface.
|
83
84
|
* **user** sets user name to connect to a Presto.
|
85
|
+
* **password** sets a password to connect to Presto using basic auth.
|
84
86
|
* **time_zone** sets time zone of queries. Time zone affects some functions such as `format_datetime`.
|
85
87
|
* **language** sets language of queries. Language affects some functions such as `format_datetime`.
|
86
88
|
* **properties** set session properties. Session properties affect internal behavior such as `hive.force_local_scheduling: true`, `raptor.reader_stream_buffer_size: "32MB"`, etc.
|
data/lib/presto/client/query.rb
CHANGED
@@ -37,6 +37,10 @@ module Presto::Client
|
|
37
37
|
|
38
38
|
ssl = faraday_ssl_options(options)
|
39
39
|
|
40
|
+
if options[:password] && !ssl
|
41
|
+
raise ArgumentError, "Protocol must be https when passing a password"
|
42
|
+
end
|
43
|
+
|
40
44
|
url = "#{ssl ? "https" : "http"}://#{server}"
|
41
45
|
proxy = options[:http_proxy] || options[:proxy] # :proxy is obsoleted
|
42
46
|
|
@@ -45,6 +49,11 @@ module Presto::Client
|
|
45
49
|
|
46
50
|
faraday = Faraday.new(faraday_options) do |faraday|
|
47
51
|
#faraday.request :url_encoded
|
52
|
+
|
53
|
+
if options[:user] && options[:password]
|
54
|
+
faraday.basic_auth(options[:user], options[:password])
|
55
|
+
end
|
56
|
+
|
48
57
|
faraday.response :logger if options[:http_debug]
|
49
58
|
faraday.adapter Faraday.default_adapter
|
50
59
|
end
|
@@ -15,7 +15,7 @@
|
|
15
15
|
#
|
16
16
|
module Presto::Client
|
17
17
|
|
18
|
-
require '
|
18
|
+
require 'json'
|
19
19
|
require 'msgpack'
|
20
20
|
require 'presto/client/models'
|
21
21
|
require 'presto/client/errors'
|
@@ -40,6 +40,11 @@ module Presto::Client
|
|
40
40
|
"User-Agent" => "presto-ruby/#{VERSION}",
|
41
41
|
}
|
42
42
|
|
43
|
+
# Presto can return too deep nested JSON
|
44
|
+
JSON_OPTIONS = {
|
45
|
+
:max_nesting => false
|
46
|
+
}
|
47
|
+
|
43
48
|
def initialize(faraday, query, options, next_uri=nil)
|
44
49
|
@faraday = faraday
|
45
50
|
@faraday.headers.merge!(HEADERS)
|
@@ -48,7 +53,7 @@ module Presto::Client
|
|
48
53
|
@query = query
|
49
54
|
@closed = false
|
50
55
|
@exception = nil
|
51
|
-
|
56
|
+
@retry_timeout = options[:retry_timeout] || 120
|
52
57
|
if model_version = @options[:model_version]
|
53
58
|
@models = ModelVersions.const_get("V#{model_version.gsub(".", "_")}")
|
54
59
|
else
|
@@ -195,7 +200,7 @@ module Presto::Client
|
|
195
200
|
when 'application/x-msgpack'
|
196
201
|
MessagePack.load(response.body)
|
197
202
|
else
|
198
|
-
|
203
|
+
JSON.parse(response.body, opts = JSON_OPTIONS)
|
199
204
|
end
|
200
205
|
end
|
201
206
|
|
@@ -230,7 +235,7 @@ module Presto::Client
|
|
230
235
|
|
231
236
|
attempts += 1
|
232
237
|
sleep attempts * 0.1
|
233
|
-
end while (Time.now - start) <
|
238
|
+
end while (Time.now - start) < @retry_timeout && !@closed
|
234
239
|
|
235
240
|
@exception = PrestoHttpError.new(408, "Presto API error due to timeout")
|
236
241
|
raise @exception
|
data/presto-client.gemspec
CHANGED
@@ -20,12 +20,11 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.required_ruby_version = ">= 1.9.1"
|
21
21
|
|
22
22
|
gem.add_dependency "faraday", ["~> 0.12"]
|
23
|
-
|
24
|
-
gem.add_dependency "msgpack", [">= 0.7.0"]
|
23
|
+
gem.add_dependency "msgpack", [">= 0.7.0"]
|
25
24
|
|
26
25
|
gem.add_development_dependency "rake", [">= 0.9.2", "< 11.0"]
|
27
26
|
gem.add_development_dependency "rspec", ["~> 2.13.0"]
|
28
|
-
gem.add_development_dependency "webmock", ["~>
|
27
|
+
gem.add_development_dependency "webmock", ["~> 2.0.0"]
|
29
28
|
gem.add_development_dependency "addressable", ["~> 2.4.0"] # 2.5.0 doesn't support Ruby 1.9.3
|
30
29
|
gem.add_development_dependency "simplecov", ["~> 0.10.0"]
|
31
30
|
end
|
@@ -136,6 +136,38 @@ describe Presto::Client::StatementClient do
|
|
136
136
|
end.should raise_error(TypeError, /String to Hash/)
|
137
137
|
end
|
138
138
|
|
139
|
+
describe 'HTTP basic auth' do
|
140
|
+
let(:password) { 'abcd' }
|
141
|
+
|
142
|
+
it "adds basic auth headers when ssl is enabled and a password is given" do
|
143
|
+
stub_request(:post, "https://localhost/v1/statement").
|
144
|
+
with(body: query,
|
145
|
+
headers: {
|
146
|
+
"User-Agent" => "presto-ruby/#{VERSION}",
|
147
|
+
"X-Presto-Catalog" => options[:catalog],
|
148
|
+
"X-Presto-Schema" => options[:schema],
|
149
|
+
"X-Presto-User" => options[:user],
|
150
|
+
"X-Presto-Language" => options[:language],
|
151
|
+
"X-Presto-Time-Zone" => options[:time_zone],
|
152
|
+
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
|
153
|
+
},
|
154
|
+
basic_auth: [options[:user], password]
|
155
|
+
).to_return(body: response_json.to_json)
|
156
|
+
|
157
|
+
faraday = Query.__send__(:faraday_client, options.merge(ssl: { verify: true }, password: password))
|
158
|
+
StatementClient.new(faraday, query, options)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "forbids using basic auth when ssl is disabled" do
|
162
|
+
lambda do
|
163
|
+
Query.__send__(:faraday_client, {
|
164
|
+
server: 'localhost',
|
165
|
+
password: 'abcd'
|
166
|
+
})
|
167
|
+
end.should raise_error(ArgumentError)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
139
171
|
describe "ssl" do
|
140
172
|
it "is disabled by default" do
|
141
173
|
f = Query.__send__(:faraday_client, {
|
@@ -230,5 +262,35 @@ describe Presto::Client::StatementClient do
|
|
230
262
|
StatementClient.new(faraday, query, options.merge(model_version: "0.111"))
|
231
263
|
end.should raise_error(NameError)
|
232
264
|
end
|
265
|
+
|
266
|
+
|
267
|
+
let :nested_json do
|
268
|
+
nested_stats = {createTime: Time.now}
|
269
|
+
# JSON max nesting default value is 100
|
270
|
+
for i in 0..100 do
|
271
|
+
nested_stats = {stats: nested_stats}
|
272
|
+
end
|
273
|
+
{
|
274
|
+
id: "queryid",
|
275
|
+
stats: nested_stats
|
276
|
+
}
|
277
|
+
end
|
278
|
+
|
279
|
+
it "parse nested json properly" do
|
280
|
+
stub_request(:post, "localhost/v1/statement").
|
281
|
+
with(body: query,
|
282
|
+
headers: {
|
283
|
+
"User-Agent" => "presto-ruby/#{VERSION}",
|
284
|
+
"X-Presto-Catalog" => options[:catalog],
|
285
|
+
"X-Presto-Schema" => options[:schema],
|
286
|
+
"X-Presto-User" => options[:user],
|
287
|
+
"X-Presto-Language" => options[:language],
|
288
|
+
"X-Presto-Time-Zone" => options[:time_zone],
|
289
|
+
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
|
290
|
+
}).to_return(body: nested_json.to_json(:max_nesting => false))
|
291
|
+
|
292
|
+
faraday = Faraday.new(url: "http://localhost")
|
293
|
+
StatementClient.new(faraday, query, options)
|
294
|
+
end
|
233
295
|
end
|
234
296
|
|
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.7
|
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-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.12'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: multi_json
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: msgpack
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,14 +78,14 @@ dependencies:
|
|
92
78
|
requirements:
|
93
79
|
- - "~>"
|
94
80
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
81
|
+
version: 2.0.0
|
96
82
|
type: :development
|
97
83
|
prerelease: false
|
98
84
|
version_requirements: !ruby/object:Gem::Requirement
|
99
85
|
requirements:
|
100
86
|
- - "~>"
|
101
87
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
88
|
+
version: 2.0.0
|
103
89
|
- !ruby/object:Gem::Dependency
|
104
90
|
name: addressable
|
105
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
168
|
version: '0'
|
183
169
|
requirements: []
|
184
170
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.6.
|
171
|
+
rubygems_version: 2.6.11
|
186
172
|
signing_key:
|
187
173
|
specification_version: 4
|
188
174
|
summary: Presto client library
|