class Spark::Command::SortByKey


Sort

Public Instance Methods

before_run() click to toggle source

Currently disabled

# File lib/spark/command/sort.rb, line 14
def before_run
  @spilling = false
end
run(iterator, _) click to toggle source
# File lib/spark/command/sort.rb, line 18
def run(iterator, _)
  if @spilling
    iterator = run_with_spilling(iterator.each)
  else
    run_without_spilling(iterator)
  end

  iterator
end
run_with_enum(iterator, _) click to toggle source
# File lib/spark/command/sort.rb, line 28
def run_with_enum(iterator, _)
  if @spilling
    iterator = run_with_spilling(iterator)
  else
    iterator = iterator.to_a
    run_without_spilling(iterator)
  end

  iterator
end

Private Instance Methods

run_with_spilling(iterator) click to toggle source
# File lib/spark/command/sort.rb, line 41
def run_with_spilling(iterator)
  sorter = Spark::ExternalSorter.new(@memory, @serializer)
  sorter.sort_by(iterator, @ascending, @key_function)
end
run_without_spilling(iterator) click to toggle source
# File lib/spark/command/sort.rb, line 46
def run_without_spilling(iterator)
  iterator.sort_by!(&@key_function)
  iterator.reverse! unless @ascending
end