module Cassie::Statements::Execution::PartitionLinking::PolicyMethods
Public Class Methods
new(executed, identifier, direction, range)
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 11 def initialize(executed, identifier, direction, range) @peeking_execution = executed @identifier = identifier @direction = direction @range = range end
Public Instance Methods
end_of_partition?()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 40 def end_of_partition? !peeking_execution.result.peeked_row rescue NoMethodError => ex message = "Results aren't available for linking. Did you forget to call `execute`?" if peeking_execution.result.nil? message ||= "Peeking not enabled. To link partitions, peeking must be included in the execution. Did you forget to call `link_partitions`?" raise ArgumentError, message end
link()
click to toggle source
returns linked result
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 19 def link if seek_partition? && partition_available? prepare_execution execution.execute combine_results else peeking_execution.result end end
partition_available?()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 48 def partition_available? key = ascending? ? next_key(current_key) : previous_key(current_key) key >= first_key && key <= last_key end
prepare_execution()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 29 def prepare_execution @execution = peeking_execution.clone change_partition adjust_limit execution end
seek_partition?()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 36 def seek_partition? end_of_partition? end
Protected Instance Methods
adjust_limit()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 85 def adjust_limit execution.limit = execution.limit - peeked_rows.count end
ascending?()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 101 def ascending? [:ascending, :asc, :ASC].include? direction end
change_partition()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 63 def change_partition key = if ascending? # explicitly pass key to keep policy subclass # interface clear and consistent next_key(current_key) else # explicitly pass key to keep policy subclass # interface clear and consistent previous_key(current_key) end if key < first_key || key > last_key logger.warn("warning: linking to partition that is outside of ranges defined. #{key} outside of (#{first_key}..#{last_key}). This could result in unexpected records being returned.") end # define object singleton method to # override getter for partition key # returning the partion that needs to be linked execution.define_singleton_method(identifier) do key end end
combine_results()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 93 def combine_results rows = combine_rows(peeked_rows.to_a , execution_rows.to_a) execution.result.define_singleton_method(:rows) do rows end execution.result end
current_key()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 89 def current_key peeking_execution.send(identifier) end
eval_opt(value, src=source)
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 117 def eval_opt(value, src=source) case value when Symbol src.send(value) else value end end
execution_rows()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 109 def execution_rows execution.result.rows end
first_key()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 55 def first_key eval_opt(range.first, peeking_execution) end
last_key()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 59 def last_key eval_opt(range.last, peeking_execution) end
logger()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 113 def logger Cassie::Statements.logger end
peeked_rows()
click to toggle source
# File lib/cassie/statements/execution/partition_linking/policy_methods.rb, line 105 def peeked_rows peeking_execution.result.rows end