def fetch_in_batches(opts={})
      opts[:batch_size] ||= 1000

      # spawn the new query as soon as the enumerable is created
      # rather than waiting until the firt iteration is executed.
      # The client could mutate the object between these moments,
      # however we don't want to spawn twice if a block isn't passed.
      paged_query = opts.delete(:_paged_query) || self.clone

      return to_enum(:fetch_in_batches, opts.merge(_paged_query: paged_query)) unless block_given?

      # use Cassandra internal paging
      # but clone the query to isolate it
      # and allow all paging queries
      # to execute within a Cassie::Query
      # for use of other features, like logging
      #
      # note: stateless page size is independent from limit
      paged_query.stateless_page_size = opts[:batch_size]
      paged_query.paging_state = nil

      loop do
        # done if the previous result was the last page
        break if paged_query.result && paged_query.result.last_page?
        raise page_size_changed_error(opts[:batch_size]) if opts[:batch_size] != paged_query.stateless_page_size

        batch = paged_query.fetch
        paged_query.paging_state = paged_query.result.paging_state

        yield batch
      end
    end
def fetch_in_batches(opts={})
      opts[:batch_size] ||= 1000

      # spawn the new query as soon as the enumerable is created
      # rather than waiting until the firt iteration is executed.
      # The client could mutate the object between these moments,
      # however we don't want to spawn twice if a block isn't passed.
      paged_query = opts.delete(:_paged_query) || self.clone

      return to_enum(:fetch_in_batches, opts.merge(_paged_query: paged_query)) unless block_given?

      # use Cassandra internal paging
      # but clone the query to isolate it
      # and allow all paging queries
      # to execute within a Cassie::Query
      # for use of other features, like logging
      #
      # note: stateless page size is independent from limit
      paged_query.stateless_page_size = opts[:batch_size]
      paged_query.paging_state = nil

      loop do
        # done if the previous result was the last page
        break if paged_query.result && paged_query.result.last_page?
        raise page_size_changed_error(opts[:batch_size]) if opts[:batch_size] != paged_query.stateless_page_size

        batch = paged_query.fetch
        paged_query.paging_state = paged_query.result.paging_state

        yield batch
      end
    end
Yields each batch of records that was found by the options as an array.

 If you do not provide a block to find_in_batches, it will return an Enumerator for chaining with other methods.

  query.fetch_in_batches do |records|
   puts "max score in group: #{records.max{ |a, b| a.score <=> b.score }}"
  end

  "max score in group: 26"

 ==== Options
 * <tt>:batch_size</tt> - Specifies the size of the batch. Default to 1000.

 NOTE: Any limit specified on the query will affect the batched set.
 Cassandra internal paging is used for batching.