Class: Sparkql::Evaluator
- Inherits:
-
Object
- Object
- Sparkql::Evaluator
- Includes:
- Token
- 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.
Constant Summary
Constants included from Token
Token::ADD, Token::AND, Token::BOOLEAN, Token::CHARACTER, Token::CONJUNCTIONS, Token::CUSTOM_FIELD, Token::DATE, Token::DATETIME, Token::DECIMAL, Token::DIV, Token::EQUAL, Token::EQUALITY_OPERATORS, Token::INTEGER, Token::KEYWORD, Token::LPAREN, Token::MOD, Token::MUL, Token::NEWLINE, Token::NOT, Token::NOT_EQUAL, Token::NULL, Token::OPERATORS, Token::OR, Token::RANGE_OPERATOR, Token::RPAREN, Token::SPACE, Token::STANDARD_FIELD, Token::SUB, Token::TIME, Token::UNARY_CONJUNCTIONS
Instance Attribute Summary collapse
-
#processed_count ⇒ Object
readonly
Returns the value of attribute processed_count.
Instance Method Summary collapse
- #evaluate(expressions) ⇒ Object
-
#initialize(expression_resolver) ⇒ Evaluator
constructor
A new instance of Evaluator.
Constructor Details
#initialize(expression_resolver) ⇒ Evaluator
Returns a new instance of Evaluator.
12 13 14 |
# File 'lib/sparkql/evaluator.rb', line 12 def initialize(expression_resolver) @resolver = expression_resolver end |
Instance Attribute Details
#processed_count ⇒ Object (readonly)
Returns the value of attribute processed_count.
10 11 12 |
# File 'lib/sparkql/evaluator.rb', line 10 def processed_count @processed_count end |
Instance Method Details
#evaluate(expressions) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sparkql/evaluator.rb', line 16 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 |