Class: Mysql::Partitioner::Operation::Abstract
- Inherits:
-
Object
- Object
- Mysql::Partitioner::Operation::Abstract
- Defined in:
- lib/mysql/partitioner/operation/abstract.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dry_run ⇒ Object
readonly
Returns the value of attribute dry_run.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #database ⇒ Object
- #empty? ⇒ Boolean
- #get_max_val(key) ⇒ Object
- #get_partition_type ⇒ Object
-
#initialize(table, session) ⇒ Abstract
constructor
A new instance of Abstract.
- #of_max_val(key, field, partition) ⇒ Object
- #partitionated? ⇒ Boolean
Constructor Details
#initialize(table, session) ⇒ Abstract
Returns a new instance of Abstract.
8 9 10 11 |
# File 'lib/mysql/partitioner/operation/abstract.rb', line 8 def initialize(table, session) @table = table @session = session end |
Instance Attribute Details
#dry_run ⇒ Object (readonly)
Returns the value of attribute dry_run.
6 7 8 |
# File 'lib/mysql/partitioner/operation/abstract.rb', line 6 def dry_run @dry_run end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
6 7 8 |
# File 'lib/mysql/partitioner/operation/abstract.rb', line 6 def session @session end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
6 7 8 |
# File 'lib/mysql/partitioner/operation/abstract.rb', line 6 def table @table end |
Instance Method Details
#database ⇒ Object
13 14 15 |
# 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? ⇒ Boolean
33 34 35 |
# 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) ⇒ Object
37 38 39 |
# 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 ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mysql/partitioner/operation/abstract.rb', line 17 def get_partition_type() results = @session.query("SELECT PARTITION_EXPRESSION, PARTITION_DESCRIPTION, PARTITION_ORDINAL_POSITION, PARTITION_METHOD, SUBPARTITION_EXPRESSION\nFROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME=\"\#{ self.table }\" AND TABLE_SCHEMA=\"\#{ database }\" LIMIT 1\n") 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) ⇒ Object
41 42 43 |
# 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? ⇒ Boolean
29 30 31 |
# File 'lib/mysql/partitioner/operation/abstract.rb', line 29 def partitionated?() get_partition_type() != nil end |