Class: Shiba::IndexStats::Table

Inherits:
Struct
  • Object
show all
Defined in:
lib/shiba/index_stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#countObject

Returns the value of attribute count

Returns:

  • (Object)

    the current value of count



25
26
27
# File 'lib/shiba/index_stats.rb', line 25

def count
  @count
end

#indexesObject

Returns the value of attribute indexes

Returns:

  • (Object)

    the current value of indexes



25
26
27
# File 'lib/shiba/index_stats.rb', line 25

def indexes
  @indexes
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



25
26
27
# File 'lib/shiba/index_stats.rb', line 25

def name
  @name
end

Instance Method Details

#add_index_column(index_name, column_name, rows_per, cardinality, is_unique) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/shiba/index_stats.rb', line 43

def add_index_column(index_name, column_name, rows_per, cardinality, is_unique)
  index = build_index(index_name, is_unique)
  index.columns << Column.new(column_name, index, rows_per, cardinality)

  if is_unique && !self.count
    # set row count from unique index
    self.count = cardinality
  end
end

#build_index(index_name, is_unique) ⇒ Object



39
40
41
# File 'lib/shiba/index_stats.rb', line 39

def build_index(index_name, is_unique)
  self.indexes[index_name] ||= Index.new(self, index_name, [], is_unique)
end

#column_sizesObject



53
54
55
# File 'lib/shiba/index_stats.rb', line 53

def column_sizes
  @column_sizes ||= {}
end

#encode_with(coder) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shiba/index_stats.rb', line 26

def encode_with(coder)
  if self.count.nil?
    #uuuugly.  No unique keys.  we'll take our best guess.
    self.count = indexes.map { |i, parts| parts.columns.map { |v| v.raw_cardinality } }.flatten.max
  end

  coder.map = self.to_h.stringify_keys
  coder.map.delete('name')

  coder.map['column_sizes'] = column_sizes
  coder.tag = nil
end