class SqlPartitioner::PartitionCollection
Represents an array of ‘Partition` objects, with some extra helper methods.
Public Instance Methods
fetch the partition which is currently active. i.e. holds the records generated now @param [Fixnum] current_timestamp @return [Partition,NilClass]
# File lib/sql_partitioner/partition.rb, line 27 def current_partition(current_timestamp) non_future_partitions.select do |p| p.timestamp > current_timestamp end.min_by { |p| p.timestamp } end
fetch the latest partition that is not a future partition i.e. (value
is not `FUTURE_PARTITION_VALUE`)
@return [Partition,NilClass] partition with maximum timestamp value
# File lib/sql_partitioner/partition.rb, line 41 def latest_partition non_future_partitions.max_by{ |p| p.timestamp } end
selects all partitions that hold records newer than the timestamp provided @param [Fixnum] timestamp @return [Array<Partition>] partitions that hold data newer than given timestamp
# File lib/sql_partitioner/partition.rb, line 18 def newer_than_timestamp(timestamp) non_future_partitions.select do |p| timestamp <= p.timestamp end end
@return [Array<Partition>] all partitions that do not have timestamp as ‘FUTURE_PARTITION_VALUE`
# File lib/sql_partitioner/partition.rb, line 34 def non_future_partitions self.reject { |p| p.future_partition? } end
selects all partitions that hold records older than the timestamp provided @param [Fixnum] timestamp @return [Array<Partition>] partitions that hold data older than given timestamp
# File lib/sql_partitioner/partition.rb, line 9 def older_than_timestamp(timestamp) non_future_partitions.select do |p| timestamp > p.timestamp end end
@return [Partition,NilClass] the partition with oldest timestamp
# File lib/sql_partitioner/partition.rb, line 46 def oldest_partition non_future_partitions.min_by { |p| p.timestamp } end