Class: Locomotive::RelationalAlgebra::Aggr

Inherits:
Unary show all
Defined in:
lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb

Instance Attribute Summary collapse

Attributes inherited from Operator

#schema

Attributes included from AstHelpers::AstNode

#kind, #left_child, #owner, #right_child, #value

Instance Method Summary collapse

Methods inherited from Operator

#bound, #free, #to_xml, #xml_kind, #xml_schema

Methods included from XML

included, #quote, #to_xml

Methods included from AstHelpers::Annotations

#method_missing, #respond_to?

Methods included from AstHelpers::AstNode

#has_left_child?, #has_right_child?, #is_leaf?, #traverse, #traverse_strategy=

Constructor Details

#initialize(op, aggr_kind, item, over, part) ⇒ Aggr

Returns a new instance of Aggr.



14
15
16
17
18
19
20
# File 'lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb', line 14

def initialize(op, aggr_kind, item, over, part)
  self.item = item
  self.aggr_kind = aggr_kind
  self.over = over
  self.part_list = part
  super(op)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Locomotive::AstHelpers::Annotations

Instance Attribute Details

#aggr_kindObject

Returns the value of attribute aggr_kind.



8
9
10
# File 'lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb', line 8

def aggr_kind
  @aggr_kind
end

#itemObject

Returns the value of attribute item.



8
9
10
# File 'lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb', line 8

def item
  @item
end

#overObject

Returns the value of attribute over.



8
9
10
# File 'lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb', line 8

def over
  @over
end

#part_listObject

Returns the value of attribute part_list.



8
9
10
# File 'lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb', line 8

def part_list
  @part_list
end

Instance Method Details

#child=(op) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb', line 22

def child=(op)
  unless op.schema.attributes?(part_list)
    raise CorruptedSchema,
          "Schema #{op.schema.attributes} does not " \
          "contain all attributes of #{part_list}."
  end
  unless op.schema.attributes?(over)
    raise CorruptedSchema,
          "Schema #{op.schema.attributes} does not " \
          "contain all attributes of #{item}."
  end
  self.schema = Schema.new( { self.item => [RNat.instance] }.merge(
                           Hash[*part_list.collect do |p|
                                   [p, op.schema[p]]
                                 end.flatten_once]))
                        
  super(op)
end

#cloneObject



55
56
57
58
59
60
61
62
# File 'lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb', line 55

def clone
  Aggr.new(
    child.clone,
    aggr_kind.clone,
    over.clone,
    item.clone,
    part_list.clone)
end

#set(var, plan) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb', line 64

def set(var,plan)
  Aggr.new(
    child.set(var,plan),
    aggr_kind.clone,
    item.clone,
    over.clone,
    part_list.clone)
end

#xml_contentObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/locomotive/relational_algebra/operators/aggregation/aggregation.rb', line 41

def xml_content
  content do
    part_list.collect do |part|
      column :name => part.to_xml, :function => :partition, :new => false
    end.join + 
    (aggregate :kind => aggr_kind.to_xml do
      ([column(:name => item.to_xml, :new => true)] + 
       over.map do |c|
         column(:name => c.to_xml, :new => false, :function => :item)
       end).join
    end)
  end
end