Class: DDQL::CoalesceOperator

Inherits:
AggOperator show all
Defined in:
lib/ddql/coalesce_operator.rb

Instance Attribute Summary

Attributes inherited from Operator

#associativity, #name, #precedence, #return_type, #symbol, #type

Instance Method Summary collapse

Methods inherited from AggOperator

#as_agg, #as_left_op_right

Methods inherited from Operator

#any_type?, #boolean?, #comparison?, #complex_comparison?, #infix?, #left?, #math?, #pattern, #postfix?, #prefix?, #register, #right?, #simple_comparison?, #type?

Constructor Details

#initializeCoalesceOperator

Returns a new instance of CoalesceOperator.



3
4
5
# File 'lib/ddql/coalesce_operator.rb', line 3

def initialize
  super("COALESCE", "Coalesce", return_type: :match)
end

Instance Method Details

#parse(parser, token, expression: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ddql/coalesce_operator.rb', line 7

def parse(parser, token, expression: nil)
  new_expression = parser.parse(precedence: precedence)
  if expression
    expression = expression.merge(new_expression)
  else
    expression = new_expression
  end

  left_factor, right_factor = expression[:string].split('|', 2)

  {
    op_coalesce: [
      {factor: left_factor},
      {factor: right_factor},
    ]
  }
end