rb_snowflake_client 1.0.6 → 1.1.0
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/Gemfile.lock +26 -23
- data/README.md +18 -0
- data/lib/ruby_snowflake/client.rb +11 -11
- data/lib/ruby_snowflake/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c61238d7915a65cc04b0219e1fd8dc016cc645d8b62819264e2476cd22bdace
|
4
|
+
data.tar.gz: b23ace47b825ed4650a12c1fe51b88a72ee51e9e6451e8421c99efbad14ccd1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c6616faa6d200731c4783e2ae0390022b9a90086e05e9c8b19527e74b65c59912155240f036f660c83c24b50fa30242a14a79f4b4c6b464cdc2d51a396725cf
|
7
|
+
data.tar.gz: 3dfeceb361c57f2f40eb3e3adc626abd0832ee977ef8ed86cdd089ae4f1eae95013c8441085aa3c9e74b19f8f367f7259adc75a477ecc34dcffeddbc65853158
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rb_snowflake_client (1.0
|
4
|
+
rb_snowflake_client (1.1.0)
|
5
5
|
concurrent-ruby (>= 1.2)
|
6
6
|
connection_pool (>= 2.4)
|
7
7
|
dotenv (>= 2.8)
|
@@ -12,38 +12,41 @@ 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
|
@@ -60,4 +63,4 @@ DEPENDENCIES
|
|
60
63
|
rspec
|
61
64
|
|
62
65
|
BUNDLED WITH
|
63
|
-
2.4
|
66
|
+
2.5.4
|
data/README.md
CHANGED
@@ -105,6 +105,24 @@ 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
|
+
## Binding parameters
|
109
|
+
|
110
|
+
Say we have `BIGTABLE` with a `data` column of a type `VARIANT`.
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
json_string = '{"valid": "json"}'
|
114
|
+
query = "insert into BIGTABLE(data) select parse_json(?)"
|
115
|
+
bindings = {
|
116
|
+
"1": {
|
117
|
+
"type": "TEXT",
|
118
|
+
"value": json_string
|
119
|
+
}
|
120
|
+
}
|
121
|
+
client.query(query, bindings: bindings)
|
122
|
+
```
|
123
|
+
|
124
|
+
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
|
125
|
+
|
108
126
|
# Configuration Options
|
109
127
|
|
110
128
|
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
|
@@ -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(
|