Class: Gandiva::ExpressionBuilder::Literal

Inherits:
Object
  • Object
show all
Defined in:
lib/gandiva/expression-builder/literal.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_class, value) ⇒ Literal

Returns a new instance of Literal.



55
56
57
58
# File 'lib/gandiva/expression-builder/literal.rb', line 55

def initialize(node_class, value)
  @node_class = node_class
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



54
55
56
# File 'lib/gandiva/expression-builder/literal.rb', line 54

def value
  @value
end

Class Method Details

.resolve(value) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gandiva/expression-builder/literal.rb', line 22

def resolve(value)
  case value
  when true, false
    new(BooleanLiteralNode, value)
  when Integer
    if value < -(2 ** 31)
      new(Int64LiteralNode, value)
    elsif value < -(2 ** 15)
      new(Int32LiteralNode, value)
    elsif value < -(2 ** 7)
      new(Int16LiteralNode, value)
    elsif value < 0
      new(Int8LiteralNode, value)
    elsif value < (2 ** 8 - 1)
      new(UInt8LiteralNode, value)
    elsif value < (2 ** 16 - 1)
      new(UInt16LiteralNode, value)
    elsif value < (2 ** 32 - 1)
      new(UInt32LiteralNode, value)
    else
      new(UInt64LiteralNode, value)
    end
  when Float
    new(DoubleLiteralNode, value)
  when String
    new(StringLiteralNode, value)
  else
    nil
  end
end

Instance Method Details

#buildObject



60
61
62
# File 'lib/gandiva/expression-builder/literal.rb', line 60

def build
  @node_class.new(value)
end