sequel-bigquery 0.5.0 → 0.6.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/README.md +13 -1
- data/lib/sequel-bigquery.rb +29 -7
- data/lib/sequel_bigquery/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: 6c15547bd0bbe53a384a987286cda32f9e1ad624c2c9e5339ac412322e810653
|
4
|
+
data.tar.gz: 26d87c1ff3d3aecf9d5401de88ad9048a239dd65bc3a682cfbb9d9d726675b9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daa23d28fc8359540d61e57a5f4087f76da68045e6535d864f711c51d8fd0517bf9d74e332ea9cd3a5399ece489beb06df08dfaf409caf8877a1cf6aaa8140a3
|
7
|
+
data.tar.gz: eb73f36dbe0317d42e5b1fd9a774dd7d5440d36a8ddebd33c5683a67723efaf5538d4b915a4b518e49a6165854b42152762d57934a57dd050efee0f735563c4f
|
data/README.md
CHANGED
@@ -17,7 +17,9 @@ Beyond migrations, I'm unsure how useful this gem is. I haven't yet tested what
|
|
17
17
|
- [Creating tables with column defaults](#creating-tables-with-column-defaults)
|
18
18
|
- [Transactions](#transactions)
|
19
19
|
- [Update statements without `WHERE`](#update-statements-without-where)
|
20
|
+
- [Combining statements](#combining-statements)
|
20
21
|
- [Alter table](#alter-table)
|
22
|
+
- [Column recreation](#column-recreation)
|
21
23
|
- [Installation](#installation)
|
22
24
|
- [Usage](#usage)
|
23
25
|
- [Contributing](#contributing)
|
@@ -65,9 +67,19 @@ BigQuery doesn't support transactions where the statements are executed individu
|
|
65
67
|
|
66
68
|
BigQuery requires all `UPDATE` statement to have a `WHERE` clause. As a workaround, statements which lack one have `where 1 = 1` appended automatically (crudely).
|
67
69
|
|
70
|
+
### Combining statements
|
71
|
+
|
72
|
+
When combining multiple statements into one query (with `;`), and the final statement is not a `SELECT`, the `google-cloud-bigquery` gem has a [bug](https://github.com/googleapis/google-cloud-ruby/issues/9617) which causes an exception. Note that all the statements have been executed when this happens. A workaround is to append `; SELECT 1`.
|
73
|
+
|
68
74
|
### Alter table
|
69
75
|
|
70
|
-
|
76
|
+
BigQuery [rate-limits alter table statements](https://cloud.google.com/bigquery/quotas#dataset_limits) to 10 per second. This is mitigated somewhat by Sequel combining `ALTER TABLE` statements whenever possible, and BigQuery having extremely high latency (\~2 seconds per query); but you may still run into this limitation.
|
77
|
+
|
78
|
+
We've also noticed a bug with `google-cloud-bigquery` where an `ALTER TABLE` statement resulted in a `NoMethodError` on nil for `fields` within `from_gapi_json`. We're not yet sure what caused this.
|
79
|
+
|
80
|
+
### Column recreation
|
81
|
+
|
82
|
+
Be careful when deleting a column which you might want to re-add. BigQuery reserves the name of a deleted column for up to the time travel duration - which is [*seven days*](https://cloud.google.com/bigquery/docs/time-travel). Re-creating the entire dataset is a painful workaround.
|
71
83
|
|
72
84
|
## Installation
|
73
85
|
|
data/lib/sequel-bigquery.rb
CHANGED
@@ -78,9 +78,10 @@ module Sequel
|
|
78
78
|
warn("Warning: Will now execute entire buffered transaction:\n" + @sql_buffer.join("\n"))
|
79
79
|
end
|
80
80
|
|
81
|
+
sql_to_execute = @sql_buffer.any? ? @sql_buffer.join("\n") : sql
|
82
|
+
|
81
83
|
synchronize(opts[:server]) do |conn|
|
82
84
|
results = log_connection_yield(sql, conn) do
|
83
|
-
sql_to_execute = @sql_buffer.any? ? @sql_buffer.join("\n") : sql
|
84
85
|
conn.query(sql_to_execute)
|
85
86
|
end
|
86
87
|
log_each(:debug, results.awesome_inspect)
|
@@ -89,7 +90,19 @@ module Sequel
|
|
89
90
|
else
|
90
91
|
results
|
91
92
|
end
|
92
|
-
rescue Google::Cloud::InvalidArgumentError,
|
93
|
+
rescue Google::Cloud::InvalidArgumentError, Google::Cloud::PermissionDeniedError => e
|
94
|
+
if e.message.include?('too many table update operations for this table')
|
95
|
+
warn('Triggered rate limit of table update operations for this table. For more information, see https://cloud.google.com/bigquery/docs/troubleshoot-quotas')
|
96
|
+
if retryable_query?(sql_to_execute)
|
97
|
+
warn('Detected retryable query - re-running query after a 1 second sleep')
|
98
|
+
sleep 1
|
99
|
+
retry
|
100
|
+
else
|
101
|
+
log_each(:error, "Query not detected as retryable; can't automatically recover from being rate-limited")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
raise_error(e)
|
105
|
+
rescue ArgumentError => e
|
93
106
|
raise_error(e)
|
94
107
|
end # rubocop:disable Style/MultilineBlockChain
|
95
108
|
.tap do
|
@@ -210,11 +223,20 @@ module Sequel
|
|
210
223
|
sql
|
211
224
|
end
|
212
225
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
226
|
+
def supports_combining_alter_table_ops?
|
227
|
+
true
|
228
|
+
end
|
229
|
+
|
230
|
+
def retryable_query?(sql)
|
231
|
+
single_statement_query?(sql) && alter_table_query?(sql)
|
232
|
+
end
|
233
|
+
|
234
|
+
def single_statement_query?(sql)
|
235
|
+
!sql.rstrip.chomp(';').include?(';')
|
236
|
+
end
|
237
|
+
|
238
|
+
def alter_table_query?(sql)
|
239
|
+
sql.match?(/\Aalter table /i)
|
218
240
|
end
|
219
241
|
end
|
220
242
|
|