sequel-bigquery 0.1.1 → 0.4.1

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: c5943f6638cf7c58e4eeee545d11bc8730f37a4724cda51e6f1000d496f6c49f
4
- data.tar.gz: 3ccaff19ff790f4840a747efa8cb1c4b7289c0a7b60bed6fb998aa989be1fcf9
3
+ metadata.gz: 288cbe303c3db264ccc9e71f7c39c63185428056bfebfe67e1cb520ddeef5243
4
+ data.tar.gz: 583b3d835d03762ef0ba1ba821d6545032db97202a672b4cd08be9cd50e134d9
5
5
  SHA512:
6
- metadata.gz: 7e9b48c5f94af9dbd49048eb8e7ee6dc81d8927f6c62d2806c12111caf23e9f868e7bf571ad2444d81efc2c61bf6778daf872d4ff928e285e042ccad0c1aeaa2
7
- data.tar.gz: be45afe3bedabb2888f3149553acee7d7ebd3e4ee3cafbe8ebbb40594df8c8bc43775937d5440e116c51ace191909192d88ad801d0bf9c62cf97568f42d6b769
6
+ metadata.gz: 2691185b162d701bc1c8d78acbb0ea7624716a10612eedbbcf5c4feb0d04f34b6ef5f7c1e8936052d3ab28a6196a75613c8c09aaa7713245105ddc989f0a1266
7
+ data.tar.gz: e642c036248215c810e2c066b37f5864d753fa0ad52cb0352538c661e7ec41b475cf43cb5a0b7220d0410402e6b2100e02b1b4411ce4c2c8fd7511b810a7c928
data/README.md CHANGED
@@ -31,6 +31,7 @@ Features:
31
31
  - Updating rows, with automatic addition of `where 1 = 1` to statements (since BigQuery requires a `where` clause)
32
32
  - Querying
33
33
  - Transactions (buffered since BigQuery only supports them when you execute the whole transaction at once)
34
+ - Table partitioning
34
35
  - Ruby types:
35
36
  + String
36
37
  + Integer
@@ -39,6 +40,7 @@ Features:
39
40
  + Date
40
41
  + Float
41
42
  + BigDecimal
43
+ - Selecting the BigQuery server location
42
44
 
43
45
  ## Installation
44
46
 
@@ -71,6 +73,7 @@ db = Sequel.connect(
71
73
  adapter: :bigquery,
72
74
  project: 'your-gcp-project',
73
75
  database: 'your_bigquery_dataset_name',
76
+ location: 'australia-southeast2',
74
77
  logger: Logger.new(STDOUT),
75
78
  )
76
79
  ```
@@ -29,12 +29,13 @@ module Sequel
29
29
  config = @orig_opts.dup
30
30
  config.delete(:adapter)
31
31
  config.delete(:logger)
32
+ location = config.delete(:location)
32
33
  bq_dataset_name = config.delete(:dataset) || config.delete(:database)
33
34
  @bigquery = Google::Cloud::Bigquery.new(config)
34
35
  # ObjectSpace.each_object(HTTPClient).each { |c| c.debug_dev = STDOUT }
35
36
  @bigquery.dataset(bq_dataset_name) || begin
36
37
  @loggers[0].debug('BigQuery dataset %s does not exist; creating it' % bq_dataset_name)
37
- @bigquery.create_dataset(bq_dataset_name)
38
+ @bigquery.create_dataset(bq_dataset_name, location: location)
38
39
  end
39
40
  .tap { puts '#connect end' }
40
41
  end
@@ -44,6 +45,17 @@ module Sequel
44
45
  # c.disconnect
45
46
  end
46
47
 
48
+ def drop_datasets(*dataset_names_to_drop)
49
+ dataset_names_to_drop.each do |dataset_name_to_drop|
50
+ puts "Dropping dataset #{dataset_name_to_drop.inspect}"
51
+ dataset_to_drop = @bigquery.dataset(dataset_name_to_drop)
52
+ next unless dataset_to_drop
53
+ dataset_to_drop.tables.each(&:delete)
54
+ dataset_to_drop.delete
55
+ end
56
+ end
57
+ alias drop_dataset drop_datasets
58
+
47
59
  def execute(sql, opts = OPTS) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
48
60
  puts '#execute'
49
61
  log_query(sql)
@@ -163,6 +175,22 @@ module Sequel
163
175
  'Note that no result data is returned while the transaction is open.',
164
176
  )
165
177
  end
178
+
179
+ # SQL for creating a table with BigQuery specific options
180
+ def create_table_sql(name, generator, options)
181
+ "#{super}#{create_table_suffix_sql(name, options)}"
182
+ end
183
+
184
+ # Handle BigQuery specific table extensions (i.e. partitioning)
185
+ def create_table_suffix_sql(_name, options)
186
+ sql = +''
187
+
188
+ if (partition_by = options[:partition_by])
189
+ sql << " PARTITION BY #{literal(Array(partition_by))}"
190
+ end
191
+
192
+ sql
193
+ end
166
194
  end
167
195
 
168
196
  class Dataset < Sequel::Dataset
@@ -193,7 +221,7 @@ module Sequel
193
221
 
194
222
  # Like MySQL, BigQuery uses the nonstandard ` (backtick) for quoting identifiers.
195
223
  def quoted_identifier_append(sql, c)
196
- sql << '`%s`' % c
224
+ sql << ('`%s`' % c)
197
225
  end
198
226
 
199
227
  def input_identifier(v)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sequel
4
4
  module Bigquery
5
- VERSION = '0.1.1'
5
+ VERSION = '0.4.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-bigquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Weibrecht
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-14 00:00:00.000000000 Z
11
+ date: 2021-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print