class SqlPartitioner::Partition

Represents information for a single partition in the database

Constants

FUTURE_PARTITION_NAME
FUTURE_PARTITION_VALUE
TO_LOG_ATTRIBUTES_SORT_ORDER

Public Class Methods

all(adapter, table_name) click to toggle source

Fetches info on all partitions for the given ‘table_name`, using the given `adapter`. @param [BaseAdapter] adapter @param [String] table_name @return [PartitionCollection]

# File lib/sql_partitioner/partition.rb, line 68
def self.all(adapter, table_name)
  select_sql = SqlPartitioner::SQL.partition_info
  result = adapter.select(select_sql, adapter.schema_name, table_name).reject{|r| r.partition_description.nil? }

  partition_collection = PartitionCollection.new
  result.each{ |r| partition_collection << self.new(r) }

  partition_collection
end
new(partition_data) click to toggle source

Likely only called by ‘Partition.all`

# File lib/sql_partitioner/partition.rb, line 60
def initialize(partition_data)
  @partition_data = partition_data
end
to_log(partitions) click to toggle source

logs the formatted partition info from information schema @param [Array] array of partition objects @return [String] formatted partitions in tabular form

# File lib/sql_partitioner/partition.rb, line 132
def self.to_log(partitions)
  return "none" if partitions.empty?

  padding = TO_LOG_ATTRIBUTES_SORT_ORDER.map do |attribute|
              max_length = partitions.map do |partition|
                partition.send(attribute).to_s.length
              end.max
              [attribute.to_s.length, max_length].max + 3
            end

  header = TO_LOG_ATTRIBUTES_SORT_ORDER.each_with_index.map do |attribute, index|
              attribute.to_s.ljust(padding[index])
            end.join

  body = partitions.map do |partition|
           TO_LOG_ATTRIBUTES_SORT_ORDER.each_with_index.map do |attribute, index|
             partition.send(attribute).to_s.ljust(padding[index])
           end.join
         end.join("\n")

  separator = ''.ljust(padding.inject(&:+),'-')

  [separator, header, separator, body, separator].join("\n")
end

Public Instance Methods

attributes() click to toggle source

@return [Hash]

# File lib/sql_partitioner/partition.rb, line 118
def attributes
  {
    :ordinal_position  => ordinal_position,
    :name              => name,
    :timestamp         => timestamp,
    :table_rows        => table_rows,
    :data_length       => data_length,
    :index_length      => index_length
  }
end
data_length() click to toggle source

@return [Fixnum]

# File lib/sql_partitioner/partition.rb, line 103
def data_length
  @partition_data.data_length
end
future_partition?() click to toggle source

@return [Boolean]

# File lib/sql_partitioner/partition.rb, line 113
def future_partition?
  self.timestamp == FUTURE_PARTITION_VALUE
end
index_length() click to toggle source

@return [Fixnum]

# File lib/sql_partitioner/partition.rb, line 108
def index_length
  @partition_data.index_length
end
name() click to toggle source

@return [String]

# File lib/sql_partitioner/partition.rb, line 84
def name
  @partition_data.partition_name
end
ordinal_position() click to toggle source

@return [Fixnum]

# File lib/sql_partitioner/partition.rb, line 79
def ordinal_position
  @partition_data.partition_ordinal_position
end
table_rows() click to toggle source

@return [Fixnum]

# File lib/sql_partitioner/partition.rb, line 98
def table_rows
  @partition_data.table_rows
end
timestamp() click to toggle source

@return [Fixnum,String] only a string for “future” partition

# File lib/sql_partitioner/partition.rb, line 89
def timestamp
  if @partition_data.partition_description == FUTURE_PARTITION_VALUE
    FUTURE_PARTITION_VALUE
  else
    @partition_data.partition_description.to_i
  end
end