rb_snowflake_client 1.0.5 → 1.1.0

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
2
  SHA256:
3
- metadata.gz: 41fc128164ffef226da74985180b136ecfbce6314cb3041e131653765c9e486f
4
- data.tar.gz: b86fe4295d3ad395682214e116a0a4bf1e25213d7815ee52dffbe302d5c87e4a
3
+ metadata.gz: 7c61238d7915a65cc04b0219e1fd8dc016cc645d8b62819264e2476cd22bdace
4
+ data.tar.gz: b23ace47b825ed4650a12c1fe51b88a72ee51e9e6451e8421c99efbad14ccd1f
5
5
  SHA512:
6
- metadata.gz: 89ad4c5b56f58acbd1440b8f0a3fb55c2a4aaa259bbea1ee8823078f95c00acfd4edf6a19e3ad03ebe539516de1988dda49b59560ccdbe43209ecdc579c0b147
7
- data.tar.gz: 2fb149655ba64aa0b45a38b65fa21f8a14889c522de6bb0bc5cd43d3905306f03f46f28ac3c51a6b8cabbf0564221958bf9f06a670c40e83fcd6229b44dbe8cf
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.5)
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.2.2)
18
+ concurrent-ruby (1.3.1)
17
19
  connection_pool (2.4.1)
18
- diff-lcs (1.5.0)
19
- dotenv (2.8.1)
20
- jwt (2.7.1)
21
- method_source (1.0.0)
22
- oj (3.16.1)
23
- parallel (1.23.0)
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.0)
31
+ rake (13.2.1)
28
32
  retryable (3.0.5)
29
- rspec (3.12.0)
30
- rspec-core (~> 3.12.0)
31
- rspec-expectations (~> 3.12.0)
32
- rspec-mocks (~> 3.12.0)
33
- rspec-core (3.12.2)
34
- rspec-support (~> 3.12.0)
35
- rspec-expectations (3.12.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.12.0)
38
- rspec-mocks (3.12.6)
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.12.0)
41
- rspec-support (3.12.1)
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
- x86_64-linux
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.19
66
+ 2.5.4
data/README.md CHANGED
@@ -4,11 +4,11 @@
4
4
 
5
5
  The available options for connecting from Ruby to Snowflake include:
6
6
  * ODBC - which works, but can be very slow, especially for a lot of data, which is probably why you're using Snowflake
7
- * The [ruby snowflake client][https://github.com/rinsed-org/ruby-snowflake-client] that wraps the go client. This is probably the fastest single threaded option, which we also created. However, that library takes the ruby GVL and so stops all other processing in your ruby process (threads).
7
+ * The [ruby snowflake client](https://github.com/rinsed-org/ruby-snowflake-client) that wraps the go client. This is probably the fastest single threaded option, which we also created. However, that library takes the ruby GVL and so stops all other processing in your ruby process (threads).
8
8
 
9
9
  This library is implemented in ruby and while it leverages some libraries that have native extensions, doesn't currently include anything itself. Depending on network latency and the shape of the data this library can be faster or slower than the go wrapper. The big advantages are:
10
10
  * It uses about half the memory when you pull a full result set into memory
11
- * It does not hold onto the [ruby GVL][https://www.speedshop.co/2020/05/11/the-ruby-gvl-and-scaling.html] and so does not block other threads while waiting on IO like the go wrapper client.
11
+ * It does not hold onto the [ruby GVL](https://www.speedshop.co/2020/05/11/the-ruby-gvl-and-scaling.html) and so does not block other threads while waiting on IO like the go wrapper client.
12
12
  * It will consume more resources for the same data, because it's using the HTTP v2 API and getting JSON back, there is just more work to as compared to the go or python clients that use Apache Arrow under the covers.
13
13
 
14
14
  # Usage
@@ -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)
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,8 +136,11 @@ module RubySnowflake
136
136
  response = nil
137
137
  connection_pool.with do |connection|
138
138
  request_body = {
139
- "statement" => query, "warehouse" => warehouse&.upcase,
140
- "database" => database&.upcase, "timeout" => @query_timeout
139
+ "warehouse" => warehouse&.upcase,
140
+ "schema" => schema&.upcase,
141
+ "database" => database&.upcase,
142
+ "statement" => query,
143
+ "bindings" => bindings
141
144
  }
142
145
 
143
146
  response = request_with_auth_and_headers(
@@ -147,7 +150,7 @@ module RubySnowflake
147
150
  Oj.dump(request_body)
148
151
  )
149
152
  end
150
- retreive_result_set(query_start_time, query, response, streaming)
153
+ retrieve_result_set(query_start_time, query, response, streaming)
151
154
  end
152
155
 
153
156
  alias fetch query
@@ -264,7 +267,7 @@ module RubySnowflake
264
267
  false
265
268
  end
266
269
 
267
- def retreive_result_set(query_start_time, query, response, streaming)
270
+ def retrieve_result_set(query_start_time, query, response, streaming)
268
271
  json_body = Oj.load(response.body, OJ_OPTIONS)
269
272
  statement_handle = json_body["statementHandle"]
270
273
 
@@ -274,18 +277,18 @@ module RubySnowflake
274
277
  end
275
278
 
276
279
  num_threads = number_of_threads_to_use(json_body["resultSetMetaData"]["partitionInfo"].size)
277
- retreive_proc = ->(index) { retreive_partition_data(statement_handle, index) }
280
+ retrieve_proc = ->(index) { retrieve_partition_data(statement_handle, index) }
278
281
 
279
282
  if streaming
280
- StreamingResultStrategy.result(json_body, retreive_proc)
283
+ StreamingResultStrategy.result(json_body, retrieve_proc)
281
284
  elsif num_threads == 1
282
- SingleThreadInMemoryStrategy.result(json_body, retreive_proc)
285
+ SingleThreadInMemoryStrategy.result(json_body, retrieve_proc)
283
286
  else
284
- ThreadedInMemoryStrategy.result(json_body, retreive_proc, num_threads)
287
+ ThreadedInMemoryStrategy.result(json_body, retrieve_proc, num_threads)
285
288
  end
286
289
  end
287
290
 
288
- def retreive_partition_data(statement_handle, partition_index)
291
+ def retrieve_partition_data(statement_handle, partition_index)
289
292
  partition_response = nil
290
293
  connection_pool.with do |connection|
291
294
  partition_response = request_with_auth_and_headers(
@@ -1,3 +1,3 @@
1
1
  module RubySnowflake
2
- VERSION = "1.0.5"
2
+ VERSION = "1.1.0"
3
3
  end
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.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rinsed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-20 00:00:00.000000000 Z
11
+ date: 2024-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby