Method: Cequel::Record::RecordSet#find_rows_in_batches

Defined in:
lib/cequel/record/record_set.rb

#find_rows_in_batches(options = {}) {|batch| ... } ⇒ Enumerator, void

Enumerate over batches of row data for the records in this record set.

Parameters:

  • options (Options) (defaults to: {})

    options for querying the database

Options Hash (options):

  • :batch_size (Integer) — default: 1000

    the maximum number of rows to return per batch query

Yield Parameters:

  • batch (Array<Hash<Symbol,Object>>)

    a batch of rows

Returns:

  • (Enumerator)

    if no block given

  • (void)

See Also:

Since:

  • 1.0.0



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# File 'lib/cequel/record/record_set.rb', line 645

def find_rows_in_batches(options = {}, &block)
  return find_rows_in_single_batch(options, &block) if row_limit
  options.assert_valid_keys(:batch_size)
  batch_size = options.fetch(:batch_size, 1000)
  batch_record_set = base_record_set = limit(batch_size)
  more_results = true

  while more_results
    rows = batch_record_set.find_rows_in_single_batch
    yield rows if rows.any?
    more_results = rows.length == batch_size
    last_row = rows.last
    if more_results
      find_nested_batches_from(last_row, options, &block)
      batch_record_set = base_record_set.next_batch_from(last_row)
    end
  end
end