sequel-bigquery 0.5.0 → 0.6.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: c37139c40fd486391d9d16ab147430352b67a1a2b5a55f7eed4189c368b5e87a
4
- data.tar.gz: e3753842a9727cf53451ff80ac9abc250343a719d4215ab368c5a93a9d2b4830
3
+ metadata.gz: 6c15547bd0bbe53a384a987286cda32f9e1ad624c2c9e5339ac412322e810653
4
+ data.tar.gz: 26d87c1ff3d3aecf9d5401de88ad9048a239dd65bc3a682cfbb9d9d726675b9f
5
5
  SHA512:
6
- metadata.gz: 6189f0b53a6edd9d66c915316ce8e9e8c836181609405b54e246c0dbe5451bce995c6f5b73e7b320624c35b62bfd66874757734f839ef7f9023dbc099271b2a4
7
- data.tar.gz: 715b5adbdb6e225ca9af37363fbc30b59bde54a0b4602d91afcca93506cac541d252b31767571605ee555f2fdaad8d316ccf67a083354bfdcc9cd5f925c51646
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
- We've found that the `google-cloud-bigquery` gem seems to have a bug where an internal lack of result value results in a `NoMethodError` on nil for `fields` within `from_gapi_json`. [See issue #6](https://github.com/ZimbiX/sequel-bigquery/issues/6#issuecomment-968523731). As a workaround, all generated statements within `alter_table` are joined together with `;` and executed only at the end of the block. A `select 1` is also appended to try to ensure we have a result to avoid the aforementioned exception. A bonus of batching the queries is that the latency should be somewhat reduced.
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
 
@@ -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, ArgumentError => e
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
- # Batch the alter table queries and make sure something is returned to avoid an error related to the return value
214
- def apply_alter_table(name, ops)
215
- sqls = alter_table_sql_list(name, ops)
216
- sqls_joined = (sqls + ['select 1']).join(";\n")
217
- execute_ddl(sqls_joined)
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sequel
4
4
  module Bigquery
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-bigquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Weibrecht