sequel-bigquery 0.1.1 → 0.4.1
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 +3 -0
- data/lib/sequel-bigquery.rb +30 -2
- data/lib/sequel_bigquery/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 288cbe303c3db264ccc9e71f7c39c63185428056bfebfe67e1cb520ddeef5243
|
4
|
+
data.tar.gz: 583b3d835d03762ef0ba1ba821d6545032db97202a672b4cd08be9cd50e134d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
```
|
data/lib/sequel-bigquery.rb
CHANGED
@@ -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)
|
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.
|
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-
|
11
|
+
date: 2021-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|