trino-client 2.2.6 → 2.3.1
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.md +3 -0
- data/README.md +9 -8
- data/lib/trino/client/client.rb +12 -4
- data/lib/trino/client/faraday_client.rb +27 -26
- data/lib/trino/client/query.rb +10 -6
- data/lib/trino/client/statement_client.rb +7 -1
- data/lib/trino/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63abc1ae1264778be0bd76aa0fb7225376a4a2169e6224823bfcdf551e8de741
|
|
4
|
+
data.tar.gz: c4a1cc7797f2f6e64602a7db829484942f437efde7fd568e82a416c48b26125a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ce7ae32f6e438f0558a4b2346b2480e860fc2a6111287c0e9c43f1226af7c832cca0a69a2f7a1ae19e02a9ef6d9bf1b9198881ebcda516d4b77d6ee3dece51b
|
|
7
|
+
data.tar.gz: 3bf7c96b9382ce83830902657b5eff930e63621afc70dda55aa21e71185e36057e5d68d4a99cec29392ee6e8411986bd06ee2099ccc1781cd78adde36eb5d98a
|
data/ChangeLog.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
trino-client-ruby
|
|
2
2
|
====
|
|
3
|
+
## 2.3.0
|
|
4
|
+
- Reuse a Faraday client per Trino::Client instance @p623 (#168)
|
|
5
|
+
|
|
3
6
|
## 2.2.6
|
|
4
7
|
- fix: improve POST retry tests and document idempotency assumption ([#159](https://github.com/treasure-data/trino-client-ruby/issues/159)) [[e64c2a9](https://github.com/treasure-data/trino-client-ruby/commit/e64c2a9)]
|
|
5
8
|
- Add retry to POST /v1/statement ([#157](https://github.com/treasure-data/trino-client-ruby/issues/157)) [[64a5c66](https://github.com/treasure-data/trino-client-ruby/commit/64a5c66)]
|
data/README.md
CHANGED
|
@@ -88,8 +88,8 @@ $ bundle exec rake modelgen:latest
|
|
|
88
88
|
|
|
89
89
|
## Options
|
|
90
90
|
|
|
91
|
-
* **server** sets address (and port) of a Trino coordinator server.
|
|
92
|
-
* **ssl** enables https.
|
|
91
|
+
* **server** sets address (and port) of a Trino coordinator server. Changes after client initialization are not applied; create a new client to change this option.
|
|
92
|
+
* **ssl** enables https. Changes after client initialization are not applied; create a new client to change this option.
|
|
93
93
|
* Setting `true` enables SSL and verifies server certificate using system's built-in certificates.
|
|
94
94
|
* Setting `{verify: false}` enables SSL but doesn't verify server certificate.
|
|
95
95
|
* Setting a Hash object enables SSL and verify server certificate with options:
|
|
@@ -104,20 +104,21 @@ $ bundle exec rake modelgen:latest
|
|
|
104
104
|
* **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.
|
|
105
105
|
* **client_tags** sets client tags to queries. It needs to be an array of strings. The tags are shown on web interface.
|
|
106
106
|
* **user** sets user name to connect to a Trino.
|
|
107
|
-
* **password** sets a password to connect to Trino using basic auth.
|
|
107
|
+
* **password** sets a password to connect to Trino using basic auth. Requires the client's connection to use HTTPS.
|
|
108
108
|
* **time_zone** sets time zone of queries. Time zone affects some functions such as `format_datetime`.
|
|
109
109
|
* **language** sets language of queries. Language affects some functions such as `format_datetime`.
|
|
110
110
|
* **properties** set session properties. Session properties affect internal behavior such as `hive.force_local_scheduling: true`, `raptor.reader_stream_buffer_size: "32MB"`, etc.
|
|
111
111
|
* **query_timeout** sets timeout in seconds for the entire query execution (from the first API call until there're no more output data). If timeout happens, client raises TrinoQueryTimeoutError. Default is nil (disabled).
|
|
112
112
|
* **plan_timeout** sets timeout in seconds for query planning execution (from the first API call until result columns become available). If timeout happens, client raises TrinoQueryTimeoutError. Default is nil (disabled).
|
|
113
113
|
* **http_headers** sets custom HTTP headers. It must be a Hash of string to string.
|
|
114
|
-
* **http_proxy** sets host:port of a HTTP proxy server.
|
|
115
|
-
* **http_debug** enables debug message to STDOUT for each HTTP requests.
|
|
116
|
-
* **http_debug_logger** sets a custom `Logger` instance for HTTP debug logs. Requires **http_debug** to be `true`.
|
|
114
|
+
* **http_proxy** sets host:port of a HTTP proxy server. Changes after client initialization are not applied; create a new client to change this option.
|
|
115
|
+
* **http_debug** enables debug message to STDOUT for each HTTP requests. Changes after client initialization are not applied; create a new client to change this option.
|
|
116
|
+
* **http_debug_logger** sets a custom `Logger` instance for HTTP debug logs. Requires **http_debug** to be `true`. Changes after client initialization are not applied; create a new client to change this option.
|
|
117
117
|
* **http_open_timeout** sets timeout in seconds to open new HTTP connection.
|
|
118
118
|
* **http_timeout** sets timeout in seconds to read data from a server.
|
|
119
|
-
* **gzip** enables gzip compression.
|
|
120
|
-
* **follow_redirect** enables HTTP redirection support.
|
|
119
|
+
* **gzip** enables gzip compression. Changes after client initialization are not applied; create a new client to change this option.
|
|
120
|
+
* **follow_redirect** enables HTTP redirection support. Changes after client initialization are not applied; create a new client to change this option.
|
|
121
|
+
* **faraday_adapter** sets the Faraday adapter to use. Default is `Faraday.default_adapter`. To reuse persistent HTTP connections, install `faraday-net_http_persistent` and specify `:net_http_persistent`. Changes after client initialization are not applied; create a new client to change this option.
|
|
121
122
|
* **model_version** set the Trino version to which a job is submitted. Supported versions are 351, 316, 303, 0.205, 0.178, 0.173, 0.153 and 0.149. Default is 351.
|
|
122
123
|
|
|
123
124
|
See [RDoc](http://www.rubydoc.info/gems/presto-client/) for the full documentation.
|
data/lib/trino/client/client.rb
CHANGED
|
@@ -19,12 +19,20 @@ module Trino::Client
|
|
|
19
19
|
require 'trino/client/query'
|
|
20
20
|
|
|
21
21
|
class Client
|
|
22
|
+
# Creates a reusable Faraday connection using the initial options.
|
|
23
|
+
# Connection settings are not reapplied after initialization.
|
|
24
|
+
# These include server, ssl, proxy, and faraday_adapter; see the README for the full list.
|
|
25
|
+
# Create a new Client to change these settings.
|
|
26
|
+
#
|
|
27
|
+
# Query-specific headers, including Basic Auth, use the options at query start.
|
|
28
|
+
# Password authentication requires the actual connection to use HTTPS, regardless of later changes to options[:ssl].
|
|
22
29
|
def initialize(options)
|
|
23
30
|
@options = options
|
|
31
|
+
@faraday = Trino::Client.faraday_client(options)
|
|
24
32
|
end
|
|
25
33
|
|
|
26
34
|
def query(query, &block)
|
|
27
|
-
q = Query.start(query, @options)
|
|
35
|
+
q = Query.start(query, @options, @faraday)
|
|
28
36
|
if block
|
|
29
37
|
begin
|
|
30
38
|
yield q
|
|
@@ -37,15 +45,15 @@ module Trino::Client
|
|
|
37
45
|
end
|
|
38
46
|
|
|
39
47
|
def resume_query(next_uri)
|
|
40
|
-
return Query.resume(next_uri, @options)
|
|
48
|
+
return Query.resume(next_uri, @options, @faraday)
|
|
41
49
|
end
|
|
42
50
|
|
|
43
51
|
def kill(query_id)
|
|
44
|
-
return Query.kill(query_id, @options)
|
|
52
|
+
return Query.kill(query_id, @options, @faraday)
|
|
45
53
|
end
|
|
46
54
|
|
|
47
55
|
def run(query)
|
|
48
|
-
q = Query.start(query, @options)
|
|
56
|
+
q = Query.start(query, @options, @faraday)
|
|
49
57
|
begin
|
|
50
58
|
columns = q.columns
|
|
51
59
|
if columns.empty?
|
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
#
|
|
16
16
|
module Trino::Client
|
|
17
|
-
FARADAY1_USED = Faraday::VERSION.start_with?("1.")
|
|
18
|
-
private_constant :FARADAY1_USED
|
|
19
17
|
|
|
18
|
+
require 'base64'
|
|
20
19
|
require 'cgi'
|
|
21
20
|
|
|
22
21
|
module TrinoHeaders
|
|
@@ -77,14 +76,6 @@ module Trino::Client
|
|
|
77
76
|
faraday_options[:ssl] = ssl if ssl
|
|
78
77
|
|
|
79
78
|
faraday = Faraday.new(faraday_options) do |faraday|
|
|
80
|
-
if options[:user] && options[:password]
|
|
81
|
-
# https://lostisland.github.io/faraday/middleware/authentication
|
|
82
|
-
if FARADAY1_USED
|
|
83
|
-
faraday.request(:basic_auth, options[:user], options[:password])
|
|
84
|
-
else
|
|
85
|
-
faraday.request :authorization, :basic, options[:user], options[:password]
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
79
|
if options[:follow_redirect]
|
|
89
80
|
faraday.response :follow_redirects
|
|
90
81
|
end
|
|
@@ -92,11 +83,10 @@ module Trino::Client
|
|
|
92
83
|
faraday.request :gzip
|
|
93
84
|
end
|
|
94
85
|
faraday.response :logger, options[:http_debug_logger] if options[:http_debug]
|
|
95
|
-
faraday.adapter Faraday.default_adapter
|
|
86
|
+
faraday.adapter(options[:faraday_adapter] || Faraday.default_adapter)
|
|
96
87
|
end
|
|
97
88
|
|
|
98
89
|
faraday.headers.merge!(HEADERS)
|
|
99
|
-
faraday.headers.merge!(optional_headers(options))
|
|
100
90
|
|
|
101
91
|
return faraday
|
|
102
92
|
end
|
|
@@ -129,71 +119,82 @@ module Trino::Client
|
|
|
129
119
|
return ssl
|
|
130
120
|
end
|
|
131
121
|
|
|
132
|
-
def self.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
122
|
+
def self.build_query_headers(options, faraday:)
|
|
123
|
+
if options[:password] && faraday.url_prefix.scheme != "https"
|
|
124
|
+
raise ArgumentError, "Protocol must be https when passing a password"
|
|
125
|
+
end
|
|
126
|
+
use_presto_headers = false
|
|
127
|
+
if options[:model_version] && options[:model_version].to_i < 351
|
|
128
|
+
use_presto_headers = true
|
|
136
129
|
end
|
|
137
130
|
|
|
138
131
|
headers = {}
|
|
132
|
+
|
|
133
|
+
if options[:user] && options[:password]
|
|
134
|
+
credentials = Base64.strict_encode64(
|
|
135
|
+
"#{options[:user]}:#{options[:password]}"
|
|
136
|
+
)
|
|
137
|
+
headers["Authorization"] = "Basic #{credentials}"
|
|
138
|
+
end
|
|
139
|
+
|
|
139
140
|
if v = options[:user]
|
|
140
|
-
if
|
|
141
|
+
if use_presto_headers
|
|
141
142
|
headers[PrestoHeaders::PRESTO_USER] = v
|
|
142
143
|
else
|
|
143
144
|
headers[TrinoHeaders::TRINO_USER] = v
|
|
144
145
|
end
|
|
145
146
|
end
|
|
146
147
|
if v = options[:source]
|
|
147
|
-
if
|
|
148
|
+
if use_presto_headers
|
|
148
149
|
headers[PrestoHeaders::PRESTO_SOURCE] = v
|
|
149
150
|
else
|
|
150
151
|
headers[TrinoHeaders::TRINO_SOURCE] = v
|
|
151
152
|
end
|
|
152
153
|
end
|
|
153
154
|
if v = options[:catalog]
|
|
154
|
-
if
|
|
155
|
+
if use_presto_headers
|
|
155
156
|
headers[PrestoHeaders::PRESTO_CATALOG] = v
|
|
156
157
|
else
|
|
157
158
|
headers[TrinoHeaders::TRINO_CATALOG] = v
|
|
158
159
|
end
|
|
159
160
|
end
|
|
160
161
|
if v = options[:schema]
|
|
161
|
-
if
|
|
162
|
+
if use_presto_headers
|
|
162
163
|
headers[PrestoHeaders::PRESTO_SCHEMA] = v
|
|
163
164
|
else
|
|
164
165
|
headers[TrinoHeaders::TRINO_SCHEMA] = v
|
|
165
166
|
end
|
|
166
167
|
end
|
|
167
168
|
if v = options[:time_zone]
|
|
168
|
-
if
|
|
169
|
+
if use_presto_headers
|
|
169
170
|
headers[PrestoHeaders::PRESTO_TIME_ZONE] = v
|
|
170
171
|
else
|
|
171
172
|
headers[TrinoHeaders::TRINO_TIME_ZONE] = v
|
|
172
173
|
end
|
|
173
174
|
end
|
|
174
175
|
if v = options[:language]
|
|
175
|
-
if
|
|
176
|
+
if use_presto_headers
|
|
176
177
|
headers[PrestoHeaders::PRESTO_LANGUAGE] = v
|
|
177
178
|
else
|
|
178
179
|
headers[TrinoHeaders::TRINO_LANGUAGE] = v
|
|
179
180
|
end
|
|
180
181
|
end
|
|
181
182
|
if v = options[:properties]
|
|
182
|
-
if
|
|
183
|
+
if use_presto_headers
|
|
183
184
|
headers[PrestoHeaders::PRESTO_SESSION] = encode_properties(v)
|
|
184
185
|
else
|
|
185
186
|
headers[TrinoHeaders::TRINO_SESSION] = encode_properties(v)
|
|
186
187
|
end
|
|
187
188
|
end
|
|
188
189
|
if v = options[:client_info]
|
|
189
|
-
if
|
|
190
|
+
if use_presto_headers
|
|
190
191
|
headers[PrestoHeaders::PRESTO_CLIENT_INFO] = encode_client_info(v)
|
|
191
192
|
else
|
|
192
193
|
headers[TrinoHeaders::TRINO_CLIENT_INFO] = encode_client_info(v)
|
|
193
194
|
end
|
|
194
195
|
end
|
|
195
196
|
if v = options[:client_tags]
|
|
196
|
-
if
|
|
197
|
+
if use_presto_headers
|
|
197
198
|
headers[PrestoHeaders::PRESTO_CLIENT_TAGS] = encode_client_tags(v)
|
|
198
199
|
else
|
|
199
200
|
headers[TrinoHeaders::TRINO_CLIENT_TAGS] = encode_client_tags(v)
|
|
@@ -245,6 +246,6 @@ module Trino::Client
|
|
|
245
246
|
Array(tags).join(",")
|
|
246
247
|
end
|
|
247
248
|
|
|
248
|
-
private_class_method :faraday_ssl_options, :
|
|
249
|
+
private_class_method :faraday_ssl_options, :encode_properties, :encode_client_info, :encode_client_tags
|
|
249
250
|
|
|
250
251
|
end
|
data/lib/trino/client/query.rb
CHANGED
|
@@ -25,17 +25,21 @@ module Trino::Client
|
|
|
25
25
|
require 'trino/client/statement_client'
|
|
26
26
|
|
|
27
27
|
class Query
|
|
28
|
-
def self.start(query, options)
|
|
29
|
-
|
|
28
|
+
def self.start(query, options, faraday = nil)
|
|
29
|
+
faraday ||= faraday_client(options)
|
|
30
|
+
new StatementClient.new(faraday, query, options)
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
def self.resume(next_uri, options)
|
|
33
|
-
|
|
33
|
+
def self.resume(next_uri, options, faraday = nil)
|
|
34
|
+
faraday ||= faraday_client(options)
|
|
35
|
+
new StatementClient.new(faraday, nil, options, next_uri)
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
def self.kill(query_id, options)
|
|
37
|
-
faraday
|
|
38
|
+
def self.kill(query_id, options, faraday = nil)
|
|
39
|
+
faraday ||= faraday_client(options)
|
|
40
|
+
headers = Trino::Client.build_query_headers(options, faraday: faraday)
|
|
38
41
|
response = faraday.delete do |req|
|
|
42
|
+
req.headers.merge!(headers)
|
|
39
43
|
req.url "/v1/query/#{query_id}"
|
|
40
44
|
end
|
|
41
45
|
return response.status / 100 == 2
|
|
@@ -30,6 +30,7 @@ module Trino::Client
|
|
|
30
30
|
|
|
31
31
|
def initialize(faraday, query, options, next_uri=nil)
|
|
32
32
|
@faraday = faraday
|
|
33
|
+
@headers = Trino::Client.build_query_headers(options, faraday: @faraday)
|
|
33
34
|
|
|
34
35
|
@options = options
|
|
35
36
|
@query = query
|
|
@@ -72,6 +73,7 @@ module Trino::Client
|
|
|
72
73
|
begin
|
|
73
74
|
r = @faraday.post do |req|
|
|
74
75
|
req.url uri
|
|
76
|
+
req.headers.merge!(@headers)
|
|
75
77
|
|
|
76
78
|
req.body = @query
|
|
77
79
|
init_request(req)
|
|
@@ -229,7 +231,9 @@ module Trino::Client
|
|
|
229
231
|
def faraday_get_with_retry(uri)
|
|
230
232
|
with_retry_loop do
|
|
231
233
|
begin
|
|
232
|
-
response = @faraday.get(uri)
|
|
234
|
+
response = @faraday.get(uri) do |req|
|
|
235
|
+
req.headers.merge!(@headers)
|
|
236
|
+
end
|
|
233
237
|
rescue Faraday::TimeoutError, Faraday::ConnectionFailed
|
|
234
238
|
throw :retry_with_backoff
|
|
235
239
|
rescue => e
|
|
@@ -278,6 +282,7 @@ module Trino::Client
|
|
|
278
282
|
def cancel_leaf_stage
|
|
279
283
|
if uri = @results.partial_cancel_uri
|
|
280
284
|
@faraday.delete do |req|
|
|
285
|
+
req.headers.merge!(@headers)
|
|
281
286
|
req.url uri
|
|
282
287
|
end
|
|
283
288
|
end
|
|
@@ -291,6 +296,7 @@ module Trino::Client
|
|
|
291
296
|
begin
|
|
292
297
|
if uri = @results.next_uri
|
|
293
298
|
@faraday.delete do |req|
|
|
299
|
+
req.headers.merge!(@headers)
|
|
294
300
|
req.url uri
|
|
295
301
|
end
|
|
296
302
|
end
|
data/lib/trino/client/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: trino-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sadayuki Furuhashi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|