Class: NoSE::Backend::MongoBackend::IndexLookupStatementStep

Inherits:
Backend::IndexLookupStatementStep show all
Defined in:
lib/nose/backend/mongo.rb

Overview

A query step to look up data from a particular collection

Instance Attribute Summary

Attributes inherited from Backend::StatementStep

#index

Instance Method Summary collapse

Methods included from Supertype

included

Constructor Details

#initialize(client, select, conditions, step, next_step, prev_step) ⇒ IndexLookupStatementStep

rubocop:disable Metrics/ParameterLists



176
177
178
179
180
181
182
183
# File 'lib/nose/backend/mongo.rb', line 176

def initialize(client, select, conditions, step, next_step, prev_step)
  super

  @logger = Logging.logger['nose::backend::mongo::indexlookupstep']
  @order = @step.order_by.map do |field|
    { MongoBackend.field_path(@index, field).join('.') => 1 }
  end
end

Instance Method Details

#process(conditions, results) ⇒ Object

Perform a column family lookup in MongoDB



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/nose/backend/mongo.rb', line 187

def process(conditions, results)
  results = initial_results(conditions) if results.nil?
  condition_list = result_conditions conditions, results

  new_result = condition_list.flat_map do |result_conditions|
    query_doc = query_doc_for_conditions result_conditions
    result = @client[@index.to_id_graph.key].find(query_doc)
    result = result.sort(*@order) unless @order.empty?

    result.to_a
  end

  # Limit the size of the results in case we fetched multiple keys
  new_result = new_result[0..(@step.limit.nil? ? -1 : @step.limit)]
  MongoBackend.rows_from_mongo new_result, @index, @step.fields
end