Class: SqlPartitioner::PartitionCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/sql_partitioner/partition.rb

Overview

Represents an array of ‘Partition` objects, with some extra helper methods.

Instance Method Summary collapse

Instance Method Details

#current_partition(current_timestamp) ⇒ Partition, NilClass

fetch the partition which is currently active. i.e. holds the records generated now

Parameters:

  • current_timestamp (Fixnum)

Returns:



27
28
29
30
31
# 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

#latest_partitionPartition, NilClass

fetch the latest partition that is not a future partition i.e. (value

is not `FUTURE_PARTITION_VALUE`)

Returns:

  • (Partition, NilClass)

    partition with maximum timestamp value



41
42
43
# File 'lib/sql_partitioner/partition.rb', line 41

def latest_partition
  non_future_partitions.max_by{ |p| p.timestamp }
end

#newer_than_timestamp(timestamp) ⇒ Array<Partition>

selects all partitions that hold records newer than the timestamp provided

Parameters:

  • timestamp (Fixnum)

Returns:

  • (Array<Partition>)

    partitions that hold data newer than given timestamp



18
19
20
21
22
# File 'lib/sql_partitioner/partition.rb', line 18

def newer_than_timestamp(timestamp)
  non_future_partitions.select do |p|
    timestamp <= p.timestamp
  end
end

#non_future_partitionsArray<Partition>

Returns all partitions that do not have timestamp as ‘FUTURE_PARTITION_VALUE`.

Returns:

  • (Array<Partition>)

    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

Parameters:

  • timestamp (Fixnum)

Returns:

  • (Array<Partition>)

    partitions that hold data older than given timestamp



9
10
11
12
13
# File 'lib/sql_partitioner/partition.rb', line 9

def older_than_timestamp(timestamp)
  non_future_partitions.select do |p|
    timestamp > p.timestamp
  end
end

#oldest_partitionPartition, NilClass

Returns the partition with oldest timestamp.

Returns:

  • (Partition, NilClass)

    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.timestamp }
end