michelson / BigBroda

GoogleBig Query ActiveRecord Adapter & API client
MIT License
113 stars 16 forks source link

MongoID anyone ? #11

Open lgs opened 9 years ago

lgs commented 9 years ago

Is there any way to use it with mongoid/mongodb ?

michelson commented 9 years ago

if you mean, use BB along with MongoId, I think it will work. I don't even try it , but I guess that you have to set up you mongo models (or app wide) with mongoid , and setup the BB models specifically.

what you think ? have you make some tests about it ?

lgs commented 9 years ago

... well, in rails/mongoid configuration you don't require ActiveRecord:

see config/application.rb

...
# require 'rails/all'
# Pick the frameworks you want:
require "active_model/railtie"
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
require "minitest/autorun"
require 'google_bigquery'
...

then you get the following error:

$ rails g google_bigquery:install
/home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bigbroda-0.0.5/lib/active_record/connection_adapters/bigquery_adapter.rb:69:in `': uninitialized constant ActiveRecord::Base (NameError)
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bigbroda-0.0.5/lib/active_record/connection_adapters/bigquery_adapter.rb:6:in `'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bigbroda-0.0.5/lib/google_bigquery/engine.rb:3:in `'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bigbroda-0.0.5/lib/google_bigquery/railtie.rb:6:in `block in '
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:36:in `call'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.4/lib/rails/application.rb:123:in `initialize'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.4/lib/rails/railtie.rb:171:in `new'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.4/lib/rails/railtie.rb:171:in `instance'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.4/lib/rails/application.rb:90:in `inherited'
    from /home/lsoave/Github/gitwatcher/config/application.rb:20:in `'
    from /home/lsoave/Github/gitwatcher/config/application.rb:19:in `'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:82:in `require'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:82:in `preload'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:140:in `serve'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/lsoave/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `
'
michelson commented 9 years ago

Hi @lgs ,
BigBroda depends on active_record, so you must use MongoId algong with activeRecord. try to require AR too , and let me know how it goes

lgs commented 9 years ago

it works ...,

of course you'll use BB in "Standalone Client mode" calling GoogleBigquery::Jobs.query(@project, {"query"=> "SELECT * FROM [#{@dataset_id}.#{@table_name}] LIMIT 100" }) for example, then parsing/saving the response within a custom mongoid model method ... but you'll end up with a messy unused DB libs ( active_record/railtie + sqlite3 ).

Not a big deal I know, but shouldn't be better having more modularity/decoupling here? Rails is becoming even less ActiveRecord centric that in past ...

What do you say?

michelson commented 9 years ago

uhm? are you saving results from BigQuery into mongoId model ? why are you doing that ?

The idea behind BigBroda is to use ActiveRecord as an interface to query over Google BigQuery datasets, using Arel, validations etc. , so is not clear to me the use case of yours. Of course you can use the standalone but it don't makes sense to me that those results are saved in MongoId models. can you describe what are you trying to achieve in more detail ?

regards

lgs commented 9 years ago

Simply take some snapshot queries on BigQuery pubblic data from time to time, caching & storing those "views" on existing Rails/MongoID app to be shown without calling BigQuery again.

I wold need just an API consumer (in Ruby) to wire in a Rails app. Do you think BB is overwhelming in that case?

Could you please describe your own best practice scenario for BB?

Yes, I read the README intro on OLAP & DataWareHousing but a real case?

michelson commented 9 years ago

Hi @lgs got it, makes sense...

The approach I will take, if Im going to snapshot with mongo(id), is to use BigBroda as an ActiveRecord model anyway, and then use those results to be copied to mongo. what do you think about that ?

maybe you could use memcached/redis to cache results and still use ActiveRecord BQ models.

best regards

lgs commented 9 years ago

... yes agree,

but I'll pay the cost of having active_record/railtie + sqlite3 unnecessary wired, as I stated in my very previous question.

It's feasible anyway ...

Thanks for sharing your view

michelson commented 9 years ago

@lgs no problem. btw. sqlite3 is not a dependency of BB, it's only used for some tests in spec

lgs commented 9 years ago

... as soon as you require active_record/railtie, you'll need sqlite3 to be bundled, otherwise you get an error starting Rails / rake or using rails g google_bigquery:install