Class: Bud::PushElement
Overview
p.insert(1) p.insert(nil)
Instance Attribute Summary collapse
#accumulate_tick_deltas, #bud_instance, #cols, #is_source, #key_cols, #new_delta, #pending, #scanner_cnt, #struct, #tabname
Instance Method Summary
collapse
-
#*(elem2, &blk) ⇒ Object
-
#<<(i) ⇒ Object
-
#add_rescan_invalidate(rescan, invalidate) ⇒ Object
-
#all?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
-
#any?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
-
#argagg(aggname, gbkey_cols, collection, &blk) ⇒ Object
-
#argmax(gbcols, col, &blk) ⇒ Object
-
#argmin(gbcols, col, &blk) ⇒ Object
-
#check_wiring ⇒ Object
-
#each_with_index(&blk) ⇒ Object
-
#flush ⇒ Object
-
#group(keycols, *aggpairs, &blk) ⇒ Object
-
#include?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
-
#initialize(name_in, bud_instance, collection_name = nil, given_schema = nil, defer_schema = false, &blk) ⇒ PushElement
constructor
A new instance of PushElement.
-
#insert(item, source = nil) ⇒ Object
-
#inspected ⇒ Object
-
#invalidate_cache ⇒ Object
-
#invalidate_tables(rescan, invalidate) ⇒ Object
-
#join(elem2, &blk) ⇒ Object
-
#member?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
-
#merge(source) ⇒ Object
(also: #<=)
-
#none?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
-
#notin(elem2, *preds, &blk) ⇒ Object
-
#on_include?(item, &blk) ⇒ Boolean
-
#one?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
-
#print_wiring(depth = 0, accum = "") ⇒ Object
-
#pro(the_name = elem_name, the_schema = schema, &blk) ⇒ Object
(also: #each, #on_exists?)
-
#push_out(item, do_block = true) ⇒ Object
-
#push_predicate(pred_symbol, name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Object
-
#reduce(initial, &blk) ⇒ Object
-
#rescan_at_tick ⇒ Object
-
#set_block(&blk) ⇒ Object
-
#sort(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Object
-
#stratum_end ⇒ Object
-
#tick ⇒ Object
-
#tick_deltas ⇒ Object
-
#wire_to(element, kind = :output) ⇒ Object
-
#wirings ⇒ Object
#[], #bootstrap, #canonicalize_col, #close, #do_insert, #each_delta, #each_raw, #each_tick_delta, #empty?, #exists?, #flat_map, #flush_deltas, #has_key?, #init_schema, #inspect, #invalidate_at_tick, #keys, #length, #non_temporal_predecessors, #null_tuple, #pending_merge, #positive_predecessors, #prep_aggpairs, #qualified_tabname, #register_coll_expr, #rename, #schema, #tick_metrics, #to_push_elem, #uniquify_tabname, #val_cols, #values
Constructor Details
#initialize(name_in, bud_instance, collection_name = nil, given_schema = nil, defer_schema = false, &blk) ⇒ PushElement
Returns a new instance of PushElement.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/bud/executor/elements.rb', line 17
def initialize(name_in, bud_instance, collection_name=nil, given_schema=nil, defer_schema=false, &blk)
super(name_in, bud_instance, given_schema, defer_schema)
@blk = blk
@outputs = Set.new
@pendings = Set.new
@deletes = Set.new
@delete_keys = Set.new
@wired_by = []
@elem_name = name_in
@found_delta = false
@collection_name = collection_name
@invalidated = true
@rescan = true
end
|
Instance Attribute Details
#elem_name ⇒ Object
Returns the value of attribute elem_name.
14
15
16
|
# File 'lib/bud/executor/elements.rb', line 14
def elem_name
@elem_name
end
|
#found_delta ⇒ Object
Returns the value of attribute found_delta.
15
16
17
|
# File 'lib/bud/executor/elements.rb', line 15
def found_delta
@found_delta
end
|
#invalidated ⇒ Object
Returns the value of attribute invalidated.
13
14
15
|
# File 'lib/bud/executor/elements.rb', line 13
def invalidated
@invalidated
end
|
#outputs ⇒ Object
Returns the value of attribute outputs.
15
16
17
|
# File 'lib/bud/executor/elements.rb', line 15
def outputs
@outputs
end
|
#pendings ⇒ Object
Returns the value of attribute pendings.
15
16
17
|
# File 'lib/bud/executor/elements.rb', line 15
def pendings
@pendings
end
|
#rescan ⇒ Object
Returns the value of attribute rescan.
13
14
15
|
# File 'lib/bud/executor/elements.rb', line 13
def rescan
@rescan
end
|
#wired_by ⇒ Object
Returns the value of attribute wired_by.
15
16
17
|
# File 'lib/bud/executor/elements.rb', line 15
def wired_by
@wired_by
end
|
Instance Method Details
#*(elem2, &blk) ⇒ Object
234
235
236
|
# File 'lib/bud/executor/elements.rb', line 234
def *(elem2, &blk)
join(elem2, &blk)
end
|
#<<(i) ⇒ Object
184
185
186
|
# File 'lib/bud/executor/elements.rb', line 184
def <<(i)
insert(i, nil)
end
|
#add_rescan_invalidate(rescan, invalidate) ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/bud/executor/elements.rb', line 151
def add_rescan_invalidate(rescan, invalidate)
srcs = non_temporal_predecessors
if srcs.any?{|p| rescan.member? p}
rescan << self
end
invalidate_tables(rescan, invalidate)
if rescan.member? self
rescan.merge(srcs)
end
end
|
#all?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
329
330
331
|
# File 'lib/bud/executor/elements.rb', line 329
def all?(name=nil, bud_instance=nil, the_schema=nil, &blk)
push_predicate(:all?, name, bud_instance, the_schema, &blk)
end
|
#any?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
332
333
334
|
# File 'lib/bud/executor/elements.rb', line 332
def any?(name=nil, bud_instance=nil, the_schema=nil, &blk)
push_predicate(:any?, name, bud_instance, the_schema, &blk)
end
|
#argagg(aggname, gbkey_cols, collection, &blk) ⇒ Object
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
# File 'lib/bud/executor/elements.rb', line 294
def argagg(aggname, gbkey_cols, collection, &blk)
gbkey_cols ||= []
gbkey_cols = gbkey_cols.map{|c| canonicalize_col(c)}
collection = canonicalize_col(collection)
toplevel = @bud_instance.toplevel
agg = toplevel.send(aggname, collection)[0]
unless agg.class <= Bud::ArgExemplary
raise Bud::Error, "#{aggname} not declared exemplary"
end
aggpairs = [[agg, collection]]
aa = Bud::PushArgAgg.new("argagg#{Time.new.tv_usec}".to_sym, toplevel.this_rule_context,
@collection_name, gbkey_cols, aggpairs, schema, &blk)
self.wire_to(aa)
toplevel.push_elems[[self.object_id, :argagg, gbkey_cols, aggpairs, blk]] = aa
return aa
end
|
#argmax(gbcols, col, &blk) ⇒ Object
311
312
313
|
# File 'lib/bud/executor/elements.rb', line 311
def argmax(gbcols, col, &blk)
argagg(:max, gbcols, col, &blk)
end
|
#argmin(gbcols, col, &blk) ⇒ Object
314
315
316
|
# File 'lib/bud/executor/elements.rb', line 314
def argmin(gbcols, col, &blk)
argagg(:min, gbcols, col, &blk)
end
|
#check_wiring ⇒ Object
69
70
71
72
73
|
# File 'lib/bud/executor/elements.rb', line 69
def check_wiring
if @blk.nil? and @outputs.empty? and @pendings.empty? and @deletes.empty? and @delete_keys.empty?
raise Bud::Error, "no output specified for PushElement #{@qualified_tabname}"
end
end
|
#each_with_index(&blk) ⇒ Object
214
215
216
217
218
219
220
221
222
|
# File 'lib/bud/executor/elements.rb', line 214
def each_with_index(&blk)
toplevel = @bud_instance.toplevel
elem = Bud::PushEachWithIndex.new("each_with_index#{object_id}".to_sym,
toplevel.this_rule_context,
@collection_name)
elem.set_block(&blk)
self.wire_to(elem)
toplevel.push_elems[[self.object_id, :each_with_index, blk]] = elem
end
|
#flush ⇒ Object
189
190
|
# File 'lib/bud/executor/elements.rb', line 189
def flush
end
|
#group(keycols, *aggpairs, &blk) ⇒ Object
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# File 'lib/bud/executor/elements.rb', line 269
def group(keycols, *aggpairs, &blk)
keycols ||= []
keycols = keycols.map{|c| canonicalize_col(c)}
keynames = keycols.map{|k| k[2]}
aggcolsdups = aggpairs.map{|ap| ap[0].class.name.split("::").last}
aggcols = []
aggcolsdups.each_with_index do |n, i|
aggcols << "#{n.downcase}_#{i}".to_sym
end
if aggcols.empty?
the_schema = keynames
else
the_schema = { keynames => aggcols }
end
aggpairs = prep_aggpairs(aggpairs)
toplevel = @bud_instance.toplevel
g = Bud::PushGroup.new("grp#{Time.new.tv_usec}".to_sym, toplevel.this_rule_context,
@collection_name, keycols, aggpairs, the_schema, &blk)
self.wire_to(g)
toplevel.push_elems[[self.object_id, :group, keycols, aggpairs, blk]] = g
return g
end
|
#include?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
335
336
337
|
# File 'lib/bud/executor/elements.rb', line 335
def include?(name=nil, bud_instance=nil, the_schema=nil, &blk)
push_predicate(:include?, name, bud_instance, the_schema, &blk)
end
|
#insert(item, source = nil) ⇒ Object
104
105
106
|
# File 'lib/bud/executor/elements.rb', line 104
def insert(item, source=nil)
push_out(item)
end
|
#inspected ⇒ Object
366
367
368
369
370
371
372
373
374
|
# File 'lib/bud/executor/elements.rb', line 366
def inspected
toplevel = @bud_instance.toplevel
if toplevel.push_elems[[self.object_id, :inspected]].nil?
ins = pro{|i| [i.inspect]}
self.wire_to(ins)
toplevel.push_elems[[self.object_id, :inspected]] = ins
end
toplevel.push_elems[[self.object_id, :inspected]]
end
|
#invalidate_cache ⇒ Object
191
192
|
# File 'lib/bud/executor/elements.rb', line 191
def invalidate_cache
end
|
#invalidate_tables(rescan, invalidate) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/bud/executor/elements.rb', line 169
def invalidate_tables(rescan, invalidate)
[@outputs, @pendings].each do |v|
v.each do |o|
unless o.class <= PushElement
o.add_rescan_invalidate(rescan, invalidate)
rescan << self if invalidate.member? o
end
end
end
end
|
#join(elem2, &blk) ⇒ Object
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/bud/executor/elements.rb', line 224
def join(elem2, &blk)
elem2 = elem2.to_push_elem unless elem2.kind_of? PushElement
toplevel = @bud_instance.toplevel
join = Bud::PushSHJoin.new([self, elem2], toplevel.this_rule_context, [])
self.wire_to(join)
elem2.wire_to(join)
toplevel.push_elems[[self.object_id, :join, [self, elem2], toplevel, blk]] = join
toplevel.push_joins[toplevel.this_stratum] << join
return join
end
|
#member?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
338
339
340
|
# File 'lib/bud/executor/elements.rb', line 338
def member?(name=nil, bud_instance=nil, the_schema=nil, &blk)
push_predicate(:member?, name, bud_instance, the_schema, &blk)
end
|
#merge(source) ⇒ Object
Also known as:
<=
248
249
250
251
252
253
254
|
# File 'lib/bud/executor/elements.rb', line 248
def merge(source)
if source.class <= PushElement and @bud_instance.wiring?
source.wire_to(self)
else
source.each {|i| self << i}
end
end
|
#none?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
341
342
343
|
# File 'lib/bud/executor/elements.rb', line 341
def none?(name=nil, bud_instance=nil, the_schema=nil, &blk)
push_predicate(:none?, name, bud_instance, the_schema, &blk)
end
|
#notin(elem2, *preds, &blk) ⇒ Object
238
239
240
241
242
243
244
245
246
|
# File 'lib/bud/executor/elements.rb', line 238
def notin(elem2, *preds, &blk)
elem2 = elem2.to_push_elem unless elem2.kind_of? PushElement
toplevel = @bud_instance.toplevel
notin_elem = Bud::PushNotIn.new([self, elem2], toplevel.this_rule_context, preds, &blk)
self.wire_to(notin_elem)
elem2.wire_to(notin_elem)
toplevel.push_elems[[self.object_id, :notin, [self, elem2], toplevel, blk]] = notin_elem
return notin_elem
end
|
#on_include?(item, &blk) ⇒ Boolean
357
358
359
360
361
362
363
364
365
|
# File 'lib/bud/executor/elements.rb', line 357
def on_include?(item, &blk)
toplevel = @bud_instance.toplevel
if toplevel.push_elems[[self.object_id, :on_include?, item, blk]].nil?
inc = pro{|i| blk.call(item) if i == item and not blk.nil?}
wire_to(inc)
toplevel.push_elems[[self.object_id, :on_include?, item, blk]] = inc
end
toplevel.push_elems[[self.object_id, :on_include?, item, blk]]
end
|
#one?(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Boolean
344
345
346
|
# File 'lib/bud/executor/elements.rb', line 344
def one?(name=nil, bud_instance=nil, the_schema=nil, &blk)
push_predicate(:one?, name, bud_instance, the_schema, &blk)
end
|
#print_wiring(depth = 0, accum = "") ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/bud/executor/elements.rb', line 37
def print_wiring(depth=0, accum="")
depth.times {print " "}
puts "#{accum} #{(self.object_id*2).to_s(16)}: #{qualified_tabname} (#{self.class})"
[@outputs, @pendings, @deletes, @delete_keys].each do |kind|
case kind.object_id
when @outputs.object_id
next_accum = "=> "
when @pendings.object_id
next_accum = "+> "
when @deletes.object_id, @delete_keys.object_id
next_accum = "-> "
end
kind.each do |o|
if o.respond_to?(:print_wiring)
o.print_wiring(depth+1, next_accum)
else
(depth+1).times {print " "}
print "#{next_accum} "
if o.class <= Bud::BudCollection
puts "#{(o.object_id*2).to_s(16)}: #{o.qualified_tabname} (#{o.class})"
elsif o.class <= Bud::LatticeWrapper
puts "#{o.inspect}"
else
puts "#{(o.object_id*2).to_s(16)}: (#{o.class.name})"
end
end
end
end
end
|
#pro(the_name = elem_name, the_schema = schema, &blk) ⇒ Object
Also known as:
each, on_exists?
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/bud/executor/elements.rb', line 200
def pro(the_name=elem_name, the_schema=schema, &blk)
toplevel = @bud_instance.toplevel
elem = Bud::PushElement.new("project#{object_id}".to_sym,
toplevel.this_rule_context,
@collection_name, the_schema)
self.wire_to(elem)
elem.set_block(&blk)
toplevel.push_elems[[self.object_id, :pro, blk]] = elem
return elem
end
|
#push_out(item, do_block = true) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/bud/executor/elements.rb', line 116
def push_out(item, do_block=true)
if do_block && @blk
item = item.to_a if @blk.arity > 1
item = @blk.call item
return if item.nil?
end
@outputs.each do |ou|
if ou.class <= Bud::PushElement
ou.insert(item, self)
elsif ou.class <= Bud::BudCollection
ou.do_insert(item, ou.new_delta)
elsif ou.class <= Bud::LatticeWrapper
ou.insert(item, self)
else
raise Bud::Error, "unexpected output target: #{ou.class}"
end
end
@deletes.each{|o| o.pending_delete([item])}
@delete_keys.each{|o| o.pending_delete_keys([item])}
@pendings.each do |o|
if o.class <= Bud::LatticeWrapper
o <+ item
else
o.pending_merge([item])
end
end
end
|
#push_predicate(pred_symbol, name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Object
322
323
324
325
326
327
328
|
# File 'lib/bud/executor/elements.rb', line 322
def push_predicate(pred_symbol, name=nil, bud_instance=nil,
the_schema=nil, &blk)
elem = Bud::PushPredicate.new(pred_symbol, name, bud_instance,
the_schema, &blk)
wire_to(elem)
elem
end
|
#reduce(initial, &blk) ⇒ Object
348
349
350
351
352
353
354
|
# File 'lib/bud/executor/elements.rb', line 348
def reduce(initial, &blk)
retval = Bud::PushReduce.new("reduce#{Time.new.tv_usec}".to_sym,
@bud_instance, @collection_name,
schema, initial, &blk)
self.wire_to(retval)
retval
end
|
#rescan_at_tick ⇒ Object
100
101
102
|
# File 'lib/bud/executor/elements.rb', line 100
def rescan_at_tick
false
end
|
#set_block(&blk) ⇒ Object
75
76
77
|
# File 'lib/bud/executor/elements.rb', line 75
def set_block(&blk)
@blk = blk
end
|
#sort(name = nil, bud_instance = nil, the_schema = nil, &blk) ⇒ Object
317
318
319
320
321
|
# File 'lib/bud/executor/elements.rb', line 317
def sort(name=nil, bud_instance=nil, the_schema=nil, &blk)
elem = Bud::PushSort.new(name, bud_instance, the_schema, &blk)
wire_to(elem)
elem
end
|
#stratum_end ⇒ Object
193
194
|
# File 'lib/bud/executor/elements.rb', line 193
def stratum_end
end
|
#tick ⇒ Object
108
109
110
|
# File 'lib/bud/executor/elements.rb', line 108
def tick
invalidate_cache if @invalidated
end
|
#tick_deltas ⇒ Object
112
113
114
|
# File 'lib/bud/executor/elements.rb', line 112
def tick_deltas
@found_delta = false
end
|
#wire_to(element, kind = :output) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/bud/executor/elements.rb', line 79
def wire_to(element, kind=:output)
unless @bud_instance.wiring?
raise Bud::Error, "wire_to called outside wiring phase"
end
case kind
when :output
@outputs << element
when :pending
@pendings << element
when :delete
@deletes << element
when :delete_by_key
@delete_keys << element
else
raise Bud::Error, "unrecognized wiring kind: #{kind}"
end
element.wired_by << self if element.respond_to? :wired_by
end
|
#wirings ⇒ Object
32
33
34
|
# File 'lib/bud/executor/elements.rb', line 32
def wirings
@wirings ||= @outputs + @pendings + @deletes + @delete_keys
end
|