class Mysql::Partitioner::Operation::Abstract
Attributes
dry_run[R]
session[R]
table[R]
Public Class Methods
new(table, session)
click to toggle source
# File lib/mysql/partitioner/operation/abstract.rb, line 8 def initialize(table, session) @table = table @session = session end
Public Instance Methods
database()
click to toggle source
# File lib/mysql/partitioner/operation/abstract.rb, line 13 def database @database = @database || @session.query("SELECT DATABASE()").first.values[0] or raise "database not selected" end
empty?()
click to toggle source
# File lib/mysql/partitioner/operation/abstract.rb, line 33 def empty?() @session.query("SELECT 1 FROM #{@table} LIMIT 1").first.nil? end
get_max_val(key)
click to toggle source
# File lib/mysql/partitioner/operation/abstract.rb, line 37 def get_max_val(key) @session.query("SELECT MAX(#{key}) FROM #{@table}").first.values[0] end
get_partition_type()
click to toggle source
# File lib/mysql/partitioner/operation/abstract.rb, line 17 def get_partition_type() results = @session.query(<<SQL) SELECT PARTITION_EXPRESSION, PARTITION_DESCRIPTION, PARTITION_ORDINAL_POSITION, PARTITION_METHOD, SUBPARTITION_EXPRESSION FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME="#{ self.table }" AND TABLE_SCHEMA="#{ database }" LIMIT 1 SQL row = results.first if row.nil? then raise "Table not found table=#{self.table} db=#{self.database}" end return row["PARTITION_METHOD"] end
of_max_val(key, field, partition)
click to toggle source
# File lib/mysql/partitioner/operation/abstract.rb, line 41 def of_max_val(key, field, partition) @session.query("SELECT MAX(#{key}), #{field} FROM #{@table} PARTITION(#{partition})").first.values[1] end
partitionated?()
click to toggle source
# File lib/mysql/partitioner/operation/abstract.rb, line 29 def partitionated?() get_partition_type() != nil end