Class: Druid::PostAggregationOperation

Inherits:
Object
  • Object
show all
Includes:
PostAggregationOperators
Defined in:
lib/druid/post_aggregation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PostAggregationOperators

#*, #+, #-, #/

Constructor Details

#initialize(left, operator, right) ⇒ PostAggregationOperation

Returns a new instance of PostAggregationOperation.



41
42
43
44
45
# File 'lib/druid/post_aggregation.rb', line 41

def initialize(left, operator, right)
  @left = left.is_a?(Numeric) ? PostAggregationConstant.new(left) : left
  @operator = operator
  @right = right.is_a?(Numeric) ? PostAggregationConstant.new(right) : right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



39
40
41
# File 'lib/druid/post_aggregation.rb', line 39

def left
  @left
end

#nameObject (readonly)

Returns the value of attribute name.



39
40
41
# File 'lib/druid/post_aggregation.rb', line 39

def name
  @name
end

#operatorObject (readonly)

Returns the value of attribute operator.



39
40
41
# File 'lib/druid/post_aggregation.rb', line 39

def operator
  @operator
end

#rightObject (readonly)

Returns the value of attribute right.



39
40
41
# File 'lib/druid/post_aggregation.rb', line 39

def right
  @right
end

Instance Method Details

#as(field) ⇒ Object



47
48
49
50
# File 'lib/druid/post_aggregation.rb', line 47

def as(field)
  @name = field.name.to_s
  self
end

#as_json(*a) ⇒ Object



69
70
71
# File 'lib/druid/post_aggregation.rb', line 69

def as_json(*a)
  to_hash
end

#get_field_namesObject



52
53
54
55
56
57
# File 'lib/druid/post_aggregation.rb', line 52

def get_field_names
  field_names = []
  field_names << left.get_field_names if left.respond_to?(:get_field_names)
  field_names << right.get_field_names if right.respond_to?(:get_field_names)
  field_names
end

#to_hashObject



59
60
61
62
63
# File 'lib/druid/post_aggregation.rb', line 59

def to_hash
  hash = { "type" => "arithmetic", "fn" => @operator, "fields" => [@left.to_hash, @right.to_hash] }
  hash["name"] = @name if @name
  hash
end

#to_json(*a) ⇒ Object



65
66
67
# File 'lib/druid/post_aggregation.rb', line 65

def to_json(*a)
  to_hash.to_json(*a)
end