-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
edge.go
119 lines (104 loc) · 2.43 KB
/
edge.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
108
109
110
111
112
113
114
115
116
117
118
119
package dataflow
import (
"github.com/stackql/any-sdk/anysdk"
"github.com/stackql/stackql-parser/go/vt/sqlparser"
"gonum.org/v1/gonum/graph"
)
type Edge interface {
graph.WeightedEdge
AddRelation(Relation)
GetColumnDescriptors() ([]anysdk.ColumnDescriptor, error)
GetDest() Vertex
GetProjection() (map[string]string, error)
GetSelectExprs() (sqlparser.SelectExprs, error)
GetSource() Vertex
IsSQL() bool
}
type standardDataFlowEdge struct {
source, dest Vertex
relations []Relation
}
func newStandardDataFlowEdge(
source Vertex,
dest Vertex,
comparisonExpr *sqlparser.ComparisonExpr,
sourceExpr sqlparser.Expr,
destColumn *sqlparser.ColName,
) Edge {
return &standardDataFlowEdge{
source: source,
dest: dest,
relations: []Relation{
NewStandardDataFlowRelation(
comparisonExpr,
destColumn,
sourceExpr,
),
},
}
}
func (de *standardDataFlowEdge) AddRelation(rel Relation) {
de.relations = append(de.relations, rel)
}
func (de *standardDataFlowEdge) From() graph.Node {
return de.source
}
func (de *standardDataFlowEdge) To() graph.Node {
return de.dest
}
func (de *standardDataFlowEdge) ReversedEdge() graph.Edge {
// Reversal is invalid given the assymetric
// expressions, therefore returning unaltered
// as per library recommmendation.
return de
}
func (de *standardDataFlowEdge) Weight() float64 {
return 1.0
}
func (de *standardDataFlowEdge) GetSource() Vertex {
return de.source
}
func (de *standardDataFlowEdge) IsSQL() bool {
for _, rel := range de.relations {
if rel.IsSQL() {
return true
}
}
return false
}
func (de *standardDataFlowEdge) GetDest() Vertex {
return de.dest
}
func (de *standardDataFlowEdge) GetProjection() (map[string]string, error) {
rv := make(map[string]string)
for _, rel := range de.relations {
src, dst, err := rel.GetProjection()
if err != nil {
return nil, err
}
rv[src] = dst
}
return rv, nil
}
func (de *standardDataFlowEdge) GetSelectExprs() (sqlparser.SelectExprs, error) {
var rv sqlparser.SelectExprs
for _, rel := range de.relations {
selExpr, err := rel.GetSelectExpr()
if err != nil {
return nil, err
}
rv = append(rv, selExpr)
}
return rv, nil
}
func (de *standardDataFlowEdge) GetColumnDescriptors() ([]anysdk.ColumnDescriptor, error) {
var rv []anysdk.ColumnDescriptor
for _, rel := range de.relations {
d, err := rel.GetColumnDescriptor()
if err != nil {
return nil, err
}
rv = append(rv, d)
}
return rv, nil
}