Class: NoSE::Backend::FileBackend::IndexLookupStatementStep

Inherits:
Backend::IndexLookupStatementStep show all
Includes:
RowMatcher
Defined in:
lib/nose/backend/file.rb

Overview

Look up data on an index in the backend

Instance Attribute Summary

Attributes inherited from Backend::StatementStep

#index

Instance Method Summary collapse

Methods included from RowMatcher

#row_matches?, #row_matches_eq?, #row_matches_range?

Methods inherited from Backend::IndexLookupStatementStep

#initialize

Methods included from Supertype

included

Constructor Details

This class inherits a constructor from NoSE::Backend::Backend::IndexLookupStatementStep

Instance Method Details

#process(conditions, results) ⇒ Object

Filter all the rows in the specified index to those requested



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/nose/backend/file.rb', line 113

def process(conditions, results)
  # Get the set of conditions we need to process
  results = initial_results(conditions) if results.nil?
  condition_list = result_conditions conditions, results

  # Loop through all rows to find the matching ones
  rows = @client[@index.key] || []
  selected = condition_list.flat_map do |condition|
    rows.select { |row| row_matches? row, condition }
  end.compact

  # Apply the limit and only return selected fields
  field_ids = Set.new @step.fields.map(&:id).to_set
  selected[0..(@step.limit.nil? ? -1 : @step.limit)].map do |row|
    row.select { |k, _| field_ids.include? k }
  end
end