Class: SqlPartitioner::PartitionCollection
- Inherits:
-
Array
- Object
- Array
- SqlPartitioner::PartitionCollection
- Defined in:
- lib/sql_partitioner/partition.rb
Overview
Represents an array of ‘Partition` objects, with some extra helper methods.
Instance Method Summary collapse
-
#current_partition(current_timestamp) ⇒ Partition, NilClass
fetch the partition which is currently active.
-
#latest_partition ⇒ Partition, NilClass
fetch the latest partition that is not a future partition i.e.
-
#newer_than_timestamp(timestamp) ⇒ Array<Partition>
selects all partitions that hold records newer than the timestamp provided.
-
#non_future_partitions ⇒ Array<Partition>
All partitions that do not have timestamp as ‘FUTURE_PARTITION_VALUE`.
-
#older_than_timestamp(timestamp) ⇒ Array<Partition>
selects all partitions that hold records older than the timestamp provided.
-
#oldest_partition ⇒ Partition, NilClass
The partition with oldest timestamp.
Instance Method Details
#current_partition(current_timestamp) ⇒ Partition, NilClass
fetch the partition which is currently active. i.e. holds the records generated now
27 28 29 30 31 |
# File 'lib/sql_partitioner/partition.rb', line 27 def current_partition() non_future_partitions.select do |p| p. > end.min_by { |p| p. } end |
#latest_partition ⇒ Partition, NilClass
fetch the latest partition that is not a future partition i.e. (value
is not `FUTURE_PARTITION_VALUE`)
41 42 43 |
# File 'lib/sql_partitioner/partition.rb', line 41 def latest_partition non_future_partitions.max_by{ |p| p. } end |
#newer_than_timestamp(timestamp) ⇒ Array<Partition>
selects all partitions that hold records newer than the timestamp provided
18 19 20 21 22 |
# File 'lib/sql_partitioner/partition.rb', line 18 def () non_future_partitions.select do |p| <= p. end end |
#non_future_partitions ⇒ Array<Partition>
Returns all partitions that do not have timestamp as ‘FUTURE_PARTITION_VALUE`.
34 35 36 |
# File 'lib/sql_partitioner/partition.rb', line 34 def non_future_partitions self.reject { |p| p.future_partition? } end |
#older_than_timestamp(timestamp) ⇒ Array<Partition>
selects all partitions that hold records older than the timestamp provided
9 10 11 12 13 |
# File 'lib/sql_partitioner/partition.rb', line 9 def () non_future_partitions.select do |p| > p. end end |
#oldest_partition ⇒ Partition, NilClass
Returns the partition with oldest timestamp.
46 47 48 |
# File 'lib/sql_partitioner/partition.rb', line 46 def oldest_partition non_future_partitions.min_by { |p| p. } end |