Class: Sparkql::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/sparkql/evaluator.rb

Overview

Using an instance of ExpressionResolver to resolve the individual expressions, this class will evaluate the rest of a parsed sparkql string to true or false. Namely, this class will handle all the nesting, boolean algebra, and dropped fields. Plus, it has some optimizations built in to skip the processing for any expressions that don’t contribute to the net result of the filter.

Defined Under Namespace

Classes: Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression_resolver) ⇒ Evaluator

Returns a new instance of Evaluator.



23
24
25
# File 'lib/sparkql/evaluator.rb', line 23

def initialize expression_resolver
  @resolver = expression_resolver
end

Instance Attribute Details

#processed_countObject (readonly)

Returns the value of attribute processed_count.



21
22
23
# File 'lib/sparkql/evaluator.rb', line 21

def processed_count
  @processed_count
end

Instance Method Details

#evaluate(expressions) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sparkql/evaluator.rb', line 27

def evaluate(expressions)
  @processed_count = 0
  @index = Node.new(0, 0, "And", 0, true, false, 0, nil)
  @groups = [@index]
  expressions.each do |expression|
    handle_group(expression)
    adjust_expression_for_dropped_field(expression)
    check_for_good_ors(expression)
    next if skip?(expression)
    evaluate_expression(expression)
  end
  cleanup
  return @index[:match]
end