Sha256: f9200c86b12b0cf7e4e6fa91125ccb93c8afe5e280b5858b1b48218446ba63ab
Contents?: true
Size: 1.13 KB
Versions: 17
Compression:
Stored size: 1.13 KB
Contents
require 'yaml' require 'pp' require 'shiba/index_stats' module Shiba class Index # 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 # schema_stats[:users] # => {:table_schema=>"blog_test", :table_name=>"users", :non_unique=>"0", :column_name=>"id", :cardinality=>"2", :is_visible=>"YES", :"expression\n"=>"NULL\n"} # 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 protected def self.read(path) # fixes :"expression\n"=>"NULL\n"}, IO.foreach(path).map { |l| l.gsub!("\n", "").split("\t") } end end end
Version data entries
17 entries across 17 versions & 1 rubygems