Class: TableLoader
- Includes:
- TableModule
- Defined in:
- lib/dataload/table_loader.rb
Instance Method Summary collapse
- #effective_block_size ⇒ Object
- #load! ⇒ Object
- #master ⇒ Object
- #target_hash_for_row(row) ⇒ Object
- #target_hash_groups ⇒ Object
- #target_hashes(rows) ⇒ Object
Instance Method Details
#effective_block_size ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/dataload/table_loader.rb', line 29 def effective_block_size if master.db_ops[:adapter].to_s == 'sqlserver' 100000 else block_size end end |
#load! ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dataload/table_loader.rb', line 52 def load! migrate! Dataload.log "Starting load of table '#{table_name}'" total = 0 target_hash_groups do |hs,num_inserted| BatchInsert.get_class.new(:rows => hs, :table_name => table_name, :ar_class => ar_cls, :block_size => block_size).insert! Dataload.log "Inserted #{num_inserted - total} rows into table '#{table_name}'. Total of #{num_inserted} rows inserted." total = num_inserted end Dataload.log "Finished load of table '#{table_name}'. Loaded #{total} rows." end |
#master ⇒ Object
26 27 28 |
# File 'lib/dataload/table_loader.rb', line 26 def master MasterLoader.instance end |
#target_hash_for_row(row) ⇒ Object
41 42 43 |
# File 'lib/dataload/table_loader.rb', line 41 def target_hash_for_row(row) columns.inject({}) { |h,col| h.merge(col.target_name => col.target_value(row)) } end |
#target_hash_groups ⇒ Object
47 48 49 50 51 |
# File 'lib/dataload/table_loader.rb', line 47 def target_hash_groups source_row_groups.each_with_index do |rows,i| yield(target_hashes(rows),i*effective_block_size+rows.size) end end |
#target_hashes(rows) ⇒ Object
44 45 46 |
# File 'lib/dataload/table_loader.rb', line 44 def target_hashes(rows) rows.map { |x| target_hash_for_row(x) } end |