This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
join.go
64 lines (55 loc) · 1.72 KB
/
join.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
package godata
import (
"fmt"
"github.com/google/godata/row"
)
// JoinResult represents the result of a join operation.
type JoinResult struct {
// Left contains the contents in the left side of the join, or nil if the
// left frame did not contain a row for the key. Left must contain the same
// index as Right.
Left interface{}
// Right contains the contents in the right side of the join, or nil if the
// right frame did not contain a row for the key. Left must contain the same
// index as Right.
Right interface{}
}
// String returns the string representation of this JoinResult.
func (j JoinResult) String() string {
if j.Left != nil && j.Right != nil {
return fmt.Sprintf("JoinResult{Left: %v, Right: %v}", j.Left, j.Right)
}
if j.Left == nil {
return fmt.Sprintf("JoinResult{Right: %v}", j.Right)
}
if j.Right == nil {
return fmt.Sprintf("JoinResult{Left: %v}", j.Left)
}
return "JoinResult{}"
}
// JoinResultIndexer indexes a JoinResult by delegating to the given RowIndexer.
type JoinResultIndexer struct {
// RowIndexer is the indexer to use for the RowData in either Left or Right.
RowIndexer row.Indexer
}
// Index returns the index of the contents of a JoinResult. At least one of
// Left and Right must be non-nil. If both Left and Right are non-nil, then
// they must have the same index value.
func (j JoinResultIndexer) Index(data row.Data) (row.Index, error) {
projection := make(map[string]interface{})
for key, val := range data {
r, ok := val.(*JoinResult)
if !ok {
projection[key] = val
continue
}
if r.Left != nil {
projection[key] = r.Left
} else if r.Right != nil {
projection[key] = r.Right
} else {
projection[key] = nil
}
}
return j.RowIndexer.Index(projection)
}