MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / valueVarAggregation

Method valueVarAggregation

query/query.go:1262–1377  ·  view source on GitHub ↗
(doneVars map[string]varValue, path []*SubGraph,
	parent *SubGraph)

Source from the content-addressed store, hash-verified

1260}
1261
1262func (sg *SubGraph) valueVarAggregation(doneVars map[string]varValue, path []*SubGraph,
1263 parent *SubGraph) error {
1264 if !sg.IsInternal() && !sg.IsGroupBy() && !sg.Params.IsEmpty {
1265 return nil
1266 }
1267
1268 // Aggregation function won't be present at root.
1269 if sg.Params.IsEmpty && parent == nil {
1270 return nil
1271 }
1272
1273 switch {
1274 case sg.IsGroupBy():
1275 if err := sg.processGroupBy(doneVars, path); err != nil {
1276 return err
1277 }
1278 case sg.SrcFunc != nil && !parent.IsGroupBy() && isAggregatorFn(sg.SrcFunc.Name):
1279 // Aggregate the value over level.
1280 mp, err := evalLevelAgg(doneVars, sg, parent)
1281 if err != nil {
1282 return err
1283 }
1284 if sg.Params.Var != "" {
1285 it := doneVars[sg.Params.Var]
1286 it.Vals = mp
1287 doneVars[sg.Params.Var] = it
1288 }
1289 sg.Params.UidToVal = mp
1290 case sg.MathExp != nil:
1291 // Preprocess to bring all variables to the same level.
1292 err := sg.transformVars(doneVars, path)
1293 if err != nil {
1294 return err
1295 }
1296
1297 err = evalMathTree(sg.MathExp)
1298 if err != nil {
1299 return err
1300 }
1301
1302 switch {
1303 case sg.MathExp.Val.Len() != 0:
1304 it := doneVars[sg.Params.Var]
1305 var isInt, isFloat bool
1306 err := sg.MathExp.Val.Iterate(func(k uint64, v types.Val) error {
1307 if v.Tid == types.FloatID {
1308 isFloat = true
1309 }
1310 if v.Tid == types.IntID {
1311 isInt = true
1312 }
1313 return nil
1314 })
1315 if err != nil {
1316 return err
1317 }
1318 if isInt && isFloat {
1319 err := sg.MathExp.Val.Iterate(func(k uint64, v types.Val) error {

Callers 1

Calls 14

IsInternalMethod · 0.95
IsGroupByMethod · 0.95
processGroupByMethod · 0.95
transformVarsMethod · 0.95
SetMethod · 0.95
NewShardedMapFunction · 0.92
isAggregatorFnFunction · 0.85
evalLevelAggFunction · 0.85
evalMathTreeFunction · 0.85
InfoMethod · 0.80
LenMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected