bigquery_migration 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +4 -0
- data/example/migrate_table.yml +1 -0
- data/example/table_info.yml +23 -0
- data/exe/bq-migrate +1 -0
- data/lib/bigquery_migration/action.rb +19 -0
- data/lib/bigquery_migration/bigquery_wrapper.rb +15 -3
- data/lib/bigquery_migration/schema.rb +1 -1
- data/lib/bigquery_migration/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fc953326453253906c139453f2bd5b7b95e09fd
|
4
|
+
data.tar.gz: e8e2d924b197c6f2b6ddbd4dc162c765396d13ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e207d801d7b5a20e241e95c76d391ddc8863cf42c319016ed84e97e226cf2247ad4bd0a452c09ec342725fdd1c92a39353032adb282ca218b2eb1cd4e211663
|
7
|
+
data.tar.gz: a6a6c3932945426f65641eebbc93cb0bda24150a33fd4456a5ebe4b372ab985312131e92c1eab5d9e122db4165682233f0a3f9341ceb8e57112fdf91f1418021
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -76,6 +76,10 @@ migrator.migrate_table(columns: columns)
|
|
76
76
|
# migrator.migrate_table(schema_file: '/path/to/schema.json')
|
77
77
|
```
|
78
78
|
|
79
|
+
## Further Details
|
80
|
+
|
81
|
+
* See [BigQueryテーブルのスキーマを変更する - sonots:blog](http://blog.livedoor.jp/sonots/archives/47294596.html) (Japanese)
|
82
|
+
|
79
83
|
## Development
|
80
84
|
|
81
85
|
### Run example:
|
data/example/migrate_table.yml
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
bigquery: &bigquery
|
2
|
+
json_keyfile: example/your-project-000.json
|
3
|
+
dataset: your_dataset_name
|
4
|
+
table: your_table_name
|
5
|
+
|
6
|
+
actions:
|
7
|
+
- action: create_dataset
|
8
|
+
<<: *bigquery
|
9
|
+
- action: migrate_table
|
10
|
+
<<: *bigquery
|
11
|
+
columns:
|
12
|
+
- { name: 'timestamp', type: 'TIMESTAMP' }
|
13
|
+
- name: 'record'
|
14
|
+
type: 'RECORD'
|
15
|
+
fields:
|
16
|
+
- { name: 'string', type: 'STRING' }
|
17
|
+
- { name: 'integer', type: 'INTEGER' }
|
18
|
+
- action: table_info
|
19
|
+
table: your_table_name
|
20
|
+
<<: *bigquery
|
21
|
+
- action: table_info
|
22
|
+
prefix: your_table_name
|
23
|
+
<<: *bigquery
|
data/exe/bq-migrate
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bq_migrate
|
@@ -41,6 +41,7 @@ class BigqueryMigration
|
|
41
41
|
preview
|
42
42
|
insert_select
|
43
43
|
copy_table
|
44
|
+
table_info
|
44
45
|
])
|
45
46
|
end
|
46
47
|
|
@@ -102,5 +103,23 @@ class BigqueryMigration
|
|
102
103
|
write_disposition: config[:write_disposition],
|
103
104
|
)
|
104
105
|
end
|
106
|
+
|
107
|
+
def table_info
|
108
|
+
if config[:prefix]
|
109
|
+
tables = client.list_tables[:tables].select {|table| table.start_with?(config[:prefix]) }
|
110
|
+
table_infos = tables.map do |table|
|
111
|
+
result = client.get_table(table: table)
|
112
|
+
result.delete(:responses)
|
113
|
+
result
|
114
|
+
end
|
115
|
+
result = {
|
116
|
+
sum_num_bytes: table_infos.map {|info| info[:num_bytes].to_i }.inject(:+),
|
117
|
+
sum_num_rows: table_infos.map {|info| info[:num_rows].to_i }.inject(:+),
|
118
|
+
table_infos: table_infos,
|
119
|
+
}
|
120
|
+
else
|
121
|
+
client.get_table
|
122
|
+
end
|
123
|
+
end
|
105
124
|
end
|
106
125
|
end
|
@@ -182,8 +182,20 @@ class BigqueryMigration
|
|
182
182
|
response = {status_code: e.status_code, message: e.message, error_class: e.class}
|
183
183
|
raise Error, "Failed to get_table(#{project}, #{dataset}, #{table}), response:#{response}"
|
184
184
|
end
|
185
|
-
|
186
|
-
|
185
|
+
|
186
|
+
result = {}
|
187
|
+
if response
|
188
|
+
result = {
|
189
|
+
table_id: response.id,
|
190
|
+
creation_time: response.creation_time.to_i, # millisec
|
191
|
+
last_modified_time: response.last_modified_time.to_i, # millisec
|
192
|
+
location: response.location,
|
193
|
+
num_bytes: response.num_bytes.to_i,
|
194
|
+
num_rows: response.num_rows.to_i,
|
195
|
+
}
|
196
|
+
end
|
197
|
+
|
198
|
+
result.merge!({ responses: { get_table: response } })
|
187
199
|
end
|
188
200
|
|
189
201
|
def insert_table(dataset: nil, table: nil, columns: )
|
@@ -262,7 +274,7 @@ class BigqueryMigration
|
|
262
274
|
end
|
263
275
|
rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e
|
264
276
|
if e.status_code == 404 && /Not found:/ =~ e.message
|
265
|
-
|
277
|
+
raise NotFoundError, "Dataset #{project}:#{dataset} is not found"
|
266
278
|
end
|
267
279
|
|
268
280
|
response = {status_code: e.status_code, message: e.message, error_class: e.class}
|
@@ -4,7 +4,7 @@ require_relative 'error'
|
|
4
4
|
|
5
5
|
class BigqueryMigration
|
6
6
|
class Schema < ::Array
|
7
|
-
ALLOWED_FIELD_TYPES = Set.new(['STRING', 'INTEGER', 'FLOAT', 'BOOLEAN', 'RECORD', 'TIMESTAMP'])
|
7
|
+
ALLOWED_FIELD_TYPES = Set.new(['STRING', 'INTEGER', 'FLOAT', 'BOOLEAN', 'RECORD', 'TIMESTAMP', 'BYTES'])
|
8
8
|
ALLOWED_FIELD_MODES = Set.new(['NULLABLE', 'REQUIRED', 'REPEATED'])
|
9
9
|
|
10
10
|
def initialize(columns = [])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigquery_migration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-api-client
|
@@ -126,6 +126,7 @@ description: Migrate BigQuery table schema.
|
|
126
126
|
email:
|
127
127
|
- sonots@gmail.com
|
128
128
|
executables:
|
129
|
+
- bq-migrate
|
129
130
|
- bq_migrate
|
130
131
|
extensions: []
|
131
132
|
extra_rdoc_files: []
|
@@ -147,6 +148,8 @@ files:
|
|
147
148
|
- example/insert_select.yml
|
148
149
|
- example/migrate_table.yml
|
149
150
|
- example/schema.json
|
151
|
+
- example/table_info.yml
|
152
|
+
- exe/bq-migrate
|
150
153
|
- exe/bq_migrate
|
151
154
|
- lib/bigquery_migration.rb
|
152
155
|
- lib/bigquery_migration/action.rb
|