bigbroda 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.pryrc +3 -0
  4. data/.rspec +2 -0
  5. data/.rvmrc +1 -0
  6. data/Gemfile +18 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +408 -0
  9. data/Rakefile +12 -0
  10. data/google_bigquery.gemspec +30 -0
  11. data/lib/.DS_Store +0 -0
  12. data/lib/active_record/.DS_Store +0 -0
  13. data/lib/active_record/connection_adapters/bigquery_adapter.rb +949 -0
  14. data/lib/active_record/tasks/bigquery_database_tasks.rb +42 -0
  15. data/lib/generators/.DS_Store +0 -0
  16. data/lib/generators/google_bigquery/.DS_Store +0 -0
  17. data/lib/generators/google_bigquery/install/install_generator.rb +21 -0
  18. data/lib/generators/templates/README +11 -0
  19. data/lib/generators/templates/bigquery.rb.erb +7 -0
  20. data/lib/google_bigquery/auth.rb +27 -0
  21. data/lib/google_bigquery/client.rb +52 -0
  22. data/lib/google_bigquery/config.rb +17 -0
  23. data/lib/google_bigquery/dataset.rb +77 -0
  24. data/lib/google_bigquery/engine.rb +21 -0
  25. data/lib/google_bigquery/jobs.rb +173 -0
  26. data/lib/google_bigquery/project.rb +16 -0
  27. data/lib/google_bigquery/railtie.rb +39 -0
  28. data/lib/google_bigquery/table.rb +63 -0
  29. data/lib/google_bigquery/table_data.rb +23 -0
  30. data/lib/google_bigquery/version.rb +3 -0
  31. data/lib/google_bigquery.rb +27 -0
  32. data/spec/.DS_Store +0 -0
  33. data/spec/dummy/.DS_Store +0 -0
  34. data/spec/dummy/.gitignore +20 -0
  35. data/spec/dummy/README.rdoc +261 -0
  36. data/spec/dummy/Rakefile +7 -0
  37. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  38. data/spec/dummy/app/assets/stylesheets/application.css.scss +13 -0
  39. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  40. data/spec/dummy/app/helpers/application_helper.rb +3 -0
  41. data/spec/dummy/app/mailers/.gitkeep +0 -0
  42. data/spec/dummy/app/models/log_data.rb +3 -0
  43. data/spec/dummy/app/models/post.rb +3 -0
  44. data/spec/dummy/app/models/user.rb +4 -0
  45. data/spec/dummy/app/views/layouts/application.html.haml +32 -0
  46. data/spec/dummy/config/application.rb +23 -0
  47. data/spec/dummy/config/boot.rb +11 -0
  48. data/spec/dummy/config/database.yml +32 -0
  49. data/spec/dummy/config/environment.rb +6 -0
  50. data/spec/dummy/config/environments/development.rb +29 -0
  51. data/spec/dummy/config/environments/production.rb +80 -0
  52. data/spec/dummy/config/environments/test.rb +36 -0
  53. data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
  54. data/spec/dummy/config/initializers/bigquery.rb +19 -0
  55. data/spec/dummy/config/initializers/inflections.rb +16 -0
  56. data/spec/dummy/config/initializers/mime_types.rb +6 -0
  57. data/spec/dummy/config/initializers/secret_token.rb +8 -0
  58. data/spec/dummy/config/initializers/session_store.rb +9 -0
  59. data/spec/dummy/config/initializers/wrap_parameters.rb +15 -0
  60. data/spec/dummy/config/locales/devise.en.yml +58 -0
  61. data/spec/dummy/config/locales/en.yml +5 -0
  62. data/spec/dummy/config/locales/simple_form.en.yml +26 -0
  63. data/spec/dummy/config/routes.rb +4 -0
  64. data/spec/dummy/config.ru +4 -0
  65. data/spec/dummy/db/migrate/20140224051640_create_users.rb +11 -0
  66. data/spec/dummy/db/migrate/20140224063709_add_last_name_to_user.rb +5 -0
  67. data/spec/dummy/db/migrate/20140225014314_create_log_data.rb +12 -0
  68. data/spec/dummy/db/migrate/20140227015551_create_posts.rb +9 -0
  69. data/spec/dummy/db/schema.rb +39 -0
  70. data/spec/dummy/db/schema_migrations.json +1 -0
  71. data/spec/dummy/lib/assets/.gitkeep +0 -0
  72. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  73. data/spec/dummy/log/.gitkeep +0 -0
  74. data/spec/dummy/public/404.html +26 -0
  75. data/spec/dummy/public/422.html +26 -0
  76. data/spec/dummy/public/500.html +25 -0
  77. data/spec/dummy/public/favicon.ico +0 -0
  78. data/spec/dummy/script/rails +6 -0
  79. data/spec/dummy/test/fixtures/log_data.yml +9 -0
  80. data/spec/dummy/test/fixtures/posts.yml +11 -0
  81. data/spec/dummy/test/fixtures/users.yml +11 -0
  82. data/spec/dummy/test/models/log_data_test.rb +7 -0
  83. data/spec/dummy/test/models/post_test.rb +7 -0
  84. data/spec/dummy/test/models/user_test.rb +7 -0
  85. data/spec/fixtures/.DS_Store +0 -0
  86. data/spec/fixtures/configs/account_config.yml-example +6 -0
  87. data/spec/fixtures/keys/.DS_Store +0 -0
  88. data/spec/fixtures/keys/example-privatekey-p12 +0 -0
  89. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/.DS_Store +0 -0
  90. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/adapter/simple_quering.yml +324 -0
  91. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/after_each.yml +154 -0
  92. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/authorize_config.yml +367 -0
  93. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/create_each.yml +195 -0
  94. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/migrations/_down/adds_the_email_at_utc_hour_column.yml +575 -0
  95. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/migrations/_up/adds_the_created_at_updated_at_column.yml +644 -0
  96. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/migrations/add_column/adds_published_column.yml +779 -0
  97. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/migrations/associations/users_posts.yml +1464 -0
  98. data/spec/fixtures/vcr_cassettes/ActiveRecord_Adapter/migrations/remove_column/should_raise_error.yml +713 -0
  99. data/spec/fixtures/vcr_cassettes/Dataset/_list.yml +64 -0
  100. data/spec/fixtures/vcr_cassettes/Dataset/authorize_config.yml +367 -0
  101. data/spec/fixtures/vcr_cassettes/Dataset/operations/_get_delete.yml +237 -0
  102. data/spec/fixtures/vcr_cassettes/Dataset/operations/_patch_delete.yml +240 -0
  103. data/spec/fixtures/vcr_cassettes/Dataset/operations/_update_delete.yml +297 -0
  104. data/spec/fixtures/vcr_cassettes/Dataset/operations/create_delete.yml +173 -0
  105. data/spec/fixtures/vcr_cassettes/Project/_list.yml +64 -0
  106. data/spec/fixtures/vcr_cassettes/Project/authorize_config.yml +2166 -0
  107. data/spec/fixtures/vcr_cassettes/Table/authorize_config.yml +367 -0
  108. data/spec/fixtures/vcr_cassettes/Table/operations/creation_edition/_create_delete.yml +404 -0
  109. data/spec/fixtures/vcr_cassettes/Table/operations/creation_edition/_create_update_delete.yml +471 -0
  110. data/spec/fixtures/vcr_cassettes/Table/operations/list.yml +232 -0
  111. data/spec/fixtures/vcr_cassettes/TableData/authorize_config.yml +2166 -0
  112. data/spec/fixtures/vcr_cassettes/TableData/create_each.yml +135 -0
  113. data/spec/fixtures/vcr_cassettes/TableData/delete_each.yml +154 -0
  114. data/spec/fixtures/vcr_cassettes/TableData/insertAll2.yml +189 -0
  115. data/spec/fixtures/vcr_cassettes/auth.yml +2168 -0
  116. data/spec/fixtures/vcr_cassettes/authorize_config.yml +2166 -0
  117. data/spec/fixtures/vcr_cassettes/datasets.yml +119 -0
  118. data/spec/fixtures/vcr_cassettes/delete_each_dataset.yml +48 -0
  119. data/spec/functional/adapter/adapter_spec.rb +213 -0
  120. data/spec/functional/auth_spec.rb +24 -0
  121. data/spec/functional/client_spec.rb +9 -0
  122. data/spec/functional/config_spec.rb +24 -0
  123. data/spec/functional/dataset_spec.rb +77 -0
  124. data/spec/functional/project_spec.rb +24 -0
  125. data/spec/functional/table_data_spec.rb +61 -0
  126. data/spec/functional/table_spec.rb +105 -0
  127. data/spec/models/user_spec.rb +0 -0
  128. data/spec/spec_helper.rb +48 -0
  129. data/spec/support/models.rb +11 -0
  130. data/spec/support/schema.rb +43 -0
  131. metadata +370 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a85336962baf88e59b45231a837fba8593239d8c
4
+ data.tar.gz: 740fe4fe305e177e8211e89fcf4a678d03f5a26c
5
+ SHA512:
6
+ metadata.gz: a8e82dbbc195c43b093a26e0d1e166d68cc18f6c819a41b7ea486b0f80e4ec044259fc9971a85c8ba160671a5ea03786f331878d97454c5e15cb984c627096ec
7
+ data.tar.gz: 2bcb219c097c31424e136b1a44c498803e730b9132656968f33ac2ed642c83b4d6dc33224428df6655406fddd3ee1bf9b72ba89a48e3726134bfa59d6ff59ec5
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ spec/fixtures/configs/account_config.yml
19
+ spec/fixtures/keys/*.p12
20
+
21
+ spec/dummy/db/*.sqlite3
22
+ spec/dummy/db/*.sqlite3-journal
23
+ spec/dummy/log/*.log
24
+ spec/dummy/tmp/
25
+ spec/dummy/.sass-cache
data/.pryrc ADDED
@@ -0,0 +1,3 @@
1
+ Pry.commands.alias_command 'c', 'continue'
2
+ Pry.commands.alias_command 's', 'step'
3
+ Pry.commands.alias_command 'n', 'next'
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 2.0.0@bigquery --create
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in google_bigquery.gemspec
4
+ gemspec
5
+
6
+ gem "certified"
7
+ gem "debugger"
8
+ gem "pry"
9
+ gem 'pry-remote'
10
+ gem 'pry-nav'
11
+ gem 'sqlite3'
12
+
13
+ group :test do
14
+ gem "rspec"
15
+ gem 'vcr'
16
+ gem 'webmock', '1.16.0', require: false
17
+ end
18
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 miguel michelson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,408 @@
1
+ # GoogleBigquery
2
+
3
+ GoogleBig Query ActiveRecord Adapter & standalone API client
4
+
5
+ ## Use Cases:
6
+
7
+ https://developers.google.com/bigquery/what-is-bigquery
8
+
9
+ BigQuery is fantastic for running ad hoc aggregate queries across a very very large dataset - large web logs, ad analysis, sensor data, sales data... etc. Basically, many kinds of "full table scan" queries. Queries are written in a SQL-style language (you don't have to write custom MapReduce functions).
10
+
11
+ But!, Bigquery has a constraint to consider before diving in,
12
+ BQ is append only , that means that you can't update records or delete them.
13
+
14
+ So, use BigQuery as an OLAP (Online Analytical Processing) service, not as OLTP (Online Transactional Processing). In other words, use BigQuery as a DataWareHouse.
15
+
16
+ ## Installation
17
+
18
+ Add 'google_bigquery' to your application's Gemfile or install it yourself as:
19
+
20
+ $ gem install google_bigquery
21
+
22
+ ## Rails / ActiveRecord:
23
+
24
+ #### Configure GoogleBigQuery:
25
+
26
+ rails g google_bigquery:install
27
+
28
+ Or generate a file in config/initializers/bigquery.rb with the following contents:
29
+
30
+ ```ruby
31
+ GoogleBigquery::Config.setup do |config|
32
+ config.pass_phrase = ["pass_phrase"]
33
+ config.key_file = ["key_file"]
34
+ config.client_id = ["client_id"]
35
+ config.scope = ["scope"]
36
+ config.email = ["email"]
37
+ end
38
+ ```
39
+
40
+ ### Active Record Adapter
41
+
42
+ #### Connection
43
+
44
+ ActiveRecord connection in plain ruby:
45
+
46
+ ```ruby
47
+ ActiveRecord::Base.establish_connection(
48
+ :adapter => 'bigquery',
49
+ :project => "MyBigQueryProject",
50
+ :database => "MyBigTable"
51
+ )
52
+ ```
53
+
54
+ In Rails app you can use the :adapter, :project and :database options in your database.yml or use the ```establish_bq_connection(bq_connection)``` connection in specific models.
55
+
56
+ ```yaml
57
+ development:
58
+ adapter: sqlite3
59
+ database: db/development.sqlite3
60
+ pool: 5
61
+
62
+ bigquery:
63
+ database: "dummy_dev"
64
+ adapter: 'bigquery'
65
+ project: 123456
66
+ #database: "dummy_test"
67
+ ```
68
+
69
+ By default if you set the development/production/test BD configuration as a bigquery connection all models are Bigquery, migrations and rake:db operations use the BigQuery migration system.
70
+
71
+ If you don't want to make all your models BigQuery you can set up specific BQ activeRecord models this way:
72
+
73
+ ```ruby
74
+ class UserLog < ActiveRecord::Base
75
+ establish_bq_connection "bigquery"
76
+ end
77
+ ```
78
+
79
+ Then you will have to execute the migration programaticly. like this:
80
+
81
+ ```ruby
82
+ UserMigration.up
83
+ ```
84
+ or
85
+
86
+ ```ruby
87
+ AddPublishedToUser.change
88
+ ```
89
+
90
+ #### Quering
91
+
92
+ The GoogleBigQuery Adapter brings some of the ActiveRecord nicieties out of the box:
93
+
94
+ ```ruby
95
+ User.all
96
+ User.first, User.last
97
+ User.count
98
+ User.find_by(name: "")
99
+ User.select("name")
100
+ User.select("name").where("name contains ?", "frank")
101
+ User.select("name, id").where("name contains ?", "frank").count
102
+ User.where("id =? and name= ?", "some-id-1393025921", "Frank")
103
+ User.where.not("admin = ?", false)
104
+ User.admins.joins(:posts)
105
+ ```
106
+
107
+ #### Note about Joins:
108
+
109
+ BigQuery supports two types of JOIN operations:
110
+
111
+ + JOIN requires that the right-side table contains less than 8 MB of compressed data.
112
+ + JOIN EACH allows join queries for tables of any size.
113
+
114
+ BigQuery supports INNER and LEFT OUTER joins. The default is INNER.
115
+
116
+ see more at: https://developers.google.com/bigquery/query-reference#joins
117
+
118
+
119
+
120
+ #### Creation:
121
+
122
+ ```ruby
123
+ User.create(name: "frank capra")
124
+ @user = User.new
125
+ @user.name = "Frank"
126
+ @user.save
127
+ ```
128
+
129
+ NOTE: by default the adapter will set Id values as an SecureRandom.hex, and for now all the foreign keys are created as a STRING type
130
+
131
+ #### Deletion and edition of single rows:
132
+
133
+ BigQuery tables are append-only. The query language does not currently support either updating or deleting data. In order to update or delete data, you must delete the table, then recreate the table with new data. Alternatively, you could write a query that modifies the data and specify a new results table.
134
+
135
+ I would actually recommend creating a new table for each day. Since BigQuery charges by amount of data queried over, this would be most economical for you, rather than having to query over entire massive datasets every time.
136
+
137
+ By the way - how are you currently collecting your data?
138
+
139
+
140
+ ### Massive Export / Import of data
141
+
142
+ Google Bigquery allows to import and export large datasets of data the default formats are JSON and CSV, currently the adapter is only able to export JSON format.
143
+
144
+ #### Export
145
+
146
+ The export can be acomplished very easy from an active record model as:
147
+ ```ruby
148
+ User.bigquery_export(destination)
149
+ ```
150
+ where destination should be a valid google cloud store uri. The adapter will manage that , so you only need to pass the file name. Example:
151
+
152
+ User.bigquery_export("file.json")
153
+
154
+ the adapter will convert that option to gs://[configured_database]/[file.json]. Just be sure to create the bucket propperly in Cloud Storage panel.
155
+ Also if you don't pass the file argument you will get an generated uri like: gs://[configured_database]/[table_name].json.
156
+
157
+ #### Import
158
+
159
+ There are two ways to import massive data in bigquery, one is from a file from google cloud store and the second is from multipart Post
160
+
161
+ From google cloud storage:
162
+
163
+ ```ruby
164
+ User.bigquery_import([an_array_with_paths_to_gs_uris])
165
+ ```
166
+
167
+ From multipart/related post:
168
+
169
+ PENDING
170
+
171
+ ### Migrations:
172
+
173
+ This adapter has migration support migrations built in, but
174
+
175
+ ```ruby
176
+ class CreateUsers < ActiveRecord::Migration
177
+ def self.up
178
+ create_table :users do |t|
179
+ t.string :name
180
+ t.record :nested_data
181
+ t.references :taggable, :polymorphic => true
182
+ t.boolean :admin
183
+ t.timestamps
184
+ end
185
+ end
186
+
187
+ def self.down
188
+ drop_table :users
189
+ end
190
+ end
191
+
192
+ class AddPublishedToUser < ActiveRecord::Migration
193
+ def change
194
+ add_column :users, :published, :boolean, default: true
195
+ end
196
+ end
197
+
198
+ ```
199
+
200
+ Note:
201
+ + Big query does not provide a way to update columns nor delete, so update_column, or remove_column migration are cancelled with an catched exception.
202
+ + Also the schema_migrations table is not created in DB, is created as a json file in db/schema_migrations.json instead. Be sure to add the file in your version control.
203
+
204
+ ## Standalone Client:
205
+
206
+ ### Configuration setup:
207
+
208
+ https://developers.google.com/bigquery/docs/authorization
209
+
210
+ Configure GoogleBigquery client:
211
+
212
+ ```ruby
213
+ GoogleBigquery::Config.setup do |config|
214
+ config.pass_phrase = "notasecret"
215
+ config.key_file = /location/to_your/key_file.p12
216
+ config.client_id = "XXXXX.apps.googleusercontent.com"
217
+ config.scope = "https://www.googleapis.com/auth/bigquery"
218
+ config.email = "XXXXXX@developer.gserviceaccount.com"
219
+ end
220
+ ```
221
+
222
+ And authorize client:
223
+
224
+ ```ruby
225
+ @auth = GoogleBigquery::Auth.new
226
+ @auth.authorize
227
+ ```
228
+ Then you are ready to go!
229
+
230
+
231
+ ### Projects
232
+
233
+ https://developers.google.com/bigquery/docs/reference/v2/projects
234
+
235
+ ```ruby
236
+ GoogleBigquery::Project.list["projects"]
237
+ ```
238
+
239
+ ### Jobs
240
+
241
+ https://developers.google.com/bigquery/docs/reference/v2/jobs
242
+
243
+ #### Exporting data into multiple files
244
+
245
+ BigQuery can export up to 1 GB of data per file. If you plan to export more than 1 GB, you can use a wildcard character to instruct BigQuery to export to multiple files.
246
+
247
+ Note: it may take a while.
248
+
249
+ ```ruby
250
+ GoogleBigquery::Jobs.export(project_id, dataset_id, table_id, bucket_location)
251
+ ```
252
+
253
+ #### Query
254
+
255
+ ```ruby
256
+ GoogleBigquery::Jobs.query(@project, {"query"=> "SELECT * FROM [#{@dataset_id}.#{@table_name}] LIMIT 1000" })
257
+ ```
258
+
259
+
260
+ ### Datasets
261
+
262
+ https://developers.google.com/bigquery/docs/reference/v2/datasets
263
+
264
+ #### List:
265
+
266
+ ```ruby
267
+ GoogleBigquery::Dataset.list(@project_id)
268
+ ```
269
+
270
+ #### Create/Insert:
271
+
272
+ ```ruby
273
+ GoogleBigquery::Dataset.create(@project, {"datasetReference"=> { "datasetId" => @dataset_id }} )
274
+ ```
275
+
276
+ #### Delete:
277
+
278
+ ```ruby
279
+ GoogleBigquery::Dataset.delete(@project, @dataset_id }} )
280
+ ```
281
+
282
+ #### Update/Patch:
283
+
284
+ Updates information in an existing dataset. The update method replaces the entire dataset resource, whereas the patch method only replaces fields that are provided in the submitted dataset resource.
285
+
286
+ ```ruby
287
+ GoogleBigquery::Dataset.update(@project, @dataset_id,
288
+ {"datasetReference"=> {
289
+ "datasetId" =>@dataset_id },
290
+ "description"=> "foobar"} )
291
+ ```
292
+
293
+
294
+ Updates information in an existing dataset. The update method replaces the entire dataset resource, whereas the patch method only replaces fields that are provided in the submitted dataset resource. This method supports patch semantics.
295
+
296
+ ```ruby
297
+ GoogleBigquery::Dataset.patch(@project, @dataset_id,
298
+ {"datasetReference"=> {
299
+ "datasetId" =>@dataset_id },
300
+ "description"=> "foobar"} )
301
+ ```
302
+
303
+
304
+ ### Tables
305
+
306
+ https://developers.google.com/bigquery/docs/reference/v2/tables
307
+
308
+ #### Create:
309
+
310
+ ```ruby
311
+ @table_body = { "tableReference"=> {
312
+ "projectId"=> @project,
313
+ "datasetId"=> @dataset_id,
314
+ "tableId"=> @table_name},
315
+ "schema"=> [fields:
316
+ {:name=> "name", :type=> "string", :mode => "REQUIRED"},
317
+ {:name=> "age", :type=> "integer"},
318
+ {:name=> "weight", :type=> "float"},
319
+ {:name=> "is_magic", :type=> "boolean"}
320
+ ]
321
+ }
322
+
323
+ GoogleBigquery::Table.create(@project, @dataset_id, @table_body
324
+ ```
325
+
326
+ #### Update:
327
+
328
+ ```ruby
329
+ GoogleBigquery::Table.update(@project, @dataset_id, @table_name,
330
+ {"tableReference"=> {
331
+ "projectId" => @project, "datasetId" =>@dataset_id, "tableId" => @table_name },
332
+ "description"=> "foobar"} )
333
+ ```
334
+
335
+ #### Delete:
336
+
337
+ ```ruby
338
+ GoogleBigquery::Table.delete(@project, @dataset_id, @table_name )
339
+ ```
340
+
341
+ #### List:
342
+
343
+ ```ruby
344
+ GoogleBigquery::Table.list(@project, @dataset_id )
345
+ ```
346
+
347
+ ### Table Data
348
+
349
+ https://developers.google.com/bigquery/docs/reference/v2/tabledata
350
+
351
+ #### InsertAll
352
+
353
+ Streaming data into BigQuery is free for an introductory period until January 1st, 2014. After that it will be billed at a flat rate of 1 cent per 10,000 rows inserted. The traditional jobs().insert() method will continue to be free. When choosing which import method to use, check for the one that best matches your use case. Keep using the jobs().insert() endpoint for bulk and big data loading. Switch to the new tabledata().insertAll() endpoint if your use case calls for a constantly and instantly updating stream of data.
354
+
355
+ ```ruby
356
+ @rows = {"rows"=> [
357
+ {
358
+ "insertId"=> Time.now.to_i.to_s,
359
+ "json"=> {
360
+ "name"=> "User #{Time.now.to_s}"
361
+ }
362
+ }
363
+ ]}
364
+
365
+ GoogleBigquery::TableData.create(@project, @name, @table_name , @rows )
366
+ ```
367
+
368
+
369
+ #### List
370
+
371
+ ```ruby
372
+ GoogleBigquery::TableData.list(@project, @dataset_id, @table_name)
373
+ ```
374
+
375
+
376
+ ## RESOURCES:
377
+
378
+ https://developers.google.com/bigquery/loading-data-into-bigquery
379
+
380
+ https://developers.google.com/bigquery/streaming-data-into-bigquery
381
+
382
+ ### Api Explorer:
383
+
384
+ https://developers.google.com/apis-explorer/#s/bigquery/v2/
385
+
386
+ ### Google Big query developer guide
387
+
388
+ https://developers.google.com/bigquery/docs/developers_guide
389
+
390
+ # Caveats:
391
+
392
+ ## Contributing
393
+
394
+ 1. Fork it
395
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
396
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
397
+ 4. Push to the branch (`git push origin my-new-feature`)
398
+ 5. Create new Pull Request
399
+
400
+
401
+ #TODO:
402
+
403
+ ActiveRecord:
404
+ + AR migration copy tables to update it (copy to gs:// , delete table, import table from gs://)
405
+ + AR migrate BQ record type
406
+ + Make id and foreign keys types and values configurable
407
+ + Jobs make multipart/related upload
408
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run unit specs.'
6
+ task :default => :spec
7
+
8
+ desc 'Test the BQ plugin.'
9
+ RSpec::Core::RakeTask.new('spec') do |t|
10
+ t.pattern = FileList['spec/**/*_spec.rb']
11
+ end
12
+
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'google_bigquery/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bigbroda"
8
+ spec.version = GoogleBigquery::VERSION
9
+ spec.authors = ["miguel michelson"]
10
+ spec.email = ["miguelmichelson@gmail.com"]
11
+ spec.description = "GoogleBigQuery ActiveRecord Adapter & standalone API client"
12
+ spec.summary = "This library is build on top of google-api-client, ActiveRecord >4 compatible"
13
+ spec.homepage = "https://github.com/michelson/BigBroda"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rails", "~> 4.0.0"
24
+
25
+ spec.add_runtime_dependency("google-api-client")
26
+
27
+ spec.add_dependency "hash-deep-merge"
28
+ spec.add_dependency "activesupport"
29
+ spec.add_dependency "activerecord"
30
+ end
data/lib/.DS_Store ADDED
Binary file
Binary file