Class: TableLoader

Inherits:
Object show all
Includes:
TableModule
Defined in:
lib/dataload/table_loader.rb

Instance Method Summary collapse

Instance Method Details

#load!Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dataload/table_loader.rb', line 42

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).insert!
    Dataload.log "Inserted #{block_size} 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

#target_hash_for_row(row) ⇒ Object



31
32
33
# File 'lib/dataload/table_loader.rb', line 31

def target_hash_for_row(row)
  columns.inject({}) { |h,col| h.merge(col.target_name => col.target_value(row)) }
end

#target_hash_groupsObject



37
38
39
40
41
# File 'lib/dataload/table_loader.rb', line 37

def target_hash_groups
  source_row_groups.each_with_index do |rows,i|
    yield(target_hashes(rows),i*block_size+rows.size)
  end
end

#target_hashes(rows) ⇒ Object



34
35
36
# File 'lib/dataload/table_loader.rb', line 34

def target_hashes(rows)
  rows.map { |x| target_hash_for_row(x) }
end