presto-client 0.5.9 → 0.5.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +5 -0
- data/README.md +3 -0
- data/lib/presto/client/faraday_client.rb +24 -1
- data/lib/presto/client/version.rb +1 -1
- data/spec/statement_client_spec.rb +59 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9766f45b1fccb135815e0e24e710a344d3f52758
|
4
|
+
data.tar.gz: 8f08cf0d14c1290665806ff20f72aa0152892897
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b75b118f64cc17d459c6a15954cf785c41f9fe47fa7e3dd31352be4bfbe97b67a8e1564f1d1138d1f3a6743cb9285cea0dc2244c87fae0b8b6f95e3852ae316
|
7
|
+
data.tar.gz: e6237ed2c819394162fd6691e9fcf9e9902db9ea2d173bbecc6352822eaeff70448a998bf06b042c03499c44bd4c5c14f177f97cdeb324594fb6e43d54fc0717
|
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -87,11 +87,14 @@ $ bundle exec rake modelgen:latest
|
|
87
87
|
* **catalog** sets catalog (connector) name of Presto such as `hive-cdh4`, `hive-hadoop1`, etc.
|
88
88
|
* **schema** sets default schema name of Presto. You need to use qualified name like `FROM myschema.table1` to use non-default schemas.
|
89
89
|
* **source** sets source name to connect to a Presto. This name is shown on Presto web interface.
|
90
|
+
* **client_info** sets client info to queries. It can be a string to pass a raw string, or an object that can be encoded to JSON.
|
91
|
+
* **client_tags** sets client tags to queries. It needs to be an array of strings. The tags are shown on web interface.
|
90
92
|
* **user** sets user name to connect to a Presto.
|
91
93
|
* **password** sets a password to connect to Presto using basic auth.
|
92
94
|
* **time_zone** sets time zone of queries. Time zone affects some functions such as `format_datetime`.
|
93
95
|
* **language** sets language of queries. Language affects some functions such as `format_datetime`.
|
94
96
|
* **properties** set session properties. Session properties affect internal behavior such as `hive.force_local_scheduling: true`, `raptor.reader_stream_buffer_size: "32MB"`, etc.
|
97
|
+
* **http_headers** sets custom HTTP headers. It must be a Hash of string to string.
|
95
98
|
* **http_proxy** sets host:port of a HTTP proxy server.
|
96
99
|
* **http_debug** enables debug message to STDOUT for each HTTP requests.
|
97
100
|
* **http_open_timeout** sets timeout in seconds to open new HTTP connection.
|
@@ -23,6 +23,8 @@ module Presto::Client
|
|
23
23
|
PRESTO_TIME_ZONE = "X-Presto-Time-Zone"
|
24
24
|
PRESTO_LANGUAGE = "X-Presto-Language"
|
25
25
|
PRESTO_SESSION = "X-Presto-Session"
|
26
|
+
PRESTO_CLIENT_INFO = "X-Presto-Client-Info";
|
27
|
+
PRESTO_CLIENT_TAGS = "X-Presto-Client-Tags";
|
26
28
|
|
27
29
|
PRESTO_CURRENT_STATE = "X-Presto-Current-State"
|
28
30
|
PRESTO_MAX_WAIT = "X-Presto-Max-Wait"
|
@@ -118,6 +120,12 @@ module Presto::Client
|
|
118
120
|
if v = options[:properties]
|
119
121
|
headers[PrestoHeaders::PRESTO_SESSION] = encode_properties(v)
|
120
122
|
end
|
123
|
+
if v = options[:client_info]
|
124
|
+
headers[PrestoHeaders::PRESTO_CLIENT_INFO] = encode_client_info(v)
|
125
|
+
end
|
126
|
+
if v = options[:client_tags]
|
127
|
+
headers[PrestoHeaders::PRESTO_CLIENT_TAGS] = encode_client_tags(v)
|
128
|
+
end
|
121
129
|
if options[:enable_x_msgpack]
|
122
130
|
# option name is enable_"x"_msgpack because "Accept: application/x-msgpack" header is
|
123
131
|
# not officially supported by Presto. We can use this option only if a proxy server
|
@@ -125,6 +133,9 @@ module Presto::Client
|
|
125
133
|
# name should be enable_msgpack, which might be slightly different behavior.
|
126
134
|
headers['Accept'] = 'application/x-msgpack,application/json'
|
127
135
|
end
|
136
|
+
if v = options[:http_headers]
|
137
|
+
headers.merge!(v)
|
138
|
+
end
|
128
139
|
headers
|
129
140
|
end
|
130
141
|
|
@@ -149,6 +160,18 @@ module Presto::Client
|
|
149
160
|
end.join("\r\n#{PrestoHeaders::PRESTO_SESSION}: ")
|
150
161
|
end
|
151
162
|
|
152
|
-
|
163
|
+
def self.encode_client_info(info)
|
164
|
+
if info.is_a?(String)
|
165
|
+
info
|
166
|
+
else
|
167
|
+
JSON.dump(info)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.encode_client_tags(tags)
|
172
|
+
Array(tags).join(",")
|
173
|
+
end
|
174
|
+
|
175
|
+
private_class_method :faraday_ssl_options, :optional_headers, :encode_properties, :encode_client_info, :encode_client_tags
|
153
176
|
|
154
177
|
end
|
@@ -9,7 +9,6 @@ describe Presto::Client::StatementClient do
|
|
9
9
|
schema: "default",
|
10
10
|
time_zone: "US/Pacific",
|
11
11
|
language: "ja_JP",
|
12
|
-
properties: {"hello" => "world", "name"=>"value"},
|
13
12
|
debug: true,
|
14
13
|
}
|
15
14
|
end
|
@@ -39,7 +38,6 @@ describe Presto::Client::StatementClient do
|
|
39
38
|
"X-Presto-User" => options[:user],
|
40
39
|
"X-Presto-Language" => options[:language],
|
41
40
|
"X-Presto-Time-Zone" => options[:time_zone],
|
42
|
-
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
|
43
41
|
}).to_return(body: response_json.to_json)
|
44
42
|
|
45
43
|
StatementClient.new(faraday, query, options)
|
@@ -64,7 +62,6 @@ describe Presto::Client::StatementClient do
|
|
64
62
|
"X-Presto-User" => options[:user],
|
65
63
|
"X-Presto-Language" => options[:language],
|
66
64
|
"X-Presto-Time-Zone" => options[:time_zone],
|
67
|
-
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
|
68
65
|
}).to_return(body: response_json2.to_json)
|
69
66
|
|
70
67
|
stub_request(:get, "localhost/v1/next_uri").
|
@@ -75,7 +72,6 @@ describe Presto::Client::StatementClient do
|
|
75
72
|
"X-Presto-User" => options[:user],
|
76
73
|
"X-Presto-Language" => options[:language],
|
77
74
|
"X-Presto-Time-Zone" => options[:time_zone],
|
78
|
-
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
|
79
75
|
}).to_return(body: lambda{|req|if retry_p; response_json.to_json; else; retry_p=true; raise Timeout::Error.new("execution expired"); end })
|
80
76
|
|
81
77
|
sc = StatementClient.new(faraday, query, options.merge(http_open_timeout: 1))
|
@@ -95,7 +91,6 @@ describe Presto::Client::StatementClient do
|
|
95
91
|
"X-Presto-User" => options[:user],
|
96
92
|
"X-Presto-Language" => options[:language],
|
97
93
|
"X-Presto-Time-Zone" => options[:time_zone],
|
98
|
-
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: "),
|
99
94
|
"Accept" => "application/x-msgpack,application/json"
|
100
95
|
}).to_return(body: MessagePack.dump(response_json2), headers: {"Content-Type" => "application/x-msgpack"})
|
101
96
|
|
@@ -107,7 +102,6 @@ describe Presto::Client::StatementClient do
|
|
107
102
|
"X-Presto-User" => options[:user],
|
108
103
|
"X-Presto-Language" => options[:language],
|
109
104
|
"X-Presto-Time-Zone" => options[:time_zone],
|
110
|
-
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: "),
|
111
105
|
"Accept" => "application/x-msgpack,application/json"
|
112
106
|
}).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"})
|
113
107
|
|
@@ -147,7 +141,6 @@ describe Presto::Client::StatementClient do
|
|
147
141
|
"X-Presto-User" => options[:user],
|
148
142
|
"X-Presto-Language" => options[:language],
|
149
143
|
"X-Presto-Time-Zone" => options[:time_zone],
|
150
|
-
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
|
151
144
|
}
|
152
145
|
|
153
146
|
stub_request(:post, "http://localhost/v1/statement").
|
@@ -179,13 +172,71 @@ describe Presto::Client::StatementClient do
|
|
179
172
|
"X-Presto-User" => options[:user],
|
180
173
|
"X-Presto-Language" => options[:language],
|
181
174
|
"X-Presto-Time-Zone" => options[:time_zone],
|
182
|
-
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: "),
|
183
175
|
}).to_return(body: {}.to_json)
|
184
176
|
|
185
177
|
Presto::Client.new(options).kill(query_id)
|
186
178
|
end
|
187
179
|
end
|
188
180
|
|
181
|
+
describe 'advanced HTTP headers' do
|
182
|
+
let(:headers) do
|
183
|
+
{
|
184
|
+
"User-Agent" => "presto-ruby/#{VERSION}",
|
185
|
+
"X-Presto-Catalog" => options[:catalog],
|
186
|
+
"X-Presto-Schema" => options[:schema],
|
187
|
+
"X-Presto-User" => options[:user],
|
188
|
+
"X-Presto-Language" => options[:language],
|
189
|
+
"X-Presto-Time-Zone" => options[:time_zone],
|
190
|
+
}
|
191
|
+
end
|
192
|
+
|
193
|
+
it "sets X-Presto-Session from properties" do
|
194
|
+
options[:properties] = {"hello" => "world", "name"=>"value"}
|
195
|
+
|
196
|
+
stub_request(:post, "localhost/v1/statement").
|
197
|
+
with(body: query,
|
198
|
+
headers: headers.merge({
|
199
|
+
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
|
200
|
+
})).
|
201
|
+
to_return(body: response_json.to_json)
|
202
|
+
|
203
|
+
StatementClient.new(faraday, query, options)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "sets X-Presto-Client-Info from client_info" do
|
207
|
+
options[:client_info] = "raw"
|
208
|
+
|
209
|
+
stub_request(:post, "localhost/v1/statement").
|
210
|
+
with(body: query,
|
211
|
+
headers: headers.merge("X-Presto-Client-Info" => "raw")).
|
212
|
+
to_return(body: response_json.to_json)
|
213
|
+
|
214
|
+
StatementClient.new(faraday, query, options)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "sets X-Presto-Client-Info in JSON from client_info" do
|
218
|
+
options[:client_info] = {"k1" => "v1", "k2" => "v2"}
|
219
|
+
|
220
|
+
stub_request(:post, "localhost/v1/statement").
|
221
|
+
with(body: query,
|
222
|
+
headers: headers.merge("X-Presto-Client-Info" => '{"k1":"v1","k2":"v2"}')).
|
223
|
+
to_return(body: response_json.to_json)
|
224
|
+
|
225
|
+
StatementClient.new(faraday, query, options)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "sets X-Presto-Client-Tags" do
|
229
|
+
options[:client_tags] = ["k1:v1", "k2:v2"]
|
230
|
+
|
231
|
+
stub_request(:post, "localhost/v1/statement").
|
232
|
+
with(body: query,
|
233
|
+
headers: headers.merge("X-Presto-Client-Tags" => "k1:v1,k2:v2")).
|
234
|
+
to_return(body: response_json.to_json)
|
235
|
+
|
236
|
+
StatementClient.new(faraday, query, options)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
189
240
|
describe 'HTTP basic auth' do
|
190
241
|
let(:password) { 'abcd' }
|
191
242
|
|
@@ -199,7 +250,6 @@ describe Presto::Client::StatementClient do
|
|
199
250
|
"X-Presto-User" => options[:user],
|
200
251
|
"X-Presto-Language" => options[:language],
|
201
252
|
"X-Presto-Time-Zone" => options[:time_zone],
|
202
|
-
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
|
203
253
|
},
|
204
254
|
basic_auth: [options[:user], password]
|
205
255
|
).to_return(body: response_json.to_json)
|
@@ -336,7 +386,6 @@ describe Presto::Client::StatementClient do
|
|
336
386
|
"X-Presto-User" => options[:user],
|
337
387
|
"X-Presto-Language" => options[:language],
|
338
388
|
"X-Presto-Time-Zone" => options[:time_zone],
|
339
|
-
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
|
340
389
|
}).to_return(body: nested_json.to_json(:max_nesting => false))
|
341
390
|
|
342
391
|
StatementClient.new(faraday, query, options)
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.6.
|
172
|
+
rubygems_version: 2.6.13
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: Presto client library
|