MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / processBinary

Function processBinary

query/math.go:40–141  ·  view source on GitHub ↗

processBinary handles the binary operands like +, -, *, /, %, max, min, logbase, dot

(mNode *mathTree)

Source from the content-addressed store, hash-verified

38// processBinary handles the binary operands like
39// +, -, *, /, %, max, min, logbase, dot
40func processBinary(mNode *mathTree) error {
41 aggName := mNode.Fn
42
43 mpl := mNode.Child[0].Val
44 mpr := mNode.Child[1].Val
45 cl := mNode.Child[0].Const
46 cr := mNode.Child[1].Const
47
48 f := func(k uint64, lshard, rshard, destMapi *map[uint64]types.Val) error {
49 ag := aggregator{
50 name: aggName,
51 }
52 lVal := (*lshard)[k]
53 if cl.Value != nil {
54 // Use the constant value that was supplied.
55 lVal = cl
56 }
57 rVal := (*rshard)[k]
58 if cr.Value != nil {
59 // Use the constant value that was supplied.
60 rVal = cr
61 }
62 err := ag.ApplyVal(lVal)
63 if err != nil {
64 return err
65 }
66 err = ag.ApplyVal(rVal)
67 if err != nil {
68 return err
69 }
70 (*destMapi)[k], err = ag.Value()
71 if err != nil {
72 return err
73 }
74 return nil
75 }
76
77 // If mpl or mpr have 0 and just 0 in it, that means it's an output of aggregation somewhere.
78 // This value would need to be applied to all.
79 checkAggrResult := func(value *types.ShardedMap) (types.Val, bool) {
80 if value.Len() != 1 {
81 return types.Val{}, false
82 }
83
84 val, ok := value.Get(0)
85 return val, ok
86 }
87
88 if val, ok := checkAggrResult(mpl); ok {
89 cl = val
90 mpl = nil
91 } else if val, ok := checkAggrResult(mpr); ok {
92 cr = val
93 mpr = nil
94 }
95
96 if mpl.Len() != 0 || mpr.Len() != 0 {
97 var wg sync.WaitGroup

Callers 4

evalMathTreeFunction · 0.85
TestProcessBinaryFunction · 0.85

Calls 9

ApplyValMethod · 0.95
ValueMethod · 0.95
GetShardOrNilMethod · 0.95
NewShardedMapFunction · 0.92
WaitMethod · 0.80
LenMethod · 0.65
GetMethod · 0.65
AddMethod · 0.45
DoneMethod · 0.45

Tested by 3

TestProcessBinaryFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…