Class: Rgviz::MemoryExecutor::EvalWhereVisitor
- Inherits:
-
EvalSelectVisitor
- Object
- Visitor
- EvalSelectVisitor
- Rgviz::MemoryExecutor::EvalWhereVisitor
- Defined in:
- lib/rgviz/memory_executor.rb
Instance Attribute Summary
Attributes inherited from EvalSelectVisitor
Instance Method Summary collapse
-
#initialize(types_to_indices, row) ⇒ EvalWhereVisitor
constructor
A new instance of EvalWhereVisitor.
- #visit_aggregate_column(col) ⇒ Object
- #visit_binary_expression(node) ⇒ Object
- #visit_logical_expression(node) ⇒ Object
- #visit_unary_expression(node) ⇒ Object
Methods inherited from EvalSelectVisitor
#visit_boolean_column, #visit_date_column, #visit_date_time_column, #visit_id_column, #visit_number_column, #visit_scalar_function_column, #visit_string_column, #visit_time_of_day_column
Constructor Details
#initialize(types_to_indices, row) ⇒ EvalWhereVisitor
Returns a new instance of EvalWhereVisitor.
509 510 511 512 |
# File 'lib/rgviz/memory_executor.rb', line 509 def initialize(types_to_indices, row) @row = row @types_to_indices = types_to_indices end |
Instance Method Details
#visit_aggregate_column(col) ⇒ Object
514 515 516 |
# File 'lib/rgviz/memory_executor.rb', line 514 def visit_aggregate_column(col) raise "Aggregation function #{col.function} cannot be used in where clause" end |
#visit_binary_expression(node) ⇒ Object
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/rgviz/memory_executor.rb', line 518 def visit_binary_expression(node) node.left.accept self; left = @value node.right.accept self; right = @value case node.operator when BinaryExpression::Gt @value = left > right when BinaryExpression::Gte @value = left >= right when BinaryExpression::Lt @value = left < right when BinaryExpression::Lte @value = left <= right when BinaryExpression::Eq @value = left == right when BinaryExpression::Neq @value = left != right when BinaryExpression::Contains @value = !!left[right] when BinaryExpression::StartsWith @value = left.start_with? right when BinaryExpression::EndsWith @value = left.end_with? right when BinaryExpression::Like right.gsub!('%', '.*') right.gsub!('_', '.') right = Regexp.new right @value = !!(left =~ right) when BinaryExpression::Matches right = Regexp.new "^#{right}$" @value = !!(left =~ right) end false end |
#visit_logical_expression(node) ⇒ Object
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/rgviz/memory_executor.rb', line 552 def visit_logical_expression(node) values = [] node.operands.each do |op| op.accept self values << @value end case node.operator when LogicalExpression::And node.operands.each do |op| op.accept self break unless @value end when LogicalExpression::Or node.operands.each do |op| op.accept self break if @value end end false end |
#visit_unary_expression(node) ⇒ Object
573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/rgviz/memory_executor.rb', line 573 def visit_unary_expression(node) node.operand.accept self case node.operator when UnaryExpression::Not @value = !@value when UnaryExpression::IsNull @value = @value.nil? when UnaryExpression::IsNotNull @value = !@value.nil? end false end |