Class: OMF::Rete::Planner::SourcePlan

Inherits:
AbstractPlan show all
Defined in:
lib/omf_rete/planner/source_plan.rb

Overview

This class represents a planned join op.

Instance Attribute Summary collapse

Attributes inherited from AbstractPlan

#cover_set, #result_set

Instance Method Summary collapse

Methods inherited from AbstractPlan

#complete, #complete?, #result_description, #used, #used?

Constructor Details

#initialize(description, store = nil, check_for_empty_result_set = true) ⇒ SourcePlan

description - description of tuples contained in set store - store to attach source_set to



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/omf_rete/planner/source_plan.rb', line 24

def initialize(description, store = nil, check_for_empty_result_set = true)
  @description = description
  # the result set consists of all the binding declarations
  # which are symbols with trailing '?'
  resultSet = Set.new
  description.each do |name|
    if name.to_s.end_with?('?')
      resultSet << name.to_sym
    end
  end
  if (check_for_empty_result_set && resultSet.empty?)
    raise NoBindingException.new("No binding declaration in sub plan '#{description.join(', ')}'")
  end
  coverSet = Set.new([self])
  super coverSet, resultSet

  #raise Exception unless store.kind_of?(Moana::Filter::Store)
  @store = store
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



17
18
19
# File 'lib/omf_rete/planner/source_plan.rb', line 17

def description
  @description
end

#source_setObject (readonly)

tuple set created by this plan



18
19
20
# File 'lib/omf_rete/planner/source_plan.rb', line 18

def source_set
  @source_set
end

Instance Method Details

#costObject

Return the cost of this plan.

TODO: Some more meaningful heuristic will be nice



62
63
64
65
66
67
68
69
# File 'lib/omf_rete/planner/source_plan.rb', line 62

def cost()
  unless @cost
    @cost = @description.inject(0) do |val, el|
      val + ((el.nil? || el.to_s.end_with?('?')) ? 1 : 0.1)
    end
  end
  @cost
end

#describe(out = STDOUT, offset = 0, incr = 2, sep = "\n") ⇒ Object



72
73
74
# File 'lib/omf_rete/planner/source_plan.rb', line 72

def describe(out = STDOUT, offset = 0, incr = 2, sep = "\n")
  @source_set.describe(out, offset, incr, sep) if @source_set
end

#materialize(indexPattern, projectPattern, opts) ⇒ Object

Materialize the plan. Returns a tuple set.



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/omf_rete/planner/source_plan.rb', line 46

def materialize(indexPattern, projectPattern, opts)
  unless indexPattern
    # this plan only consists of a single source
    projectPattern ||= result_description
    @source_set = ProcessingTupleStream.new(projectPattern, projectPattern, @description)
  else
    @source_set = OMF::Rete::IndexedTupleSet.new(@description, indexPattern)
  end
  #@store.registerTSet(@source_set, @description) if @store
  @source_set.register_with_store(@store, @description)
end