Class: ConceptQL::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/conceptql/scope.rb

Overview

Scope coordinates the creation of any TempTables that might be used when a Recall operator is present in the statement.

Any time an operator is given a label, it becomes a candidate for a Recall operator to reuse the output of that operator somewhere else in the statement.

Scope keeps track of all labeled operators and provides an API for Recall operators to fetch the results/types from labeled operators.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScope



16
17
18
19
# File 'lib/conceptql/scope.rb', line 16

def initialize
  @known_operators = {}
  @flagged = {}
end

Instance Attribute Details

#known_operatorsObject (readonly)

Returns the value of attribute known_operators.



15
16
17
# File 'lib/conceptql/scope.rb', line 15

def known_operators
  @known_operators
end

#person_idsObject

Returns the value of attribute person_ids.



14
15
16
# File 'lib/conceptql/scope.rb', line 14

def person_ids
  @person_ids
end

Instance Method Details

#add_operator(operator) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/conceptql/scope.rb', line 21

def add_operator(operator)
  # Recall operators respond to source, so when we add such an
  # operator, we want to flag it so that we can come back to it later
  # and create the appropriate temp tables
  if operator.respond_to?(:source)
    flagged[operator.source] = true
  end
  return unless operator.label
  known_operators[operator.label] = operator
end

#from(db, label) ⇒ Object



32
33
34
# File 'lib/conceptql/scope.rb', line 32

def from(db, label)
  temp_table(db, label).from(db)
end

#prep(db) ⇒ Object



46
47
48
49
50
# File 'lib/conceptql/scope.rb', line 46

def prep(db)
  temp_tables(db).values.map do |temp|
    temp.build(db)
  end
end

#sql(db) ⇒ Object



40
41
42
43
44
# File 'lib/conceptql/scope.rb', line 40

def sql(db)
  temp_tables(db).values.map do |temp|
    temp.sql(db)
  end
end

#types(label) ⇒ Object



36
37
38
# File 'lib/conceptql/scope.rb', line 36

def types(label)
  fetch_operator(label).types
end