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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression_resolver) ⇒ Evaluator

Returns a new instance of Evaluator.



9
10
11
# File 'lib/sparkql/evaluator.rb', line 9

def initialize(expression_resolver)
  @resolver = expression_resolver
end

Instance Attribute Details

#processed_countObject (readonly)

Returns the value of attribute processed_count.



7
8
9
# File 'lib/sparkql/evaluator.rb', line 7

def processed_count
  @processed_count
end

Instance Method Details

#evaluate(expressions) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sparkql/evaluator.rb', line 13

def evaluate(expressions)
  @processed_count = 0
  levels = {}
  block_groups = {}

  build_structures(levels, block_groups, expressions)

  final_result = process_structures(levels, block_groups)
  # If we didn't process anything, we consider that a success
  if final_result.nil?
    final_result = true
  end

  final_result
end