bigquery_migration 0.1.0.pre5 → 0.1.0.pre6

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
  SHA1:
3
- metadata.gz: a97b4467ac7f590ebcdfc72191270b67670a50a2
4
- data.tar.gz: 00e9d766e4234ef79a67464dd69d30f7619376a4
3
+ metadata.gz: 7f59228af936baf7e4dab8f4e065f24945f47c26
4
+ data.tar.gz: 7fa846a9830ec47617e92b76899adba0a8ad1891
5
5
  SHA512:
6
- metadata.gz: 4a69066ad64ce36003930f62e260db450d86482e8a05a37c6cc0e44cb71634f2db00fef4f85c6733aab055d0df6b74a1e1b21f50b66c2ff6d7ca7416bf8ef891
7
- data.tar.gz: 73c7c9260f997a53dd6920c695b84ade0a422ea6cf079043cd6b9d2f2f6b991d1e4404362c6b9eb5f70da664904175481a21fa5e3ddcdfd623b8793e1309f041
6
+ metadata.gz: 63474dac494bc19b8041255d43cb1f8c20513379bf397c30b5390dba30aa59ff3e3db9193841af9b713a73aecccda305b32c73c88ca41337f6e2df6cdfa185dd
7
+ data.tar.gz: a0c74a1689507a38b6194393e691b3fcdcbd3a82b9e62b9f0e3bd93713d5d6f28a857b1610ef7bacec9f168aabbc5f2103956dd70568afa8e15e5b44c8025ea1
@@ -0,0 +1,20 @@
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: copy_table
19
+ <<: *bigquery
20
+ destination_table: your_table_name_copy
@@ -0,0 +1 @@
1
+ migrate_table.yml
@@ -0,0 +1,21 @@
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: insert_select
19
+ <<: *bigquery
20
+ destination_table: your_table_name_insert_select
21
+ query: select * from [your_dataset_name.your_table_name]
@@ -0,0 +1,22 @@
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: migrate_table
19
+ <<: *bigquery
20
+ schema_file: example/schema.json
21
+ - action: delete_table
22
+ <<: *bigquery
@@ -39,6 +39,8 @@ class BigqueryMigration
39
39
  migrate_table
40
40
  insert
41
41
  preview
42
+ insert_select
43
+ copy_table
42
44
  ])
43
45
  end
44
46
 
@@ -81,5 +83,24 @@ class BigqueryMigration
81
83
  def preview
82
84
  client.list_table_data(max_results: config[:max_results])
83
85
  end
86
+
87
+ def copy_table
88
+ client.copy_table(
89
+ destination_table: config[:destination_table],
90
+ destination_dataset: config[:destination_dataset],
91
+ source_table: config[:source_table],
92
+ source_dataset: config[:source_dataset],
93
+ write_disposition: config[:write_disposition],
94
+ )
95
+ end
96
+
97
+ def insert_select
98
+ client.insert_select(
99
+ query: config[:query],
100
+ destination_table: config[:destination_table],
101
+ destination_dataset: config[:destination_dataset],
102
+ write_disposition: config[:write_disposition],
103
+ )
104
+ end
84
105
  end
85
106
  end
@@ -107,6 +107,9 @@ class BigqueryMigration
107
107
  begin
108
108
  result = get_table
109
109
  response = result[:responses][:get_table]
110
+ return [] unless response
111
+ return [] unless response.schema
112
+ return [] unless response.schema.fields
110
113
  response.schema.fields.map {|column| column.to_h }
111
114
  rescue NotFoundError
112
115
  return []
@@ -470,10 +473,11 @@ class BigqueryMigration
470
473
  end
471
474
  alias :add_column :patch_table
472
475
 
473
- def copy_table(destination_table:, destination_dataset: nil, source_table: nil, source_dataset: nil, write_disposition: 'WRITE_TRUNCATE')
476
+ def copy_table(destination_table:, destination_dataset: nil, source_table: nil, source_dataset: nil, write_disposition: nil)
474
477
  source_table ||= self.table
475
478
  source_dataset ||= self.dataset
476
479
  destination_dataset ||= source_dataset
480
+ write_disposition ||= 'WRITE_TRUNCATE'
477
481
 
478
482
  body = {
479
483
  configuration: {
@@ -509,9 +513,10 @@ class BigqueryMigration
509
513
  }
510
514
  end
511
515
 
512
- def insert_select(query:, destination_table: nil, destination_dataset: nil, write_disposition: 'WRITE_TRUNCATE')
516
+ def insert_select(query:, destination_table: nil, destination_dataset: nil, write_disposition: nil)
513
517
  destination_table ||= self.table
514
518
  destination_dataset ||= self.dataset
519
+ write_disposition ||= 'WRITE_TRUNCATE'
515
520
 
516
521
  body = {
517
522
  configuration: {
@@ -1,3 +1,3 @@
1
1
  class BigqueryMigration
2
- VERSION = "0.1.0.pre5"
2
+ VERSION = "0.1.0.pre6"
3
3
  end
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.0.pre5
4
+ version: 0.1.0.pre6
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-03-26 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -141,7 +141,10 @@ files:
141
141
  - bigquery_migration.gemspec
142
142
  - bin/console
143
143
  - bin/setup
144
+ - example/copy_table.yml
144
145
  - example/example.yml
146
+ - example/insert_select.yml
147
+ - example/migrate_table.yml
145
148
  - example/schema.json
146
149
  - exe/bq_migrate
147
150
  - lib/bigquery_migration.rb
data/example/example.yml DELETED
@@ -1,22 +0,0 @@
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: migrate_table
19
- <<: *bigquery
20
- schema_file: example/schema.json
21
- - action: delete_table
22
- <<: *bigquery