presto-client 0.4.16 → 0.4.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +7 -0
- data/README.md +36 -20
- data/lib/presto/client/query.rb +34 -2
- data/lib/presto/client/version.rb +1 -1
- data/spec/statement_client_spec.rb +79 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33c1344d5c5fdbd9243609bee287ead639459b42
|
4
|
+
data.tar.gz: 3930795b17c3c7568f0f907fe7719aeda4552af9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dacfb03dc4ec93ff88db6dba2cd1d015ddd67fad92fdf25732434763e7ef52c7ab58e58186068bf6cc133e7301fea9f38d03cc0616ffdd7f498ed5c215cddb6
|
7
|
+
data.tar.gz: 06986f8b3bc2f52b518e3e34d0d05a9edade2aae43b3abdd65f80c5f32695eb1fd03042b99f6b0d9bc34b9aab69adea882f6ed458b13966caa27b8f6ce1eda94
|
data/ChangeLog
CHANGED
@@ -1,11 +1,18 @@
|
|
1
|
+
2016-08-09 version 0.4.17:
|
2
|
+
|
3
|
+
* Added support for :ssl option.
|
4
|
+
|
5
|
+
|
1
6
|
2016-08-03 version 0.4.16:
|
2
7
|
|
3
8
|
* Upgraded Presto model version to 0.151
|
4
9
|
|
10
|
+
|
5
11
|
2016-08-03 version 0.4.15:
|
6
12
|
|
7
13
|
* decode method of model classes validate Hash type
|
8
14
|
|
15
|
+
|
9
16
|
2016-08-02 version 0.4.14:
|
10
17
|
|
11
18
|
* Added support for resuming fetching query results by using new `Query.resume(next_uri, options)` method (@tetrakai++)
|
data/README.md
CHANGED
@@ -14,24 +14,28 @@ require 'presto-client'
|
|
14
14
|
|
15
15
|
# create a client object:
|
16
16
|
client = Presto::Client.new(
|
17
|
-
server: "localhost:8880",
|
17
|
+
server: "localhost:8880", # required option
|
18
|
+
ssl: {verify: false},
|
18
19
|
catalog: "native",
|
19
20
|
schema: "default",
|
20
21
|
user: "frsyuki",
|
21
|
-
time_zone: "US/Pacific",
|
22
|
-
language: "English",
|
23
|
-
properties: {
|
24
|
-
|
22
|
+
time_zone: "US/Pacific",
|
23
|
+
language: "English",
|
24
|
+
properties: {
|
25
|
+
"hive.force_local_scheduling": true,
|
26
|
+
"raptor.reader_stream_buffer_size": "32MB"
|
27
|
+
},
|
28
|
+
http_proxy: "proxy.example.com:8080",
|
25
29
|
http_debug: true,
|
26
30
|
)
|
27
31
|
|
28
|
-
# run a query and get results:
|
32
|
+
# run a query and get results as an array of arrays:
|
29
33
|
columns, rows = client.run("select * from sys.node")
|
30
34
|
rows.each {|row|
|
31
|
-
p row
|
35
|
+
p row # row is an array
|
32
36
|
}
|
33
37
|
|
34
|
-
# run a query and get results as
|
38
|
+
# run a query and get results as an array of hashes:
|
35
39
|
results = client.run_with_names("select alpha, 1 AS beta from tablename")
|
36
40
|
results.each {|row|
|
37
41
|
p row['alpha'] # access by name
|
@@ -40,32 +44,44 @@ results.each {|row|
|
|
40
44
|
p row.values[1]
|
41
45
|
}
|
42
46
|
|
43
|
-
#
|
44
|
-
# start running a query on presto
|
47
|
+
# run a query and fetch results streamingly:
|
45
48
|
client.query("select * from sys.node") do |q|
|
46
|
-
#
|
49
|
+
# get columns:
|
47
50
|
q.columns.each {|column|
|
48
51
|
puts "column: #{column.name}.#{column.type}"
|
49
52
|
}
|
50
53
|
|
51
|
-
# get query results
|
54
|
+
# get query results. it feeds more rows until
|
55
|
+
# query execution finishes:
|
52
56
|
q.each_row {|row|
|
53
|
-
p row
|
57
|
+
p row # row is an array
|
54
58
|
}
|
55
59
|
end
|
56
60
|
```
|
57
61
|
|
58
62
|
## Options
|
59
63
|
|
60
|
-
* **server** sets address
|
64
|
+
* **server** sets address (and port) of a Presto coordinator server.
|
65
|
+
* **ssl** enables https.
|
66
|
+
* Setting `true` enables SSL and verifies server certificate using system's built-in certificates.
|
67
|
+
* Setting `{verify: false}` enables SSL but doesn't verify server certificate.
|
68
|
+
* Setting a Hash object enables SSL and verify server certificate with options:
|
69
|
+
* **ca_file**: path of a CA certification file in PEM format
|
70
|
+
* **ca_path**: path of a CA certification directory containing certifications in PEM format
|
71
|
+
* **cert_store**: a `OpenSSL::X509::Store` object used for verification
|
72
|
+
* **client_cert**: a `OpenSSL::X509::Certificate` object as client certificate
|
73
|
+
* **client_key**: a `OpenSSL::PKey::RSA` or `OpenSSL::PKey::DSA` object used for client certificate
|
61
74
|
* **catalog** sets catalog (connector) name of Presto such as `hive-cdh4`, `hive-hadoop1`, etc.
|
62
|
-
* **schema** sets default schema name of Presto. You
|
75
|
+
* **schema** sets default schema name of Presto. You need to use qualified name like `FROM myschema.table1` to use non-default schemas.
|
63
76
|
* **source** sets source name to connect to a Presto. This name is shown on Presto web interface.
|
64
77
|
* **user** sets user name to connect to a Presto.
|
65
|
-
* **time_zone** sets time zone of
|
66
|
-
* **language** sets language of
|
78
|
+
* **time_zone** sets time zone of queries. Time zone affects some functions such as `format_datetime`.
|
79
|
+
* **language** sets language of queries. Language affects some functions such as `format_datetime`.
|
80
|
+
* **properties** set session properties. Session properties affect internal behavior such as `hive.force_local_scheduling: true`, `raptor.reader_stream_buffer_size: "32MB"`, etc.
|
67
81
|
* **http_proxy** sets host:port of a HTTP proxy server.
|
68
|
-
* **http_debug** enables debug message to STDOUT for each HTTP requests
|
69
|
-
* **http_open_timeout** sets timeout in seconds to open new HTTP connection
|
70
|
-
* **http_timeout** sets timeout in seconds to read data from a server
|
82
|
+
* **http_debug** enables debug message to STDOUT for each HTTP requests.
|
83
|
+
* **http_open_timeout** sets timeout in seconds to open new HTTP connection.
|
84
|
+
* **http_timeout** sets timeout in seconds to read data from a server.
|
85
|
+
|
86
|
+
See [RDoc](http://www.rubydoc.info/gems/presto-client/) for the full documentation.
|
71
87
|
|
data/lib/presto/client/query.rb
CHANGED
@@ -35,8 +35,12 @@ module Presto::Client
|
|
35
35
|
raise ArgumentError, ":server option is required"
|
36
36
|
end
|
37
37
|
|
38
|
+
ssl = faraday_ssl_options(options)
|
39
|
+
|
40
|
+
url = "#{ssl ? "https" : "http"}://#{server}"
|
38
41
|
proxy = options[:http_proxy] || options[:proxy] # :proxy is obsoleted
|
39
|
-
|
42
|
+
|
43
|
+
faraday = Faraday.new(url: url, proxy: "#{proxy}", ssl: ssl) do |faraday|
|
40
44
|
#faraday.request :url_encoded
|
41
45
|
faraday.response :logger if options[:http_debug]
|
42
46
|
faraday.adapter Faraday.default_adapter
|
@@ -45,7 +49,35 @@ module Presto::Client
|
|
45
49
|
return faraday
|
46
50
|
end
|
47
51
|
|
48
|
-
|
52
|
+
def self.faraday_ssl_options(options)
|
53
|
+
ssl = options[:ssl]
|
54
|
+
|
55
|
+
case ssl
|
56
|
+
when true
|
57
|
+
ssl = {verify: true}
|
58
|
+
|
59
|
+
when Hash
|
60
|
+
verify = ssl.fetch(:verify, true)
|
61
|
+
case verify
|
62
|
+
when true
|
63
|
+
# detailed SSL options. pass through to faraday
|
64
|
+
when nil, false
|
65
|
+
ssl = {verify: false}
|
66
|
+
else
|
67
|
+
raise ArgumentError, "Can't convert #{verify.class} of :verify option of :ssl option to true or false"
|
68
|
+
end
|
69
|
+
|
70
|
+
when nil, false
|
71
|
+
ssl = false
|
72
|
+
|
73
|
+
else
|
74
|
+
raise ArgumentError, "Can't convert #{ssl.class} of :ssl option to true, false, or Hash"
|
75
|
+
end
|
76
|
+
|
77
|
+
return ssl
|
78
|
+
end
|
79
|
+
|
80
|
+
private_class_method :faraday_client, :faraday_ssl_options
|
49
81
|
|
50
82
|
def initialize(api)
|
51
83
|
@api = api
|
@@ -101,5 +101,84 @@ describe Presto::Client::StatementClient do
|
|
101
101
|
})
|
102
102
|
end.should raise_error(TypeError, /String to Hash/)
|
103
103
|
end
|
104
|
+
|
105
|
+
describe "ssl" do
|
106
|
+
it "is disabled by default" do
|
107
|
+
f = Query.__send__(:faraday_client, {
|
108
|
+
server: "localhost",
|
109
|
+
})
|
110
|
+
f.url_prefix.to_s.should == "http://localhost/"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "is enabled with ssl: true" do
|
114
|
+
f = Query.__send__(:faraday_client, {
|
115
|
+
server: "localhost",
|
116
|
+
ssl: true,
|
117
|
+
})
|
118
|
+
f.url_prefix.to_s.should == "https://localhost/"
|
119
|
+
f.ssl.verify?.should == true
|
120
|
+
end
|
121
|
+
|
122
|
+
it "is enabled with ssl: {verify: false}" do
|
123
|
+
f = Query.__send__(:faraday_client, {
|
124
|
+
server: "localhost",
|
125
|
+
ssl: {verify: false}
|
126
|
+
})
|
127
|
+
f.url_prefix.to_s.should == "https://localhost/"
|
128
|
+
f.ssl.verify?.should == false
|
129
|
+
end
|
130
|
+
|
131
|
+
it "rejects invalid ssl: verify: object" do
|
132
|
+
lambda do
|
133
|
+
f = Query.__send__(:faraday_client, {
|
134
|
+
server: "localhost",
|
135
|
+
ssl: {verify: "??"}
|
136
|
+
})
|
137
|
+
end.should raise_error(ArgumentError, /String/)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "is enabled with ssl: Hash" do
|
141
|
+
require 'openssl'
|
142
|
+
|
143
|
+
ssl = {
|
144
|
+
ca_file: "/path/to/dummy.pem",
|
145
|
+
ca_path: "/path/to/pemdir",
|
146
|
+
cert_store: OpenSSL::X509::Store.new,
|
147
|
+
client_cert: OpenSSL::X509::Certificate.new,
|
148
|
+
client_key: OpenSSL::PKey::DSA.new,
|
149
|
+
}
|
150
|
+
|
151
|
+
f = Query.__send__(:faraday_client, {
|
152
|
+
server: "localhost",
|
153
|
+
ssl: ssl,
|
154
|
+
})
|
155
|
+
|
156
|
+
f.url_prefix.to_s.should == "https://localhost/"
|
157
|
+
f.ssl.verify?.should == true
|
158
|
+
f.ssl.ca_file.should == ssl[:ca_file]
|
159
|
+
f.ssl.ca_path.should == ssl[:ca_path]
|
160
|
+
f.ssl.cert_store.should == ssl[:cert_store]
|
161
|
+
f.ssl.client_cert.should == ssl[:client_cert]
|
162
|
+
f.ssl.client_key.should == ssl[:client_key]
|
163
|
+
end
|
164
|
+
|
165
|
+
it "rejects an invalid string" do
|
166
|
+
lambda do
|
167
|
+
Query.__send__(:faraday_client, {
|
168
|
+
server: "localhost",
|
169
|
+
ssl: '??',
|
170
|
+
})
|
171
|
+
end.should raise_error(ArgumentError, /String/)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "rejects an integer" do
|
175
|
+
lambda do
|
176
|
+
Query.__send__(:faraday_client, {
|
177
|
+
server: "localhost",
|
178
|
+
ssl: 3,
|
179
|
+
})
|
180
|
+
end.should raise_error(ArgumentError, /:ssl/)
|
181
|
+
end
|
182
|
+
end
|
104
183
|
end
|
105
184
|
|
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.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|