rb_snowflake_client 1.0.6 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +13 -0
- data/Gemfile +0 -6
- data/Gemfile.lock +26 -29
- data/README.md +24 -0
- data/lib/ruby_snowflake/client.rb +12 -12
- data/lib/ruby_snowflake/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '089c46288d7dc44f8717542fce8732ce32c65db796e5ac5d49fa6fff6cb1f29d'
|
4
|
+
data.tar.gz: '035589f8bcc072830f037c333379a2059eb6a205ad8ae6daecb2bb2ea9c4761a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e390973b02ce165e3bb5722c84cc79cb8c1fcc8457b57ceaf9317f2675fdfe2e5b6276d7c8a496ec5605ab66c15fcdfa2247182d1f54bed39df3c8ce4240fed7
|
7
|
+
data.tar.gz: '092ba2997da8f64f6e9e7ff912d7bdb43882681f5d564028f9a9c6ad51854515e237de27b51de35329acb3fd021de3d4212551cbc31a58942592627805f2e298'
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rb_snowflake_client (1.
|
4
|
+
rb_snowflake_client (1.1.1)
|
5
5
|
concurrent-ruby (>= 1.2)
|
6
6
|
connection_pool (>= 2.4)
|
7
7
|
dotenv (>= 2.8)
|
@@ -12,52 +12,49 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
+
base64 (0.2.0)
|
16
|
+
bigdecimal (3.1.8)
|
15
17
|
coderay (1.1.3)
|
16
|
-
concurrent-ruby (1.
|
18
|
+
concurrent-ruby (1.3.1)
|
17
19
|
connection_pool (2.4.1)
|
18
|
-
diff-lcs (1.5.
|
19
|
-
dotenv (
|
20
|
-
jwt (2.
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
diff-lcs (1.5.1)
|
21
|
+
dotenv (3.1.2)
|
22
|
+
jwt (2.8.1)
|
23
|
+
base64
|
24
|
+
method_source (1.1.0)
|
25
|
+
oj (3.16.3)
|
26
|
+
bigdecimal (>= 3.0)
|
27
|
+
parallel (1.24.0)
|
24
28
|
pry (0.14.2)
|
25
29
|
coderay (~> 1.1)
|
26
30
|
method_source (~> 1.0)
|
27
|
-
rake (13.1
|
31
|
+
rake (13.2.1)
|
28
32
|
retryable (3.0.5)
|
29
|
-
rspec (3.
|
30
|
-
rspec-core (~> 3.
|
31
|
-
rspec-expectations (~> 3.
|
32
|
-
rspec-mocks (~> 3.
|
33
|
-
rspec-core (3.
|
34
|
-
rspec-support (~> 3.
|
35
|
-
rspec-expectations (3.
|
33
|
+
rspec (3.13.0)
|
34
|
+
rspec-core (~> 3.13.0)
|
35
|
+
rspec-expectations (~> 3.13.0)
|
36
|
+
rspec-mocks (~> 3.13.0)
|
37
|
+
rspec-core (3.13.0)
|
38
|
+
rspec-support (~> 3.13.0)
|
39
|
+
rspec-expectations (3.13.0)
|
36
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-mocks (3.
|
41
|
+
rspec-support (~> 3.13.0)
|
42
|
+
rspec-mocks (3.13.1)
|
39
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.
|
41
|
-
rspec-support (3.
|
44
|
+
rspec-support (~> 3.13.0)
|
45
|
+
rspec-support (3.13.1)
|
42
46
|
|
43
47
|
PLATFORMS
|
44
|
-
arm64-darwin-21
|
45
48
|
arm64-darwin-22
|
46
|
-
|
49
|
+
ruby
|
47
50
|
|
48
51
|
DEPENDENCIES
|
49
52
|
bundler
|
50
|
-
concurrent-ruby
|
51
|
-
connection_pool
|
52
|
-
dotenv
|
53
|
-
jwt
|
54
|
-
oj
|
55
53
|
parallel
|
56
54
|
pry
|
57
55
|
rake
|
58
56
|
rb_snowflake_client!
|
59
|
-
retryable
|
60
57
|
rspec
|
61
58
|
|
62
59
|
BUNDLED WITH
|
63
|
-
2.4
|
60
|
+
2.5.4
|
data/README.md
CHANGED
@@ -105,6 +105,30 @@ Clients are not warehouse specific, you can override the default warehouse per q
|
|
105
105
|
client.query("SELECT * FROM BIGTABLE", warehouse: "FAST_WH")
|
106
106
|
```
|
107
107
|
|
108
|
+
## Specifying a schema
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
client.query("SELECT * FROM BIGTABLE", schema: "MY_SCHEMA")
|
112
|
+
```
|
113
|
+
|
114
|
+
## Binding parameters
|
115
|
+
|
116
|
+
Say we have `BIGTABLE` with a `data` column of a type `VARIANT`.
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
json_string = '{"valid": "json"}'
|
120
|
+
query = "insert into BIGTABLE(data) select parse_json(?)"
|
121
|
+
bindings = {
|
122
|
+
"1": {
|
123
|
+
"type": "TEXT",
|
124
|
+
"value": json_string
|
125
|
+
}
|
126
|
+
}
|
127
|
+
client.query(query, bindings: bindings)
|
128
|
+
```
|
129
|
+
|
130
|
+
For additional information about binding parameters refer to snowflake documentation: https://docs.snowflake.com/en/developer-guide/sql-api/submitting-requests#using-bind-variables-in-a-statement
|
131
|
+
|
108
132
|
# Configuration Options
|
109
133
|
|
110
134
|
The client supports the following configuration options, each with their own getter/setter except connection pool options which must be set at construction. Additionally, all except logger can be configured with environment variables (see above, but the pattern is like: "SNOWFLAKE_HTTP_RETRIES". Configuration options can only be set on initialization through `new` or `from_env`.
|
@@ -128,7 +128,7 @@ module RubySnowflake
|
|
128
128
|
@_enable_polling_queries = false
|
129
129
|
end
|
130
130
|
|
131
|
-
def query(query, warehouse: nil, streaming: false, database: nil, schema: nil)
|
131
|
+
def query(query, warehouse: nil, streaming: false, database: nil, schema: nil, bindings: nil)
|
132
132
|
warehouse ||= @default_warehouse
|
133
133
|
database ||= @default_database
|
134
134
|
|
@@ -136,11 +136,11 @@ module RubySnowflake
|
|
136
136
|
response = nil
|
137
137
|
connection_pool.with do |connection|
|
138
138
|
request_body = {
|
139
|
-
"
|
139
|
+
"warehouse" => warehouse&.upcase,
|
140
140
|
"schema" => schema&.upcase,
|
141
|
+
"database" => database&.upcase,
|
141
142
|
"statement" => query,
|
142
|
-
"
|
143
|
-
"warehouse" => warehouse&.upcase,
|
143
|
+
"bindings" => bindings
|
144
144
|
}
|
145
145
|
|
146
146
|
response = request_with_auth_and_headers(
|
@@ -150,7 +150,7 @@ module RubySnowflake
|
|
150
150
|
Oj.dump(request_body)
|
151
151
|
)
|
152
152
|
end
|
153
|
-
|
153
|
+
retrieve_result_set(query_start_time, query, response, streaming)
|
154
154
|
end
|
155
155
|
|
156
156
|
alias fetch query
|
@@ -223,7 +223,7 @@ module RubySnowflake
|
|
223
223
|
def retryable_http_response_code?(code)
|
224
224
|
# retry (in order): bad request, forbidden (token expired in flight), method not allowed,
|
225
225
|
# request timeout, too many requests, anything in the 500 range (504 is fairly common)
|
226
|
-
[400, 403, 405, 408, 429, 504].include?(code.to_i) || (500..599).include?(code)
|
226
|
+
[400, 403, 405, 408, 429, 502, 504].include?(code.to_i) || (500..599).include?(code.to_i)
|
227
227
|
end
|
228
228
|
|
229
229
|
def retryable_log_method
|
@@ -267,7 +267,7 @@ module RubySnowflake
|
|
267
267
|
false
|
268
268
|
end
|
269
269
|
|
270
|
-
def
|
270
|
+
def retrieve_result_set(query_start_time, query, response, streaming)
|
271
271
|
json_body = Oj.load(response.body, OJ_OPTIONS)
|
272
272
|
statement_handle = json_body["statementHandle"]
|
273
273
|
|
@@ -277,18 +277,18 @@ module RubySnowflake
|
|
277
277
|
end
|
278
278
|
|
279
279
|
num_threads = number_of_threads_to_use(json_body["resultSetMetaData"]["partitionInfo"].size)
|
280
|
-
|
280
|
+
retrieve_proc = ->(index) { retrieve_partition_data(statement_handle, index) }
|
281
281
|
|
282
282
|
if streaming
|
283
|
-
StreamingResultStrategy.result(json_body,
|
283
|
+
StreamingResultStrategy.result(json_body, retrieve_proc)
|
284
284
|
elsif num_threads == 1
|
285
|
-
SingleThreadInMemoryStrategy.result(json_body,
|
285
|
+
SingleThreadInMemoryStrategy.result(json_body, retrieve_proc)
|
286
286
|
else
|
287
|
-
ThreadedInMemoryStrategy.result(json_body,
|
287
|
+
ThreadedInMemoryStrategy.result(json_body, retrieve_proc, num_threads)
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
|
-
def
|
291
|
+
def retrieve_partition_data(statement_handle, partition_index)
|
292
292
|
partition_response = nil
|
293
293
|
connection_pool.with do |connection|
|
294
294
|
partition_response = request_with_auth_and_headers(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb_snowflake_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rinsed
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -105,6 +105,7 @@ executables: []
|
|
105
105
|
extensions: []
|
106
106
|
extra_rdoc_files: []
|
107
107
|
files:
|
108
|
+
- ".github/dependabot.yml"
|
108
109
|
- ".github/workflows/ci.yml"
|
109
110
|
- ".github/workflows/release-gh-packages.yml"
|
110
111
|
- ".github/workflows/release-rubygems.yml"
|