Class: OMF::Rete::Planner::JoinPlan
- Inherits:
-
AbstractPlan
- Object
- AbstractPlan
- OMF::Rete::Planner::JoinPlan
- Defined in:
- lib/omf_rete/planner/join_plan.rb
Overview
This class represents a planned join op.
Instance Attribute Summary
Attributes inherited from AbstractPlan
Instance Method Summary collapse
-
#cost ⇒ Object
Return the cost of this plan.
- #describe(out = STDOUT, offset = 0, incr = 2, sep = "\n") ⇒ Object
-
#hash ⇒ Object
Create a hash for this plan which allows us to to identify identical plans.
-
#initialize(stream1, stream2, joinSet, resultSet, coverSet, planBuilder) ⇒ JoinPlan
constructor
stream1 - first stream to join stream2 - second stream to join joinSet - set of bindings to join on resultSet - set of bindings in result coverSet - set of leaf nodes contributing to this result.
-
#materialize(indexPattern, resultSet, opts, &block) ⇒ Object
Materialize the plan.
- #to_s ⇒ Object
Methods inherited from AbstractPlan
#complete, #complete?, #result_description, #used, #used?
Constructor Details
#initialize(stream1, stream2, joinSet, resultSet, coverSet, planBuilder) ⇒ JoinPlan
stream1 - first stream to join stream2 - second stream to join joinSet - set of bindings to join on resultSet - set of bindings in result coverSet - set of leaf nodes contributing to this result
20 21 22 23 24 25 26 27 |
# File 'lib/omf_rete/planner/join_plan.rb', line 20 def initialize(stream1, stream2, joinSet, resultSet, coverSet, planBuilder) super coverSet, resultSet @planBuilder = planBuilder @left = stream1 @right = stream2 @join_set = joinSet end |
Instance Method Details
#cost ⇒ Object
Return the cost of this plan.
TODO: Some more meaningful heuristic will be nice
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/omf_rete/planner/join_plan.rb', line 67 def cost() unless @cost lcost = @left.cost() rcost = @right.cost() #@cost = 1 + 1.2 * (lcost > rcost ? lcost : rcost) @cost = 1 + 1.2 * (lcost + rcost) end @cost end |
#describe(out = STDOUT, offset = 0, incr = 2, sep = "\n") ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/omf_rete/planner/join_plan.rb', line 78 def describe(out = STDOUT, offset = 0, incr = 2, sep = "\n") out.write(" " * offset) result = @result_set.to_a.sort join = @join_set.to_a.sort out.write("join: [#{join.join(', ')}] => [#{result.join(', ')}] cost: #{cost}#{sep}") @left.describe(out, offset + incr, incr, sep) @right.describe(out, offset + incr, incr, sep) end |
#hash ⇒ Object
Create a hash for this plan which allows us to to identify identical plans.
Please note, that there is most likely a mroe efficient way to calculate a hash with the above properties
53 54 55 56 57 58 59 60 61 |
# File 'lib/omf_rete/planner/join_plan.rb', line 53 def hash() unless @hash s = StringIO.new describe(s, 0, 0, '|') str = s.string @hash = str.hash end @hash end |
#materialize(indexPattern, resultSet, opts, &block) ⇒ Object
Materialize the plan. Create all the relevant operations and tuple sets to realize a configuration for the respective query. Returns the result set.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/omf_rete/planner/join_plan.rb', line 33 def materialize(indexPattern, resultSet, opts, &block) unless resultSet description = @result_set.to_a.sort resultSet = IndexedTupleSet.new(description, indexPattern, nil, opts) end indexPattern = @join_set.to_a leftSet = @left.materialize(indexPattern, nil, opts) rightSet = @right.materialize(indexPattern, nil, opts) op = JoinOP.new(leftSet, rightSet, resultSet) resultSet.source = op resultSet end |
#to_s ⇒ Object
87 88 89 90 91 |
# File 'lib/omf_rete/planner/join_plan.rb', line 87 def to_s result = @result_set.to_a.sort join = @join_set.to_a.sort "JoinPlan [#{join.join(', ')}] out: [#{result.join(', ')}]" end |