-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcolumnarize.go
51 lines (45 loc) · 968 Bytes
/
columnarize.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package exectoy
type staticTupleSource struct {
tuples []tuple
}
func (s *staticTupleSource) NextTuple() tuple {
if len(s.tuples) == 0 {
return nil
}
t := s.tuples[0]
s.tuples = s.tuples[1:]
return t
}
// columnarizeOp takes tuples and turns them into a dataFlow.
type columnarizeOp struct {
input TupleSource
numCols int
internalBatch batch
internalSel intColumn
}
func (c *columnarizeOp) Init() {
b := make([]int, c.numCols*batchRowLen)
c.internalBatch = make(batch, c.numCols)
c.internalSel = make(intColumn, batchRowLen)
for i := range c.internalBatch {
c.internalBatch[i] = intColumn(b[i*batchRowLen : (i+1)*batchRowLen])
}
}
func (c columnarizeOp) Next() dataFlow {
d := dataFlow{
b: c.internalBatch,
sel: c.internalSel,
useSel: false,
}
for d.n < batchRowLen {
t := c.input.NextTuple()
if t == nil {
break
}
for i := range t {
c.internalBatch[i].(intColumn)[d.n] = t[i]
}
d.n++
}
return d
}