bigrecord 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -48,5 +48,6 @@ Big Record is released under the MIT license.
48
48
  == Links
49
49
 
50
50
  * Contact Us
51
+ * Google Group - http://groups.google.com/group/bigrecord
51
52
  * Website - http://www.bigrecord.org
52
53
  * IRC Channel - <tt>#bigrecord</tt> on irc.freenode.net
data/Rakefile CHANGED
@@ -1,16 +1,9 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  require 'rubygems'
4
- require 'rake'
5
- require 'rake/rdoctask'
6
- require 'rake/gempackagetask'
7
- require 'spec/rake/spectask'
8
-
9
2
 
10
- DATA_STORES = ["hbase", "cassandra"]
3
+ DATA_STORES = ["hbase"]
11
4
  ROOT = File.expand_path(File.dirname(__FILE__)) + '/'
12
5
 
13
- require ROOT + 'tasks/gem'
14
- require ROOT + 'tasks/rdoc'
15
- require ROOT + 'tasks/spec'
16
- require ROOT + 'tasks/data_store'
6
+ load 'tasks/data_store.rake'
7
+ load 'tasks/gem.rake'
8
+ load 'tasks/rdoc.rake'
9
+ load 'tasks/spec.rake'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
@@ -172,7 +172,7 @@ module BigRecord
172
172
 
173
173
  attributes.each do |k, v|
174
174
  begin
175
- k.include?("(") ? multi_parameter_attributes << [ k, v ] : send(k + "=", v)
175
+ k.include?("(") ? multi_parameter_attributes << [ k, v ] : send(k + "=", v) if v
176
176
  rescue
177
177
  logger.debug "#{__FILE__}:#{__LINE__} Warning! Ignoring attribute '#{k}' because it doesn't exist anymore"
178
178
  end
@@ -891,6 +891,7 @@ private
891
891
  # @return [ConnectionAdapters::Column] The column object created.
892
892
  def column(name, type, options={})
893
893
  name = name.to_s
894
+ name = "#{self.default_column_prefix}#{name}" unless (name =~ /:/) || self.default_column_prefix.blank?
894
895
 
895
896
  @columns_hash = default_columns unless @columns_hash
896
897
 
@@ -1045,6 +1046,11 @@ private
1045
1046
  read_inheritable_attribute(:attr_create_accessible)
1046
1047
  end
1047
1048
 
1049
+ # Default column prefix used when auto-generating column attribute names
1050
+ def default_column_prefix
1051
+ ""
1052
+ end
1053
+
1048
1054
  protected
1049
1055
  def invalidate_views
1050
1056
  @views = nil
@@ -5,7 +5,7 @@ module BigRecord
5
5
  alias_method :proxy_respond_to?, :respond_to?
6
6
  alias_method :proxy_extend, :extend
7
7
  delegate :to_param, :to => :proxy_target
8
- instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_)/ }
8
+ instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|object_id)/ }
9
9
 
10
10
  def initialize(owner, reflection)
11
11
  @owner, @reflection = owner, reflection
@@ -399,7 +399,7 @@ module BigRecord
399
399
  #
400
400
  # Defaults to "attribute"
401
401
  def default_family
402
- (superclass == BigRecord::Base) ? (@default_family ||= "attribute") : superclass.default_family
402
+ @default_family ||= "attribute"
403
403
  end
404
404
 
405
405
  # Set the default column family used to store attributes that have no column family set explicitly.
@@ -466,12 +466,8 @@ module BigRecord
466
466
  {primary_key => ConnectionAdapters::Column.new(primary_key, 'string')}
467
467
  end
468
468
 
469
- # @see BigRecord::AbstractBase.column
470
- def column(name, type, options={})
471
- name = name.to_s
472
- name = "#{self.default_family}:#{name}" unless (name =~ /:/)
473
-
474
- super(name, type, options)
469
+ def default_column_prefix
470
+ "#{default_family}:"
475
471
  end
476
472
 
477
473
  # Return the hash of default views which consist of all columns and the :default named views.
@@ -5,7 +5,7 @@ module BigRecord
5
5
  alias_method :proxy_respond_to?, :respond_to?
6
6
  alias_method :proxy_extend, :extend
7
7
  delegate :to_param, :to => :proxy_target
8
- instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_)/ }
8
+ instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|object_id)/ }
9
9
 
10
10
  def initialize(owner, reflection)
11
11
  @owner, @reflection = owner, reflection
@@ -42,9 +42,10 @@ module BigRecord
42
42
  # Generate the sql query. The join table has to be in mysql.
43
43
  conditions = "#{@finder_sql}"
44
44
 
45
- if sanitized_conditions = ActiveRecord::Base.send(:sanitize_sql, options[:conditions])
46
- conditions << " AND (#{sanitized_conditions})"
47
- end
45
+ # FIXME: throws "undefined method `abstract_class?' for Object:Class"
46
+ # if sanitized_conditions = ActiveRecord::Base.send(:sanitize_sql, options[:conditions])
47
+ # conditions << " AND (#{sanitized_conditions})"
48
+ # end
48
49
 
49
50
  if options[:order] && @reflection.options[:order]
50
51
  order = "#{options[:order]}, #{@reflection.options[:order]}"
@@ -60,9 +60,9 @@ module BigRecord
60
60
  when macro == :belongs_to_big_record
61
61
  @primary_key_name = options[:foreign_key] || class_name.foreign_key
62
62
  when macro == :belongs_to_many
63
- @primary_key_name = options[:foreign_key] || "#{big_record.default_family}:#{class_name.tableize}_ids"
63
+ @primary_key_name = options[:foreign_key] || "#{big_record.default_column_prefix}#{class_name.tableize}_ids"
64
64
  when options[:as]
65
- @primary_key_name = options[:foreign_key] || "#{big_record.default_family}:#{options[:as]}_id"
65
+ @primary_key_name = options[:foreign_key] || "#{big_record.default_column_prefix}#{options[:as]}_id"
66
66
  else
67
67
  @primary_key_name = options[:foreign_key] || big_record.name.foreign_key
68
68
  end
@@ -306,7 +306,8 @@ module BigRecord
306
306
  when String then value.split(COLLECTION_SEPARATOR)
307
307
  when Hash then value.values.first.scan(/\[(.*?)\]/).flatten
308
308
  when NilClass then []
309
- else value
309
+ when Array then value
310
+ else [value]
310
311
  end
311
312
  end
312
313
 
@@ -316,7 +317,16 @@ module BigRecord
316
317
  end
317
318
 
318
319
  def hash_to_integer_collection(value)
319
- parse_collection(value).collect(&:to_i)
320
+ ret = nil
321
+ begin
322
+ collection = parse_collection(value)
323
+ ret = collection.collect(&:to_i)
324
+ rescue
325
+ $stderr.puts("expected an array, got #{collection}, (#{collection.class})\n"+
326
+ "original value fed into parse_collection was #{value}, (#{value.class})")
327
+ ret = [collection.to_i]
328
+ end
329
+ ret
320
330
  end
321
331
 
322
332
  def hash_to_float_collection(value)
@@ -354,6 +364,9 @@ module BigRecord
354
364
  end
355
365
 
356
366
  def string_to_date(string)
367
+ # Important: the stored value could be an instance of Time. If we don't
368
+ # cast to Date, the cast will fail because column type != value type
369
+ return new_date(string.year, string.month, string.day) if (string.is_a?Time)
357
370
  return string unless string.is_a?(String)
358
371
  return nil if string.empty?
359
372
 
@@ -1,25 +1,15 @@
1
- require 'rubygems'
2
1
  require 'set'
3
2
  require 'drb'
4
3
 
5
4
  module BigRecord
6
5
  class Base
7
6
  # Establishes a connection to the database that's used by all Active Record objects.
8
- def self.hbase_connection(config) # :nodoc:
9
- unless defined?(BigRecordDriver)
10
- begin
11
- # Bigrecord's source is included with Bigrecord-Driver, that's where we check for it first.
12
- require File.join(File.dirname(__FILE__), "..", "..", "..", "..", "bigrecord-driver", "lib", "big_record_driver")
13
- rescue LoadError
14
- # Then we'll require it from the load path (or rubygems)
15
- begin
16
- require 'bigrecord_driver'
17
- rescue LoadError => e
18
- # If it couldn't be found, we'll just prompt the user to install the gem.
19
- puts "[BigRecord] bigrecord-driver is needed for HbaseAdapter. Install it with: gem install bigrecord-driver"
20
- raise e
21
- end
22
- end
7
+ def self.hbase_connection(config)
8
+ begin
9
+ require 'big_record_driver'
10
+ rescue LoadError => e
11
+ puts "[BigRecord] bigrecord-driver is needed for HbaseAdapter. Install it with: gem install bigrecord-driver"
12
+ raise e
23
13
  end
24
14
 
25
15
  config = config.symbolize_keys
@@ -29,7 +19,7 @@ module BigRecord
29
19
  drb_host = config[:drb_host]
30
20
  drb_port = config[:drb_port]
31
21
 
32
- hbase = BigRecordDriver::Client.new(config)
22
+ hbase = BigRecord::Driver::Client.new(config)
33
23
 
34
24
  ConnectionAdapters::HbaseAdapter.new(hbase, logger, [zookeeper_host, zookeeper_client_port], config)
35
25
  end
@@ -88,7 +78,7 @@ module BigRecord
88
78
 
89
79
  def active?
90
80
  @connection.ping
91
- rescue BigRecordError
81
+ rescue BigRecord::Driver::DriverError
92
82
  false
93
83
  end
94
84
 
@@ -259,7 +249,7 @@ module BigRecord
259
249
  end
260
250
 
261
251
  def add_column_family(table_name, column_name, options = {})
262
- column = BigRecordDriver::ColumnDescriptor.new(column_name.to_s, options)
252
+ column = BigRecord::Driver::ColumnDescriptor.new(column_name.to_s, options)
263
253
 
264
254
  result = nil
265
255
  log "ADD COLUMN TABLE #{table_name} COLUMN #{column_name} (#{options.inspect});" do
@@ -281,7 +271,7 @@ module BigRecord
281
271
  alias :remove_family :remove_column_family
282
272
 
283
273
  def modify_column_family(table_name, column_name, options = {})
284
- column = BigRecordDriver::ColumnDescriptor.new(column_name.to_s, options)
274
+ column = BigRecord::Driver::ColumnDescriptor.new(column_name.to_s, options)
285
275
 
286
276
  result = nil
287
277
  log "MODIFY COLUMN TABLE #{table_name} COLUMN #{column_name} (#{options.inspect});" do
@@ -332,7 +322,7 @@ module BigRecord
332
322
  when TYPE_NULL then nil
333
323
  when TYPE_STRING then data[1..-1]
334
324
  when TYPE_BINARY then data[1..-1]
335
- else nil
325
+ else data
336
326
  end
337
327
  end
338
328
 
@@ -412,7 +402,7 @@ module BigRecord
412
402
  end
413
403
 
414
404
  def column_family(name, options = {})
415
- column = self[name] || BigRecordDriver::ColumnDescriptor.new(name.to_s, options)
405
+ column = self[name] || BigRecord::Driver::ColumnDescriptor.new(name.to_s, options)
416
406
 
417
407
  @column_families << column unless @column_families.include? column
418
408
  self
@@ -5,16 +5,16 @@ module BigRecord
5
5
  # Establishes a connection to the database that's used by all Active Record objects.
6
6
  def self.hbase_rest_connection(config) # :nodoc:
7
7
  begin
8
- require 'hbase'
8
+ require 'stargate'
9
9
  rescue LoadError => e
10
- puts "[BigRecord] hbase-ruby is needed for HbaseRestAdapter. Install it with: gem install hbase-ruby"
10
+ puts "[BigRecord] hbase-stargate is needed for HbaseRestAdapter. Install it with: gem install hbase-stargate"
11
11
  raise e
12
12
  end
13
13
 
14
14
  config = config.symbolize_keys
15
15
 
16
16
  api_address = config[:api_address]
17
- hbase = HBase::Client.new(api_address)
17
+ hbase = Stargate::Client.new(api_address)
18
18
  ConnectionAdapters::HbaseRestAdapter.new(hbase, logger, [], config)
19
19
  end
20
20
  end
@@ -163,7 +163,7 @@ module BigRecord
163
163
  def get_consecutive_rows_raw(table_name, start_row, limit, columns, stop_row = nil)
164
164
  result = nil
165
165
  log "SCAN (#{columns.join(", ")}) FROM #{table_name} WHERE START_ROW=#{start_row} AND STOP_ROW=#{stop_row} LIMIT=#{limit};" do
166
- options = {:start_row => start_row, :end_row => stop_row, :columns => columns}
166
+ options = {:start_row => start_row, :end_row => stop_row, :columns => columns, :batch => 200}
167
167
  scanner = @connection.open_scanner(table_name, options)
168
168
  result = @connection.get_rows(scanner, limit)
169
169
  @connection.close_scanner(scanner)
@@ -21,7 +21,7 @@ module BigRecord
21
21
 
22
22
  # Add an existing dynamic column to this record
23
23
  def add_dynamic_column(col)
24
- columns_hash[c.name] = col
24
+ columns_hash[col.name] = col
25
25
  @columns_name= nil; @columns= nil #reset
26
26
  col
27
27
  end
@@ -1,7 +1,7 @@
1
1
  module BigRecord
2
2
  module EmbeddedAssociations
3
3
  class AssociationProxy #:nodoc:
4
- instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_)/ }
4
+ instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|object_id)/ }
5
5
 
6
6
  def find(id)
7
7
  @target.select{|s| s.id == id}.first
@@ -246,8 +246,10 @@ module BigRecord
246
246
  # whether or not to validate the record. See #validates_each.
247
247
  def evaluate_condition(condition, record)
248
248
  case condition
249
- when Symbol: record.send(condition)
250
- when String: eval(condition, binding)
249
+ when Symbol
250
+ record.send(condition)
251
+ when String
252
+ eval(condition, binding)
251
253
  else
252
254
  if condition_block?(condition)
253
255
  condition.call(record)
@@ -0,0 +1,3 @@
1
+ module BigRecord
2
+ VERSION = File.read(File.join(File.dirname(__FILE__), "..", "..", "VERSION")).chomp.freeze
3
+ end
data/lib/big_record.rb CHANGED
@@ -53,6 +53,7 @@ require dir + '/family_span_columns'
53
53
  require dir + '/migration'
54
54
  require dir + '/connection_adapters'
55
55
  require dir + '/fixtures'
56
+ require dir + '/version'
56
57
 
57
58
  # Add support for collections to tag builders
58
59
  require dir + '/action_view_extensions'
@@ -9,11 +9,13 @@
9
9
 
10
10
  require 'rubygems'
11
11
  require 'benchmark'
12
- require 'pathname'
13
12
  require 'ruby-debug'
14
13
 
15
- SPEC_ROOT = Pathname(__FILE__).dirname.expand_path
16
- require SPEC_ROOT.parent + 'lib/big_record'
14
+ bigrecord_driver_path = File.expand_path(File.dirname(__FILE__)+'/../../bigrecord-driver/lib')
15
+ $:.unshift(bigrecord_driver_path) if File.directory?(bigrecord_driver_path) && !$:.include?(bigrecord_driver_path)
16
+
17
+ SPEC_ROOT = File.expand_path(File.dirname(__FILE__))
18
+ require SPEC_ROOT + '/../lib/big_record'
17
19
 
18
20
  BigRecord::Base.configurations = YAML::load(File.open(File.join(File.dirname(__FILE__), "connections", "bigrecord.yml")))
19
21
  BigRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "benchmark.log"))
@@ -53,3 +55,5 @@ Benchmark.bm do |x|
53
55
  end
54
56
  end
55
57
  end
58
+
59
+ Book.delete_all
@@ -1,7 +1,7 @@
1
- hbase_rest:
1
+ hbase:
2
2
  adapter: hbase_rest
3
3
  api_address: http://localhost:8080
4
- hbase:
4
+ hbase_brd:
5
5
  adapter: hbase
6
6
  zookeeper_quorum: localhost
7
7
  zookeeper_client_port: 2181
data/spec/spec.opts CHANGED
@@ -1,4 +1,4 @@
1
1
  --colour
2
2
  --loadby random
3
3
  --format progress
4
- --debugger
4
+ --debugger
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,11 @@
1
- require 'pathname'
2
1
  require 'rubygems'
3
-
4
- gem 'rspec', '~>1.2'
5
2
  require 'spec'
6
3
 
7
- SPEC_ROOT = Pathname(__FILE__).dirname.expand_path
8
- require SPEC_ROOT.parent + 'lib/big_record'
4
+ bigrecord_driver_path = File.expand_path(File.dirname(__FILE__)+'/../../bigrecord-driver/lib')
5
+ $:.unshift(bigrecord_driver_path) if File.directory?(bigrecord_driver_path) && !$:.include?(bigrecord_driver_path)
6
+
7
+ SPEC_ROOT = File.expand_path(File.dirname(__FILE__))
8
+ require SPEC_ROOT + '/../lib/big_record'
9
9
 
10
10
  if ENV["HBASE_REST_ADDRESS"]
11
11
  config = YAML::load(File.open(File.join(File.dirname(__FILE__), "connections", "bigrecord.yml")))
@@ -58,4 +58,4 @@ class Hash
58
58
  other_hash.subset_of?(self)
59
59
  end
60
60
 
61
- end
61
+ end
@@ -0,0 +1,25 @@
1
+ namespace :data_store do
2
+ require File.join(File.dirname(__FILE__), "..", "lib", "big_record")
3
+
4
+ if ENV["HBASE_REST_ADDRESS"]
5
+ config = YAML::load(File.open(File.join(ROOT, "spec", "connections", "bigrecord.yml")))
6
+ config["hbase"]["api_address"] = ENV["HBASE_REST_ADDRESS"]
7
+ BigRecord::Base.configurations = config
8
+ else
9
+ BigRecord::Base.configurations = YAML::load(File.open(File.join(ROOT, "spec", "connections", "bigrecord.yml")))
10
+ end
11
+ BigRecord::Base.logger = Logger.new(File.expand_path(File.join(ROOT, "migrate.log")))
12
+
13
+ @migrations_path = File.expand_path(File.join(ROOT, "spec", "lib", "migrations"))
14
+
15
+ desc 'Migrate the test schema for the data store specified by ENV=<data_store>'
16
+ task :migrate do
17
+ environment = ENV['ENV']
18
+ raise ArgumentError, "Usage: rake data_store:migrate ENV=<#{DATA_STORES.join("|")}>" unless environment
19
+
20
+ BigRecord::Base.establish_connection environment
21
+
22
+ BigRecord::Migrator.migrate(@migrations_path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
23
+ end
24
+
25
+ end
File without changes
File without changes
@@ -1,3 +1,6 @@
1
+ require 'spec'
2
+ require 'spec/rake/spectask'
3
+
1
4
  desc "Run #{DATA_STORES.join(" and ")} specs"
2
5
  task :spec => DATA_STORES.map{|store| "spec:#{store}" }
3
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigrecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - openplaces.org
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-02 00:00:00 -05:00
12
+ date: 2010-02-12 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -125,6 +125,7 @@ files:
125
125
  - lib/big_record/routing_ext.rb
126
126
  - lib/big_record/timestamp.rb
127
127
  - lib/big_record/validations.rb
128
+ - lib/big_record/version.rb
128
129
  - lib/bigrecord.rb
129
130
  - rails/init.rb
130
131
  - spec/adapter_benchmark.rb
@@ -165,10 +166,10 @@ files:
165
166
  - spec/unit/scanner_spec.rb
166
167
  - spec/unit/validations_spec.rb
167
168
  - tasks/bigrecord_tasks.rake
168
- - tasks/data_store.rb
169
- - tasks/gem.rb
170
- - tasks/rdoc.rb
171
- - tasks/spec.rb
169
+ - tasks/data_store.rake
170
+ - tasks/gem.rake
171
+ - tasks/rdoc.rake
172
+ - tasks/spec.rake
172
173
  - LICENSE
173
174
  - README.rdoc
174
175
  has_rdoc: true
@@ -198,6 +199,6 @@ rubyforge_project:
198
199
  rubygems_version: 1.3.5
199
200
  signing_key:
200
201
  specification_version: 3
201
- summary: Object mapper for supporting column-oriented data stores (supports hbase cassandra) in Ruby on Rails.
202
+ summary: Object mapper for supporting column-oriented data stores (supports hbase) in Ruby on Rails.
202
203
  test_files: []
203
204
 
data/tasks/data_store.rb DELETED
@@ -1,53 +0,0 @@
1
- namespace :data_store do
2
- require 'lib/big_record'
3
-
4
- if ENV["HBASE_REST_ADDRESS"]
5
- config = YAML::load(File.open(File.join(ROOT, "spec", "connections", "bigrecord.yml")))
6
- config["hbase"]["api_address"] = ENV["HBASE_REST_ADDRESS"]
7
- BigRecord::Base.configurations = config
8
- else
9
- BigRecord::Base.configurations = YAML::load(File.open(File.join(ROOT, "spec", "connections", "bigrecord.yml")))
10
- end
11
- BigRecord::Base.logger = Logger.new(File.expand_path(File.join(ROOT, "migrate.log")))
12
-
13
- @migrations_path = File.expand_path(File.join(ROOT, "spec", "lib", "migrations"))
14
-
15
- desc 'Migrate the test schema for the data store specified by ENV=<data_store>'
16
- task :migrate do
17
- environment = ENV['ENV']
18
- raise ArgumentError, "Usage: rake data_store:migrate ENV=<#{DATA_STORES.join("|")}>" unless environment
19
-
20
- BigRecord::Base.establish_connection environment
21
-
22
- BigRecord::Migrator.migrate(@migrations_path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
23
- end
24
-
25
- namespace :migrate do
26
- desc 'Runs the "up" for a given migration VERSION.'
27
- task :up do
28
- environment = ENV['ENV']
29
- raise ArgumentError, "Usage: rake data_store:migrate:up ENV=<#{DATA_STORES.join("|")}>" unless environment
30
-
31
- BigRecord::Base.establish_connection environment
32
-
33
- version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
34
- raise "VERSION is required" unless version
35
-
36
- BigRecord::Migrator.run(:up, @migrations_path, version)
37
- end
38
-
39
- desc 'Runs the "down" for a given migration VERSION.'
40
- task :down do
41
- environment = ENV['ENV']
42
- raise ArgumentError, "Usage: rake data_store:migrate:down ENV=<#{DATA_STORES.join("|")}>" unless environment
43
-
44
- BigRecord::Base.establish_connection environment
45
-
46
- version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
47
- raise "VERSION is required" unless version
48
-
49
- BigRecord::Migrator.run(:down, @migrations_path, version)
50
- end
51
- end
52
-
53
- end