-
Notifications
You must be signed in to change notification settings - Fork 0
/
errorrel_test.go
107 lines (90 loc) · 2.85 KB
/
errorrel_test.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package rel
import (
"fmt"
"reflect"
)
// type for error testing only. It produces card default tuples from the
// TupleChan method, and then sets the err field and closes the results.
type errorRel struct {
zero interface{}
card int // this many blank zeroes will be sent on TupleChan before err is set.
err error
}
// TupleChan sends each tuple in the relation to a channel
// note: this consumes the values of the relation, and when it is finished it
// closes the input channel.
func (r1 *errorRel) TupleChan(t interface{}) chan<- struct{} {
cancel := make(chan struct{})
// reflect on the channel
chv := reflect.ValueOf(t)
err := EnsureChan(chv.Type(), r1.zero)
if err != nil {
r1.err = err
return cancel
}
if r1.err != nil {
chv.Close()
return cancel
}
go func(res reflect.Value) {
for i := 0; i < r1.card; i++ {
// note: these won't be distinct.
res.Send(reflect.ValueOf(r1.zero))
}
r1.err = fmt.Errorf("testing error")
res.Close()
}(chv)
return cancel
}
// Zero returns the zero value of the relation (a blank tuple)
func (r1 *errorRel) Zero() interface{} {
return r1.zero
}
// CKeys is the set of candidate keys in the relation
func (r1 *errorRel) CKeys() CandKeys {
return CandKeys{}
}
// GoString returns a text representation of the Relation
func (r1 *errorRel) GoString() string {
return "error{" + HeadingString(r1) + "}"
}
// String returns a text representation of the Relation
func (r1 *errorRel) String() string {
return "error{" + HeadingString(r1) + "}"
}
// Project creates a new relation with less than or equal degree
func (r1 *errorRel) Project(z2 interface{}) Relation {
return NewProject(r1, z2)
}
// Restrict creates a new relation with less than or equal cardinality
func (r1 *errorRel) Restrict(p Predicate) Relation {
return NewRestrict(r1, p)
}
// Rename creates a new relation with new column names
func (r1 *errorRel) Rename(z2 interface{}) Relation {
return NewRename(r1, z2)
}
// Union creates a new relation by unioning the bodies of both inputs
func (r1 *errorRel) Union(r2 Relation) Relation {
return NewUnion(r1, r2)
}
// Diff creates a new relation by set minusing the two inputs
func (r1 *errorRel) Diff(r2 Relation) Relation {
return NewDiff(r1, r2)
}
// Join creates a new relation by performing a natural join on the inputs
func (r1 *errorRel) Join(r2 Relation, zero interface{}) Relation {
return NewJoin(r1, r2, zero)
}
// GroupBy creates a new relation by grouping and applying a user defined func
func (r1 *errorRel) GroupBy(t2, gfcn interface{}) Relation {
return NewGroupBy(r1, t2, gfcn)
}
// Map creates a new relation by applying a function to tuples in the source
func (r1 *errorRel) Map(mfcn interface{}, ckeystr [][]string) Relation {
return NewMap(r1, mfcn, ckeystr)
}
// Err returns an error encountered during construction or computation
func (r1 *errorRel) Err() error {
return r1.err
}