Class: Alf::Update::Inserter

Inherits:
Algebra::Compiler show all
Includes:
Lang::Functional
Defined in:
lib/alf/update/inserter.rb

Instance Method Summary collapse

Methods included from Lang::Functional

#Heading, #Relation, #Tuple, def_aggregator_method, def_operator_method

Methods inherited from Algebra::Compiler

#apply, #on_missing

Methods included from Algebra::Visitor

#copy_and_apply

Instance Method Details

#call(expr, tuples) ⇒ Object

overridings


8
9
10
# File 'lib/alf/update/inserter.rb', line 8

def call(expr, tuples)
  super(expr, Algebra::Operand.coerce(tuples))
end

#not_supported(expr, *args) ⇒ Object Also known as: on_coerce, on_generator, on_quota, on_summarize, on_ungroup, on_unwrap

Raises:


12
13
14
# File 'lib/alf/update/inserter.rb', line 12

def not_supported(expr, *args)
  raise NotSupportedError, "Unable to insert through `#{expr}`"
end

#on_autonum(expr, inserted) ⇒ Object


28
29
30
# File 'lib/alf/update/inserter.rb', line 28

def on_autonum(expr, inserted)
  apply(expr.operand, allbut(inserted, [expr.as]))
end

#on_clip(expr, inserted) ⇒ Object


32
33
34
35
# File 'lib/alf/update/inserter.rb', line 32

def on_clip(expr, inserted)
  defaults = expr.attributes.project_tuple(expr.defaults, expr.allbut)
  apply(expr.operand, extend(inserted, defaults))
end

#on_compact(expr, inserted) ⇒ Object


37
38
39
# File 'lib/alf/update/inserter.rb', line 37

def on_compact(expr, inserted)
  apply(expr.operand, inserted)
end

#on_defaults(expr, inserted) ⇒ Object


41
42
43
# File 'lib/alf/update/inserter.rb', line 41

def on_defaults(expr, inserted)
  apply(expr.operand, defaults(inserted, expr.defaults))
end

#on_extend(expr, inserted) ⇒ Object

relational


51
52
53
# File 'lib/alf/update/inserter.rb', line 51

def on_extend(expr, inserted)
  apply(expr.operand, allbut(inserted, expr.ext.to_attr_list))
end

#on_group(expr, inserted) ⇒ Object


55
56
57
# File 'lib/alf/update/inserter.rb', line 55

def on_group(expr, inserted)
  apply(expr.operand, ungroup(inserted, expr.as))
end

#on_intersect(expr, inserted) ⇒ Object


59
60
61
62
# File 'lib/alf/update/inserter.rb', line 59

def on_intersect(expr, inserted)
  apply(expr.left, inserted)
  apply(expr.right, inserted)
end

#on_join(expr, inserted) ⇒ Object


64
65
66
67
# File 'lib/alf/update/inserter.rb', line 64

def on_join(expr, inserted)
  apply(expr.left,  project(inserted, expr.left.heading.to_attr_list))
  apply(expr.right, project(inserted, expr.right.heading.to_attr_list))
end

#on_leaf_operand(expr, inserted) ⇒ Object

leaf Operand, recursion end :-)


18
19
20
21
# File 'lib/alf/update/inserter.rb', line 18

def on_leaf_operand(expr, inserted)
  inserted = inserted.to_cog if inserted.respond_to?(:to_cog)
  expr.to_relvar.insert(inserted)
end

#on_matching(expr, inserted) ⇒ Object


69
70
71
72
# File 'lib/alf/update/inserter.rb', line 69

def on_matching(expr, inserted)
  # TODO: check that not_matching(inserted, expr.right) is empty
  apply(expr.left, inserted)
end

#on_minus(expr, inserted) ⇒ Object


74
75
76
77
# File 'lib/alf/update/inserter.rb', line 74

def on_minus(expr, inserted)
  # TODO: check that intersect(inserted, expr.right) is empty
  apply(expr.left, inserted)
end

#on_not_matching(expr, inserted) ⇒ Object


79
80
81
82
# File 'lib/alf/update/inserter.rb', line 79

def on_not_matching(expr, inserted)
  # TODO: check that matching(inserted, expr.right) is empty
  apply(expr.left, inserted)
end

#on_project(expr, inserted) ⇒ Object


84
85
86
87
# File 'lib/alf/update/inserter.rb', line 84

def on_project(expr, inserted)
  defaults = expr.attributes.project_tuple(expr.defaults, expr.allbut)
  apply(expr.operand, extend(inserted, defaults))
end

#on_rank(expr, inserted) ⇒ Object


91
92
93
# File 'lib/alf/update/inserter.rb', line 91

def on_rank(expr, inserted)
  apply(expr.operand, allbut(inserted, [expr.as]))
end

#on_rename(expr, inserted) ⇒ Object


95
96
97
# File 'lib/alf/update/inserter.rb', line 95

def on_rename(expr, inserted)
  apply(expr.operand, rename(inserted, expr.renaming.invert))
end

#on_restrict(expr, inserted) ⇒ Object


99
100
101
102
# File 'lib/alf/update/inserter.rb', line 99

def on_restrict(expr, inserted)
  # TODO: check that restrict(inserted, expr.predicate)==inserted
  apply(expr.operand, inserted)
end

#on_sort(expr, inserted) ⇒ Object


45
46
47
# File 'lib/alf/update/inserter.rb', line 45

def on_sort(expr, inserted)
  apply(expr.operand, sort(inserted, expr.ordering))
end

#on_union(expr, inserted) ⇒ Object


107
108
109
110
# File 'lib/alf/update/inserter.rb', line 107

def on_union(expr, inserted)
  apply(expr.left,  inserted)
  apply(expr.right, inserted)
end

#on_wrap(expr, inserted) ⇒ Object


114
115
116
# File 'lib/alf/update/inserter.rb', line 114

def on_wrap(expr, inserted)
  apply(expr.operand, unwrap(inserted, expr.as))
end