Class: Alf::Compiler::Default

Inherits:
Alf::Compiler show all
Defined in:
lib/alf/compiler/default.rb

Instance Method Summary collapse

Methods inherited from Alf::Compiler

#call, #compile, #join, #on_leaf_operand, #on_missing, #on_relation, #on_relvar, #on_shortcut, #on_unsupported

Instance Method Details

#on_autonum(plan, expr, compiled) ⇒ Object

non relational


15
16
17
# File 'lib/alf/compiler/default.rb', line 15

def on_autonum(plan, expr, compiled)
  factor(Engine::Autonum, expr, compiled, expr.as)
end

#on_clip(plan, expr, compiled) ⇒ Object


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

def on_clip(plan, expr, compiled)
  factor(Engine::Clip, expr, compiled, expr.attributes, expr.allbut)
end

#on_coerce(plan, expr, compiled) ⇒ Object


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

def on_coerce(plan, expr, compiled)
  factor(Engine::Coerce, expr, compiled, expr.coercions)
end

#on_compact(plan, expr, compiled) ⇒ Object


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

def on_compact(plan, expr, compiled)
  factor(Engine::Compact, expr, compiled)
end

#on_defaults(plan, expr, compiled) ⇒ Object


31
32
33
34
35
36
# File 'lib/alf/compiler/default.rb', line 31

def on_defaults(plan, expr, compiled)
  compiled = plan.recompile(compiled){|p|
    p.clip(expr.operand, expr.defaults.to_attr_list)
  } if expr.strict
  factor(Engine::Defaults, expr, compiled, expr.defaults)
end

#on_extend(plan, expr, compiled) ⇒ Object

relational


49
50
51
# File 'lib/alf/compiler/default.rb', line 49

def on_extend(plan, expr, compiled)
  factor(Engine::SetAttr, expr, compiled, expr.ext)
end

#on_frame(plan, expr, compiled) ⇒ Object


53
54
55
56
57
58
59
# File 'lib/alf/compiler/default.rb', line 53

def on_frame(plan, expr, compiled)
  compiled = plan.recompile(compiled){|p|
    ordering = expr.total_ordering rescue expr.ordering
    p.sort(expr.operand, ordering)
  }
  factor(Engine::Take, expr, compiled, expr.offset, expr.limit)
end

#on_generator(plan, expr) ⇒ Object


38
39
40
# File 'lib/alf/compiler/default.rb', line 38

def on_generator(plan, expr)
  factor(Engine::Generator, expr, expr.as, 1, 1, expr.size)
end

#on_group(plan, expr, compiled) ⇒ Object


61
62
63
# File 'lib/alf/compiler/default.rb', line 61

def on_group(plan, expr, compiled)
  factor(Engine::Group::Hash, expr, compiled, expr.attributes, expr.as, expr.allbut)
end

#on_hierarchize(plan, expr, compiled) ⇒ Object


65
66
67
# File 'lib/alf/compiler/default.rb', line 65

def on_hierarchize(plan, expr, compiled)
  factor(Engine::Hierarchize, expr, compiled, expr.id, expr.parent, expr.as)
end

#on_image(plan, expr, left, right) ⇒ Object


69
70
71
# File 'lib/alf/compiler/default.rb', line 69

def on_image(plan, expr, left, right)
  factor(Engine::Image::Hash, expr, left, right, expr.as)
end

#on_intersect(plan, expr, left, right) ⇒ Object


73
74
75
# File 'lib/alf/compiler/default.rb', line 73

def on_intersect(plan, expr, left, right)
  factor(Engine::Join::Hash, expr, left, right)
end

#on_join(plan, expr, left, right) ⇒ Object


77
78
79
# File 'lib/alf/compiler/default.rb', line 77

def on_join(plan, expr, left, right)
  factor(Engine::Join::Hash, expr, left, right)
end

#on_matching(plan, expr, left, right) ⇒ Object


81
82
83
# File 'lib/alf/compiler/default.rb', line 81

def on_matching(plan, expr, left, right)
  factor(Engine::Semi::Hash, expr, left, right, true)
end

#on_minus(plan, expr, left, right) ⇒ Object


85
86
87
# File 'lib/alf/compiler/default.rb', line 85

def on_minus(plan, expr, left, right)
  factor(Engine::Semi::Hash, expr, left, right, false)
end

#on_not_matching(plan, expr, left, right) ⇒ Object


89
90
91
# File 'lib/alf/compiler/default.rb', line 89

def on_not_matching(plan, expr, left, right)
  factor(Engine::Semi::Hash, expr, left, right, false)
end

#on_page(plan, expr, compiled) ⇒ Object


93
94
95
96
97
98
99
100
101
# File 'lib/alf/compiler/default.rb', line 93

def on_page(plan, expr, compiled)
  index, size = expr.page_index, expr.page_size
  compiled = plan.recompile(compiled){|p|
    ordering = expr.total_ordering rescue expr.ordering
    ordering = ordering.reverse if index < 0
    p.sort(expr.operand, ordering)
  }
  factor(Engine::Take, expr, compiled, (index.abs - 1) * size, size)
end

#on_project(plan, expr, compiled) ⇒ Object


103
104
105
106
107
108
109
110
# File 'lib/alf/compiler/default.rb', line 103

def on_project(plan, expr, compiled)
  preserving = expr.key_preserving? rescue false
  compiled = plan.recompile(compiled){|p|
    p.clip(expr.operand, expr.attributes, allbut: expr.allbut)
  }
  compiled = factor(Engine::Compact, expr, compiled) unless preserving
  compiled
end

#on_quota(plan, expr, compiled) ⇒ Object


112
113
114
115
116
117
# File 'lib/alf/compiler/default.rb', line 112

def on_quota(plan, expr, compiled)
  compiled = plan.recompile(compiled){|p|
    p.sort(expr.operand, expr.by.to_ordering + expr.order)
  }
  factor(Engine::Quota::Cesure, expr, compiled, expr.by, expr.summarization)
end

#on_rank(plan, expr, compiled) ⇒ Object


119
120
121
122
123
124
# File 'lib/alf/compiler/default.rb', line 119

def on_rank(plan, expr, compiled)
  compiled = plan.recompile(compiled){|p|
    p.sort(expr.operand, expr.order)
  }
  factor(Engine::Rank::Cesure, expr, compiled, expr.order, expr.as)
end

#on_rename(plan, expr, compiled) ⇒ Object


126
127
128
# File 'lib/alf/compiler/default.rb', line 126

def on_rename(plan, expr, compiled)
  factor(Engine::Rename, expr, compiled, expr.renaming)
end

#on_restrict(plan, expr, compiled) ⇒ Object


130
131
132
# File 'lib/alf/compiler/default.rb', line 130

def on_restrict(plan, expr, compiled)
  factor(Engine::Filter, expr, compiled, expr.predicate)
end

#on_sort(plan, expr, compiled) ⇒ Object


42
43
44
45
# File 'lib/alf/compiler/default.rb', line 42

def on_sort(plan, expr, compiled)
  return compiled if compiled.orderedby?(expr.ordering)
  factor(Engine::Sort, expr, compiled, expr.ordering)
end

#on_summarize(plan, expr, compiled) ⇒ Object


134
135
136
137
138
139
140
141
142
143
# File 'lib/alf/compiler/default.rb', line 134

def on_summarize(plan, expr, compiled)
  if expr.allbut
    factor(Engine::Summarize::Hash, expr, compiled, expr.by, expr.summarization, expr.allbut)
  else
    compiled = plan.recompile(compiled){|p|
      p.sort(expr.operand, expr.by.to_ordering)
    }
    factor(Engine::Summarize::Cesure, expr, compiled, expr.by, expr.summarization, expr.allbut)
  end
end

#on_ungroup(plan, expr, compiled) ⇒ Object


145
146
147
# File 'lib/alf/compiler/default.rb', line 145

def on_ungroup(plan, expr, compiled)
  factor(Engine::Ungroup, expr, compiled, expr.attribute)
end

#on_union(plan, expr, left, right) ⇒ Object


149
150
151
152
153
154
# File 'lib/alf/compiler/default.rb', line 149

def on_union(plan, expr, left, right)
  compiled = factor(Engine::Concat, expr, [left, right])
  compiled = factor(Engine::Compact, expr, compiled)
  #
  compiled
end

#on_unwrap(plan, expr, compiled) ⇒ Object


156
157
158
# File 'lib/alf/compiler/default.rb', line 156

def on_unwrap(plan, expr, compiled)
  factor(Engine::Unwrap, expr, compiled, expr.attribute)
end

#on_wrap(plan, expr, compiled) ⇒ Object


160
161
162
# File 'lib/alf/compiler/default.rb', line 160

def on_wrap(plan, expr, compiled)
  factor(Engine::Wrap, expr, compiled, expr.attributes, expr.as, expr.allbut)
end

#reuse(plan, cog) ⇒ Object


9
10
11
# File 'lib/alf/compiler/default.rb', line 9

def reuse(plan, cog)
  cog
end

#supports_reuse?Boolean

Returns:

  • (Boolean)

5
6
7
# File 'lib/alf/compiler/default.rb', line 5

def supports_reuse?
  true
end