Class: SqlPartitioner::BasePartitionsManager
- Inherits:
-
Object
- Object
- SqlPartitioner::BasePartitionsManager
- Defined in:
- lib/sql_partitioner/base_partitions_manager.rb
Direct Known Subclasses
Constant Summary collapse
- FUTURE_PARTITION_NAME =
'future'
- FUTURE_PARTITION_VALUE =
'MAXVALUE'
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#current_timestamp ⇒ Object
Returns the value of attribute current_timestamp.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Instance Method Summary collapse
-
#drop_partitions(partition_names, dry_run = false) ⇒ String
Drop partitions by name.
-
#initialize(options = {}) ⇒ BasePartitionsManager
constructor
A new instance of BasePartitionsManager.
-
#initialize_partitioning(partition_data, dry_run = false) ⇒ Object
initialize partitioning on the given table based on partition_data provided.
- #log(message, prefix = true) ⇒ Object
-
#name_from_timestamp(timestamp) ⇒ String
generates name of for “until_yyyy_mm_dd” from the given timestamp.
-
#reorg_future_partition(partition_data, dry_run = false) ⇒ Boolean, String
Reorgs future partition into partitions provided as input.
Constructor Details
#initialize(options = {}) ⇒ BasePartitionsManager
Returns a new instance of BasePartitionsManager.
24 25 26 27 28 29 30 31 32 |
# File 'lib/sql_partitioner/base_partitions_manager.rb', line 24 def initialize( = {}) @adapter = [:adapter] @tuc = TimeUnitConverter.new([:time_unit] || :seconds) @current_timestamp = @tuc.from_seconds(([:current_time] || Time.now).to_i) @table_name = [:table_name] @logger = [:logger] @lock_wait_timeout = [:lock_wait_timeout] end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
4 5 6 |
# File 'lib/sql_partitioner/base_partitions_manager.rb', line 4 def adapter @adapter end |
#current_timestamp ⇒ Object
Returns the value of attribute current_timestamp.
4 5 6 |
# File 'lib/sql_partitioner/base_partitions_manager.rb', line 4 def @current_timestamp end |
#logger ⇒ Object
Returns the value of attribute logger.
4 5 6 |
# File 'lib/sql_partitioner/base_partitions_manager.rb', line 4 def logger @logger end |
#table_name ⇒ Object
Returns the value of attribute table_name.
4 5 6 |
# File 'lib/sql_partitioner/base_partitions_manager.rb', line 4 def table_name @table_name end |
Instance Method Details
#drop_partitions(partition_names, dry_run = false) ⇒ String
Drop partitions by name
63 64 65 66 67 68 |
# File 'lib/sql_partitioner/base_partitions_manager.rb', line 63 def drop_partitions(partition_names, dry_run = false) _validate_drop_partitions_names(partition_names) drop_sql = SqlPartitioner::SQL.drop_partitions(table_name, partition_names) _execute_and_display_partition_info(drop_sql, dry_run) end |
#initialize_partitioning(partition_data, dry_run = false) ⇒ Object
initialize partitioning on the given table based on partition_data provided. partition data should be of form
{partition_name1 => ,
partition_name2 => ...}
For example:
{'until_2014_03_17' => 1395077901193149,
'until_2014_04_01' => 1396373901193398}
48 49 50 51 52 53 54 55 |
# File 'lib/sql_partitioner/base_partitions_manager.rb', line 48 def initialize_partitioning(partition_data, dry_run = false) partition_data = partition_data.merge(FUTURE_PARTITION_NAME => FUTURE_PARTITION_VALUE) _validate_partition_data(partition_data) init_sql = SqlPartitioner::SQL.initialize_partitioning(table_name, partition_data) _execute_and_display_partition_info(init_sql, dry_run) end |
#log(message, prefix = true) ⇒ Object
89 90 91 92 |
# File 'lib/sql_partitioner/base_partitions_manager.rb', line 89 def log(, prefix = true) = "[#{self.class.name}]#{}" if prefix @logger.info "#{}" end |
#name_from_timestamp(timestamp) ⇒ String
generates name of for “until_yyyy_mm_dd” from the given timestamp. returns future partition name if value is FUTURE_PARTITION_VALUE
101 102 103 104 105 106 107 108 |
# File 'lib/sql_partitioner/base_partitions_manager.rb', line 101 def () if == FUTURE_PARTITION_VALUE FUTURE_PARTITION_NAME else seconds = @tuc.to_seconds() "until_#{Time.at(seconds).utc.strftime("%Y_%m_%d")}" end end |
#reorg_future_partition(partition_data, dry_run = false) ⇒ Boolean, String
Reorgs future partition into partitions provided as input.
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sql_partitioner/base_partitions_manager.rb', line 76 def reorg_future_partition(partition_data, dry_run = false) partition_data = partition_data.dup if partition_data.any? partition_data[FUTURE_PARTITION_NAME] = FUTURE_PARTITION_VALUE end _validate_partition_data(partition_data) reorg_sql = SqlPartitioner::SQL.reorg_partitions(table_name, partition_data, FUTURE_PARTITION_NAME) _execute_and_display_partition_info(reorg_sql, dry_run) end |