presto-client 0.5.10 → 0.5.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9766f45b1fccb135815e0e24e710a344d3f52758
4
- data.tar.gz: 8f08cf0d14c1290665806ff20f72aa0152892897
2
+ SHA256:
3
+ metadata.gz: 8057cfffdbe9a99760500827e16e2acfa2226c8fe70c7a20ce3fe4708ed80c02
4
+ data.tar.gz: 7655979e2fc05d9805c0ea704fba1b37c029a5051c2d4eb3a5d5f2d0d1f392ce
5
5
  SHA512:
6
- metadata.gz: 1b75b118f64cc17d459c6a15954cf785c41f9fe47fa7e3dd31352be4bfbe97b67a8e1564f1d1138d1f3a6743cb9285cea0dc2244c87fae0b8b6f95e3852ae316
7
- data.tar.gz: e6237ed2c819394162fd6691e9fcf9e9902db9ea2d173bbecc6352822eaeff70448a998bf06b042c03499c44bd4c5c14f177f97cdeb324594fb6e43d54fc0717
6
+ metadata.gz: 554e580324ff6bcf0cb0a5d38360147ac731e1abe0a93390ce3a8a8c2de6683d6e0365ec14022d6a888e44abcafb7eb4756a8a7bf2f45f0f9baf62c6c7bbf616
7
+ data.tar.gz: 5b647ad42f45cbb703c6d4ac5dc7ae0bc7ba6f6f36eea5826d7659b7fb704cee11dc562f3fb1eed47b0f4ce3a1a586b8ee7ddd43ae979b259b7ee9d3829af9de
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 2018-06-27 version 0.5.11
2
+
3
+ * Support multiple session properties
4
+ * Check invalid JSON data response
5
+
1
6
  2018-03-22 version 0.5.10
2
7
 
3
8
  * Added client_info, client_tags, and http_headers options.
@@ -146,7 +146,6 @@ module Presto::Client
146
146
  HTTP11_CTL_CHARSET_REGEXP = /[#{Regexp.escape(HTTP11_CTL_CHARSET.join)}]/
147
147
 
148
148
  def self.encode_properties(properties)
149
- # this is a hack to set same header multiple times.
150
149
  properties.map do |k, v|
151
150
  token = k.to_s
152
151
  field_value = v.to_s # TODO LWS encoding is not implemented
@@ -157,7 +156,7 @@ module Presto::Client
157
156
  raise Faraday::ClientError, "Value of properties can't include HTTP/1.1 control characters"
158
157
  end
159
158
  "#{token}=#{field_value}"
160
- end.join("\r\n#{PrestoHeaders::PRESTO_SESSION}: ")
159
+ end
161
160
  end
162
161
 
163
162
  def self.encode_client_info(info)
@@ -140,11 +140,16 @@ module Presto::Client
140
140
  private :decode_model
141
141
 
142
142
  def parse_body(response)
143
- case response.headers['Content-Type']
144
- when 'application/x-msgpack'
145
- MessagePack.load(response.body)
146
- else
147
- JSON.parse(response.body, opts = JSON_OPTIONS)
143
+ begin
144
+ case response.headers['Content-Type']
145
+ when 'application/x-msgpack'
146
+ MessagePack.load(response.body)
147
+ else
148
+ JSON.parse(response.body, opts = JSON_OPTIONS)
149
+ end
150
+ rescue => e
151
+ @exception = PrestoHttpError.new(500, "Presto API returned unexpected data format. #{e}")
152
+ raise @exception
148
153
  end
149
154
  end
150
155
 
@@ -15,6 +15,6 @@
15
15
  #
16
16
  module Presto
17
17
  module Client
18
- VERSION = "0.5.10"
18
+ VERSION = "0.5.11"
19
19
  end
20
20
  end
@@ -133,8 +133,8 @@ describe Presto::Client::StatementClient do
133
133
  end
134
134
 
135
135
  describe '#query_info' do
136
- it "raises an exception with sample JSON if response is unexpected" do
137
- headers = {
136
+ let :headers do
137
+ {
138
138
  "User-Agent" => "presto-ruby/#{VERSION}",
139
139
  "X-Presto-Catalog" => options[:catalog],
140
140
  "X-Presto-Schema" => options[:schema],
@@ -142,21 +142,32 @@ describe Presto::Client::StatementClient do
142
142
  "X-Presto-Language" => options[:language],
143
143
  "X-Presto-Time-Zone" => options[:time_zone],
144
144
  }
145
+ end
145
146
 
147
+ let :statement_client do
146
148
  stub_request(:post, "http://localhost/v1/statement").
147
149
  with(body: query, headers: headers).
148
150
  to_return(body: response_json2.to_json)
151
+ StatementClient.new(faraday, query, options)
152
+ end
149
153
 
150
- sc = StatementClient.new(faraday, query, options)
151
-
152
- stub_request(:get, "http://localhost/v1/query/#{response_json2[:id]}").
153
- with(headers: headers).
154
- to_return(body: {"session" => "invalid session structure"}.to_json)
155
-
154
+ it "raises an exception with sample JSON if response is unexpected" do
156
155
  lambda do
157
- sc.query_info
156
+ stub_request(:get, "http://localhost/v1/query/#{response_json2[:id]}").
157
+ with(headers: headers).
158
+ to_return(body: {"session" => "invalid session structure"}.to_json)
159
+ statement_client.query_info
158
160
  end.should raise_error(PrestoHttpError, /Presto API returned unexpected structure at \/v1\/query\/queryid\. Expected Presto::Client::ModelVersions::.*::QueryInfo but got {"session":"invalid session structure"}/)
159
161
  end
162
+
163
+ it "raises an exception if response format is unexpected" do
164
+ lambda do
165
+ stub_request(:get, "http://localhost/v1/query/#{response_json2[:id]}").
166
+ with(headers: headers).
167
+ to_return(body: "unexpected data structure (not JSON)")
168
+ statement_client.query_info
169
+ end.should raise_error(PrestoHttpError, /Presto API returned unexpected data format./)
170
+ end
160
171
  end
161
172
 
162
173
  describe "Killing a query" do
@@ -196,7 +207,7 @@ describe Presto::Client::StatementClient do
196
207
  stub_request(:post, "localhost/v1/statement").
197
208
  with(body: query,
198
209
  headers: headers.merge({
199
- "X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join("\r\nX-Presto-Session: ")
210
+ "X-Presto-Session" => options[:properties].map {|k,v| "#{k}=#{v}"}.join(", ")
200
211
  })).
201
212
  to_return(body: response_json.to_json)
202
213
 
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.10
4
+ version: 0.5.11
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-22 00:00:00.000000000 Z
11
+ date: 2018-06-28 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.13
172
+ rubygems_version: 2.7.6
173
173
  signing_key:
174
174
  specification_version: 4
175
175
  summary: Presto client library