presto-client 0.4.1 → 0.4.2
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 +8 -8
- data/ChangeLog +6 -0
- data/README.md +3 -0
- data/lib/presto/client/statement_client.rb +25 -0
- data/lib/presto/client/version.rb +1 -1
- data/spec/statement_client_spec.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGU1Zjc0ZTVmNmY0ZGM3YzcyMjgyY2RkNDJhOWFmODhkMWY4ZTI5Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTY1NDcwYTM5ODMxY2M5OWE2ZDRkZjEzOWIxMGIxOGVjZTY0YzQ3NQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTBjYmQ4OWJjOTk1MTcyZDY2OWRlMzJmNWU1ZTM1NDlhM2QyYTczNThlNDdi
|
10
|
+
OWQxMjYzMDVmYjlkNjE5ZDEwNzU2NDhiN2I2ZDJjNTE2MTgzYjcxYTljMTY2
|
11
|
+
NDE3YjI1Zjk5YmRjYjdjNDI1NDlmMzFiYzlkZWY1NDE5YTdkMzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWVlY2QwMmNiNWZhNWM1NmFhZDU5NzcwMGM0ODZlYzA4YTA2Y2I2ODg1YTUz
|
14
|
+
NjE0NjIyNjg1NzVkYmQ2ZGZkNTY4ODE4MGUxYjk1ZGEyNThiZWRkZTM2ZmQz
|
15
|
+
YWUwZjY5OWVmZDM2ZjUwYzMyYjQyYTkwZjk1OWZhN2U5Nzk4N2M=
|
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -16,6 +16,9 @@ client = Presto::Client.new(
|
|
16
16
|
catalog: "native",
|
17
17
|
schema: "default",
|
18
18
|
user: "frsyuki",
|
19
|
+
time_zone: "US/Pacific", # optional
|
20
|
+
language: "en_us", # optional
|
21
|
+
properties: {"hello" => "world", "mycatalog.hello" => "world"}, # optional
|
19
22
|
http_debug: true,
|
20
23
|
)
|
21
24
|
|
@@ -26,6 +26,7 @@ module Presto::Client
|
|
26
26
|
PRESTO_SCHEMA = "X-Presto-Schema"
|
27
27
|
PRESTO_TIME_ZONE = "X-Presto-Time-Zone"
|
28
28
|
PRESTO_LANGUAGE = "X-Presto-Language"
|
29
|
+
PRESTO_SESSION = "X-Presto-Session"
|
29
30
|
|
30
31
|
PRESTO_CURRENT_STATE = "X-Presto-Current-State"
|
31
32
|
PRESTO_MAX_WAIT = "X-Presto-Max-Wait"
|
@@ -78,6 +79,9 @@ module Presto::Client
|
|
78
79
|
if v = @options[:language]
|
79
80
|
req.headers[PrestoHeaders::PRESTO_LANGUAGE] = v
|
80
81
|
end
|
82
|
+
if v = @options[:properties]
|
83
|
+
req.headers[PrestoHeaders::PRESTO_SESSION] = encode_properties(v)
|
84
|
+
end
|
81
85
|
|
82
86
|
req.body = @query
|
83
87
|
end
|
@@ -183,6 +187,27 @@ module Presto::Client
|
|
183
187
|
return false
|
184
188
|
end
|
185
189
|
|
190
|
+
HTTP11_SEPARATOR = ["(", ")", "<", ">", "@", ",", ";", ":", "\\", "<", ">", "/", "[", "]", "?", "=", "{", "}", " ", "\v"]
|
191
|
+
HTTP11_TOKEN_CHARSET = (32..126).map {|x| x.chr } - HTTP11_SEPARATOR
|
192
|
+
HTTP11_TOKEN_REGEXP = /^[#{Regexp.escape(HTTP11_TOKEN_CHARSET.join)}]+\z/
|
193
|
+
HTTP11_CTL_CHARSET = (0..31).map {|x| x.chr } + [127.chr]
|
194
|
+
HTTP11_CTL_CHARSET_REGEXP = /[#{Regexp.escape(HTTP11_CTL_CHARSET.join)}]/
|
195
|
+
|
196
|
+
def encode_properties(properties)
|
197
|
+
# this is a hack to set same header multiple times.
|
198
|
+
properties.map do |k, v|
|
199
|
+
token = k.to_s
|
200
|
+
field_value = v.to_s # TODO LWS encoding is not implemented
|
201
|
+
unless k =~ HTTP11_TOKEN_REGEXP
|
202
|
+
raise Faraday::ClientError, "Key of properties can't include HTTP/1.1 control characters or separators (#{HTTP11_SEPARATOR.map {|c| c =~ /\s/ ? c.dump : c }.join(' ')})"
|
203
|
+
end
|
204
|
+
if field_value =~ HTTP11_CTL_CHARSET_REGEXP
|
205
|
+
raise Faraday::ClientError, "Value of properties can't include HTTP/1.1 control characters"
|
206
|
+
end
|
207
|
+
"#{token}=#{field_value}"
|
208
|
+
end.join("\r\n#{PrestoHeaders::PRESTO_SESSION}: ")
|
209
|
+
end
|
210
|
+
|
186
211
|
def close
|
187
212
|
return if @closed
|
188
213
|
|
@@ -9,6 +9,7 @@ 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"},
|
12
13
|
debug: true,
|
13
14
|
}
|
14
15
|
end
|
@@ -34,6 +35,7 @@ describe Presto::Client::StatementClient do
|
|
34
35
|
"X-Presto-User" => options[:user],
|
35
36
|
"X-Presto-Language" => options[:language],
|
36
37
|
"X-Presto-Time-Zone" => options[:time_zone],
|
38
|
+
"X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
|
37
39
|
}).to_return(body: response_json.to_json)
|
38
40
|
|
39
41
|
faraday = Faraday.new(url: "http://localhost")
|
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.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|