processTernary handles the ternary operand cond()
(mNode *mathTree)
| 209 | |
| 210 | // processTernary handles the ternary operand cond() |
| 211 | func processTernary(mNode *mathTree) error { |
| 212 | destMap := types.NewShardedMap() |
| 213 | aggName := mNode.Fn |
| 214 | condMap := mNode.Child[0].Val |
| 215 | if condMap.IsEmpty() { |
| 216 | return errors.Errorf("Expected a value variable in %v but missing.", aggName) |
| 217 | } |
| 218 | varOne := mNode.Child[1].Val |
| 219 | varTwo := mNode.Child[2].Val |
| 220 | constOne := mNode.Child[1].Const |
| 221 | constTwo := mNode.Child[2].Const |
| 222 | condMap.Iterate(func(k uint64, val types.Val) error { |
| 223 | var res types.Val |
| 224 | v, ok := val.Value.(bool) |
| 225 | if !ok { |
| 226 | return errors.Errorf("First variable of conditional function not a bool value") |
| 227 | } |
| 228 | if v { |
| 229 | // Pick the value of first map. |
| 230 | if constOne.Value != nil { |
| 231 | res = constOne |
| 232 | } else { |
| 233 | res, _ = varOne.Get(k) |
| 234 | } |
| 235 | } else { |
| 236 | // Pick the value of second map. |
| 237 | if constTwo.Value != nil { |
| 238 | res = constTwo |
| 239 | } else { |
| 240 | res, _ = varTwo.Get(k) |
| 241 | } |
| 242 | } |
| 243 | destMap.Set(k, res) |
| 244 | return nil |
| 245 | }) |
| 246 | mNode.Val = destMap |
| 247 | return nil |
| 248 | } |
| 249 | |
| 250 | func evalMathTree(mNode *mathTree) error { |
| 251 | if mNode.Const.Value != nil { |
searching dependent graphs…