/
chain.go
76 lines (59 loc) · 1.64 KB
/
chain.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package exec
import (
"github.com/squareup/pranadb/common"
)
// PullChain combines a sequence of executors in a linked list and exposes them as a single executor.
type PullChain struct {
nonEmptyChain []PullExecutor
colNames []string
}
var _ PullExecutor = (*PullChain)(nil)
func NewPullChain(head PullExecutor, tail ...PullExecutor) *PullChain {
chain := make([]PullExecutor, 1, len(tail)+1)
chain[0] = head
chain = append(chain, tail...)
result := &PullChain{nonEmptyChain: chain}
result.connectExecutors()
return result
}
func (c *PullChain) connectExecutors() {
for i := 0; i < len(c.nonEmptyChain)-1; i++ {
ConnectPullExecutors([]PullExecutor{c.nonEmptyChain[i+1]}, c.nonEmptyChain[i])
}
}
func (c *PullChain) first() PullExecutor {
return c.nonEmptyChain[0]
}
func (c *PullChain) last() PullExecutor {
return c.nonEmptyChain[len(c.nonEmptyChain)-1]
}
func (c *PullChain) GetRows(limit int) (*common.Rows, error) {
return c.first().GetRows(limit)
}
func (c *PullChain) AddChild(child PullExecutor) {
c.last().AddChild(child)
}
func (c *PullChain) GetChildren() []PullExecutor {
return c.last().GetChildren()
}
func (c *PullChain) GetParent() PullExecutor {
return c.first().GetParent()
}
func (c *PullChain) SetParent(parent PullExecutor) {
c.first().SetParent(parent)
}
func (c *PullChain) ColNames() []string {
return c.colNames
}
func (c *PullChain) ColTypes() []common.ColumnType {
return c.first().ColTypes()
}
func (c *PullChain) SetColNames(colNames []string) {
c.colNames = colNames
}
func (c *PullChain) RowsFactory() *common.RowsFactory {
return c.first().RowsFactory()
}
func (c *PullChain) Close() {
c.first().Close()
}