Class: Shiba::Index
- Inherits:
-
Object
- Object
- Shiba::Index
- Defined in:
- lib/shiba/index.rb
Class Method Summary collapse
-
.parse(path) ⇒ Object
Given the path to the information_schema.statistics output, returns index statistics keyed by table name.
Class Method Details
.parse(path) ⇒ Object
Given the path to the information_schema.statistics output, returns index statistics keyed by table name. Examples: Exploring the schema:
schema_stats = Index.parse(“./shiba/schema_stats.tsv”) schema_stats.keys
> :users, :posts, :comments
> :table_name=>“users”, :non_unique=>“0”, :column_name=>“id”, :cardinality=>“2”, :is_visible=>“YES”, :“expressionn”=>“NULLn”
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/shiba/index.rb', line 17 def self.parse(path) stats = IndexStats.new tables = {} records = read(path) headers = records.shift.map { |header| header.downcase } records.each do |r| h = Hash[headers.zip(r)] h["cardinality"] = h["cardinality"].to_i stats.add_index_column(h['table_name'], h['index_name'], h['column_name'], h['cardinality'], h['non_unique'] == "0") end stats end |