14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/data_sampler/sample.rb', line 14
def compute!
@connection.tables.each do |table_name|
@table_samples[table_name] = TableSample.new(@connection, table_name, @rows_per_table)
end
warn "Sampling #{@table_samples.count} tables from database `#{@connection.current_database}`..."
@table_samples.values.map &:sample!
warn "Ensuring referential integrity..."
begin
new_dependencies = 0
@table_samples.values.each do |table_sample|
newly_added = table_sample.ensure_referential_integrity(@table_samples)
if newly_added > 0
new_dependencies += newly_added
warn " Found #{newly_added} new dependents for table `#{table_sample.table_name}`"
end
end
warn " Discovered #{new_dependencies} new dependencies" if new_dependencies > 0
end while new_dependencies > 0
warn "Referential integrity obtained"
warn "Final sample contains:"
@table_samples.values.each do |table_sample|
warn " #{table_sample.size} row(s) from `#{table_sample.table_name}`"
end
@computed = true
end
|