Class: NoSE::Backend::Backend::FilterStatementStep

Inherits:
StatementStep show all
Defined in:
lib/nose/backend.rb

Overview

Perform filtering external to the backend

Instance Attribute Summary

Attributes inherited from StatementStep

#index

Instance Method Summary collapse

Methods included from Supertype

included

Constructor Details

#initialize(_client, _fields, _conditions, step, _next_step, _prev_step) ⇒ FilterStatementStep

Returns a new instance of FilterStatementStep.



221
222
223
224
# File 'lib/nose/backend.rb', line 221

def initialize(_client, _fields, _conditions,
               step, _next_step, _prev_step)
  @step = step
end

Instance Method Details

#process(conditions, results) ⇒ Array<Hash>

Filter results by a list of fields given in the step

Returns:



228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/nose/backend.rb', line 228

def process(conditions, results)
  # Extract the equality conditions
  eq_conditions = conditions.values.select do |condition|
    !condition.range? && @step.eq.include?(condition.field)
  end

  # XXX: This assumes that the range filter step is the same as
  #      the one in the query, which is always true for now
  range = @step.range && conditions.each_value.find(&:range?)

  results.select! { |row| include_row?(row, eq_conditions, range) }

  results
end