Module: RR::TableScanHelper

Included in:
DirectTableScan, ProxyBlockCursor, TableScan
Defined in:
lib/rubyrep/table_scan_helper.rb

Overview

Some helper functions that are of use to all TableScan classes

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.scan_class(session) ⇒ Object

Returns the correct class for the table scan based on the type of the session (proxied or direct).



30
31
32
33
34
35
36
# File 'lib/rubyrep/table_scan_helper.rb', line 30

def self.scan_class(session)
  if session.proxied?
    ProxiedTableScan
  else
    DirectTableScan
  end
end

Instance Method Details

#rank_rows(left_row, right_row) ⇒ Object

Compares the primary keys of left_row and right_row to determine their rank. Assumes there is a function primary_key_names returning the array of primary keys that are relevant for this comparison

Assumes that at least one of left_row and right_row is not nil A nil row counts as infinite.

    1. left_row is something and right_row is nil ==> left_row is smaller ==> return -1



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubyrep/table_scan_helper.rb', line 16

def rank_rows(left_row, right_row)
  raise "At least one of left_row and right_row must not be nil!" unless left_row or right_row
  return -1 unless right_row
  return 1 unless left_row 
  rank = 0
  primary_key_names.any? do |key|
    rank = left_row[key] <=> right_row[key]
    rank != 0
  end
  rank
end