Class: Locomotive::RelationalAlgebra::SerializeRelation

Inherits:
Serialize show all
Includes:
XML
Defined in:
lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb

Overview

serialize operator

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 included from XML

included, #quote, #to_xml

Methods inherited from Operator

#bound, #free, #to_xml, #xml_schema

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(side, alg, iter, pos, items) ⇒ SerializeRelation

Returns a new instance of SerializeRelation.



17
18
19
20
21
22
# File 'lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb', line 17

def initialize(side,alg,iter,pos,items)
  self.iter,
  self.pos,
  self.items = iter, pos, items
  super(side,alg)
end

Dynamic Method Handling

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

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



10
11
12
# File 'lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb', line 10

def items
  @items
end

#iterObject

Returns the value of attribute iter.



10
11
12
# File 'lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb', line 10

def iter
  @iter
end

#posObject

Returns the value of attribute pos.



10
11
12
# File 'lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb', line 10

def pos
  @pos
end

Instance Method Details

#cloneObject



85
86
87
88
89
90
91
# File 'lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb', line 85

def clone
  Serialization.new(left.clone,
                    right.clone,
                    iter.clone,
                    pos.clone,
                    items.clone)
end

#left_and_right(side, alg) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb', line 24

def left_and_right(side,alg)
  unless alg.schema.attributes?([self.iter])
    raise CorruptedSchema,
          "Schema #{alg.schema.attributes} does not " \
          "contain all attributes of #{iter}."
  end
  unless alg.schema.attributes?([self.pos])
    raise CorruptedSchema,
          "Schema #{alg.schema.attributes} does not " \
          "contain all attributes of #{pos}."
  end
  unless alg.schema.attributes?(self.items)
    raise CorruptedSchema,
          "Schema #{alg.schema.attributes} does not " \
          "contain all attributes of #{items}."
  end
  self.schema = alg.schema.clone
  super(side,alg)
end

#serializeObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb', line 64

def serialize
  xml_id = 0
  xml_list = []
    
  self.traverse_strategy = Locomotive::AstHelpers::PostOrderTraverse
  self.traverse do |op|
    next if op.ann_vis
    op.ann_xml_id = xml_id += 1
    xml_list << op.to_xml
    op.ann_vis = true
  end

  self.traverse do |op|
    op.ann_vis = false
  end
    
  logical_query_plan :unique_names => true do
    xml_list.join
  end
end

#set(var, plan) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb', line 93

def set(var,plan)
  Serialization.new(
    left.set(var,plan),
    right.set(var,plan),
    iter.clone,
    pos.clone,
    items.clone)
end

#xml_contentObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb', line 48

def xml_content
  pos_ = -1
  content do
    [
      column(:name => iter.to_xml, :new => false, :function => :iter),
      column(:name => pos.to_xml, :new => false, :function => :pos),
      items.collect do |it|
        column :name => it.to_xml,
               :new => false,
               :function => :item,
               :position => pos_ += 1
      end.join
    ].join
  end
end

#xml_kindObject



44
45
46
# File 'lib/locomotive/relational_algebra/operators/serialization/serialize_relation.rb', line 44

def xml_kind
  "serialize relation".to_sym
end