Class: Alf::Engine::Compiler

Inherits:
Algebra::Compiler show all
Defined in:
lib/alf-engine/alf/engine/compiler.rb

Instance Method Summary collapse

Methods inherited from Algebra::Compiler

#apply, #call, #on_missing

Methods included from Algebra::Visitor

#copy_and_apply

Instance Method Details

#not_supported(expr) ⇒ Object



5
6
7
8
9
# File 'lib/alf-engine/alf/engine/compiler.rb', line 5

def not_supported(expr)
  # sub-compilers (i.e. Alf::Sequel's one) cheat a bit by partly rewriting
  # expressions so that their operands are actually Cogs...
  expr.is_a?(Cog) ? expr : super
end

#on_autonum(expr) ⇒ Object

non relational



19
20
21
# File 'lib/alf-engine/alf/engine/compiler.rb', line 19

def on_autonum(expr)
  Autonum.new(apply(expr.operand), expr.as)
end

#on_clip(expr) ⇒ Object



23
24
25
# File 'lib/alf-engine/alf/engine/compiler.rb', line 23

def on_clip(expr)
  Clip.new(apply(expr.operand), expr.attributes, expr.allbut)
end

#on_coerce(expr) ⇒ Object



27
28
29
# File 'lib/alf-engine/alf/engine/compiler.rb', line 27

def on_coerce(expr)
  Coerce.new(apply(expr.operand), expr.coercions)
end

#on_compact(expr) ⇒ Object



31
32
33
# File 'lib/alf-engine/alf/engine/compiler.rb', line 31

def on_compact(expr)
  Compact.new(apply(expr.operand))
end

#on_defaults(expr) ⇒ Object



35
36
37
38
39
# File 'lib/alf-engine/alf/engine/compiler.rb', line 35

def on_defaults(expr)
  op = Defaults.new(apply(expr.operand), expr.defaults)
  op = Clip.new(op, expr.defaults.to_attr_list, false) if expr.strict
  op
end

#on_extend(expr) ⇒ Object

relational



56
57
58
# File 'lib/alf-engine/alf/engine/compiler.rb', line 56

def on_extend(expr)
  SetAttr.new(apply(expr.operand), expr.ext)
end

#on_generator(expr) ⇒ Object



41
42
43
# File 'lib/alf-engine/alf/engine/compiler.rb', line 41

def on_generator(expr)
  Generator.new(expr.as, 1, 1, expr.size)
end

#on_group(expr) ⇒ Object



60
61
62
# File 'lib/alf-engine/alf/engine/compiler.rb', line 60

def on_group(expr)
  Group::Hash.new(apply(expr.operand), expr.attributes, expr.as, expr.allbut)
end

#on_infer_heading(expr) ⇒ Object



64
65
66
# File 'lib/alf-engine/alf/engine/compiler.rb', line 64

def on_infer_heading(expr)
  InferHeading.new(apply(expr.operand))
end

#on_intersect(expr) ⇒ Object



68
69
70
# File 'lib/alf-engine/alf/engine/compiler.rb', line 68

def on_intersect(expr)
  Join::Hash.new(apply(expr.left), apply(expr.right))
end

#on_join(expr) ⇒ Object



72
73
74
# File 'lib/alf-engine/alf/engine/compiler.rb', line 72

def on_join(expr)
  Join::Hash.new(apply(expr.left), apply(expr.right))
end

#on_leaf_operand(expr) ⇒ Object

leaf



13
14
15
# File 'lib/alf-engine/alf/engine/compiler.rb', line 13

def on_leaf_operand(expr)
  expr.to_cog
end

#on_matching(expr) ⇒ Object



76
77
78
# File 'lib/alf-engine/alf/engine/compiler.rb', line 76

def on_matching(expr)
  Semi::Hash.new(apply(expr.left), apply(expr.right), true)
end

#on_minus(expr) ⇒ Object



80
81
82
# File 'lib/alf-engine/alf/engine/compiler.rb', line 80

def on_minus(expr)
  Semi::Hash.new(apply(expr.left), apply(expr.right), false)
end

#on_not_matching(expr) ⇒ Object



84
85
86
# File 'lib/alf-engine/alf/engine/compiler.rb', line 84

def on_not_matching(expr)
  Semi::Hash.new(apply(expr.left), apply(expr.right), false)
end

#on_project(expr) ⇒ Object



88
89
90
91
92
# File 'lib/alf-engine/alf/engine/compiler.rb', line 88

def on_project(expr)
  op = Clip.new(apply(expr.operand), expr.attributes, expr.allbut)
  op = Compact.new(op)
  op
end

#on_quota(expr) ⇒ Object



94
95
96
97
98
# File 'lib/alf-engine/alf/engine/compiler.rb', line 94

def on_quota(expr)
  op = Sort.new(apply(expr.operand), expr.by.to_ordering + expr.order)
  op = Quota::Cesure.new(op, expr.by, expr.summarization)
  op
end

#on_rank(expr) ⇒ Object



100
101
102
103
104
# File 'lib/alf-engine/alf/engine/compiler.rb', line 100

def on_rank(expr)
  op = Sort.new(apply(expr.operand), expr.order)
  op = Rank::Cesure.new(op, expr.order, expr.as)
  op
end

#on_rename(expr) ⇒ Object



106
107
108
# File 'lib/alf-engine/alf/engine/compiler.rb', line 106

def on_rename(expr)
  Rename.new(apply(expr.operand), expr.renaming)
end

#on_restrict(expr) ⇒ Object



110
111
112
# File 'lib/alf-engine/alf/engine/compiler.rb', line 110

def on_restrict(expr)
  Filter.new(apply(expr.operand), expr.predicate)
end

#on_sort(expr) ⇒ Object



45
46
47
# File 'lib/alf-engine/alf/engine/compiler.rb', line 45

def on_sort(expr)
  Sort.new(apply(expr.operand), expr.ordering)
end

#on_summarize(expr) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/alf-engine/alf/engine/compiler.rb', line 114

def on_summarize(expr)
  if expr.allbut
    Summarize::Hash.new(apply(expr.operand), expr.by, expr.summarization, expr.allbut)
  else
    op = Sort.new(apply(expr.operand), expr.by.to_ordering)
    op = Summarize::Cesure.new(op, expr.by, expr.summarization, expr.allbut)
    op
  end
end

#on_type_safe(expr) ⇒ Object



49
50
51
52
# File 'lib/alf-engine/alf/engine/compiler.rb', line 49

def on_type_safe(expr)
  checker = TypeCheck.new(expr.heading, expr.strict)
  TypeSafe.new(apply(expr.operand), checker)
end

#on_ungroup(expr) ⇒ Object



124
125
126
# File 'lib/alf-engine/alf/engine/compiler.rb', line 124

def on_ungroup(expr)
  Ungroup.new(apply(expr.operand), expr.attribute)
end

#on_union(expr) ⇒ Object



128
129
130
131
132
# File 'lib/alf-engine/alf/engine/compiler.rb', line 128

def on_union(expr)
  op = Concat.new([apply(expr.left), apply(expr.right)])
  op = Compact.new(op)
  op
end

#on_unwrap(expr) ⇒ Object



134
135
136
# File 'lib/alf-engine/alf/engine/compiler.rb', line 134

def on_unwrap(expr)
  Unwrap.new(apply(expr.operand), expr.attribute)
end

#on_wrap(expr) ⇒ Object



138
139
140
# File 'lib/alf-engine/alf/engine/compiler.rb', line 138

def on_wrap(expr)
  Wrap.new(apply(expr.operand), expr.attributes, expr.as, expr.allbut)
end