processBinary handles the binary operands like +, -, *, /, %, max, min, logbase, dot
(mNode *mathTree)
| 38 | // processBinary handles the binary operands like |
| 39 | // +, -, *, /, %, max, min, logbase, dot |
| 40 | func 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 |
searching dependent graphs…