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

Function evalLevelAgg

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

Source from the content-addressed store, hash-verified

1040}
1041
1042func evalLevelAgg(
1043 doneVars map[string]varValue,
1044 sg, parent *SubGraph) (*types.ShardedMap, error) {
1045 var mp *types.ShardedMap
1046
1047 if parent == nil {
1048 return nil, ErrWrongAgg
1049 }
1050
1051 needsVar := sg.Params.NeedsVar[0].Name
1052 if parent.Params.IsEmpty {
1053 // The aggregated value doesn't really belong to a uid, we put it in UidToVal map
1054 // corresponding to uid 0 to avoid defining another field in SubGraph.
1055 vals := doneVars[needsVar].Vals
1056
1057 ag := aggregator{
1058 name: sg.SrcFunc.Name,
1059 }
1060 err := vals.Iterate(func(k uint64, val types.Val) error {
1061 err := ag.Apply(val)
1062 if err != nil {
1063 return err
1064 }
1065 return nil
1066 })
1067 if err != nil {
1068 return nil, err
1069 }
1070 v, err := ag.Value()
1071 if err != nil && err != ErrEmptyVal {
1072 return nil, err
1073 }
1074 if v.Value != nil {
1075 mp = types.NewShardedMap()
1076 mp.Set(0, v)
1077 }
1078 return mp, nil
1079 }
1080
1081 var relSG *SubGraph
1082 for _, ch := range parent.Children {
1083 if sg == ch {
1084 continue
1085 }
1086 for _, v := range ch.Params.FacetVar {
1087 if v == needsVar {
1088 relSG = ch
1089 }
1090 }
1091 for _, cch := range ch.Children {
1092 // Find the sibling node whose child has the required variable.
1093 if cch.Params.Var == needsVar {
1094 relSG = ch
1095 }
1096 }
1097 }
1098 if relSG == nil {
1099 return nil, errors.Errorf("Invalid variable aggregation. Check the levels.")

Callers 1

valueVarAggregationMethod · 0.85

Calls 7

ApplyMethod · 0.95
ValueMethod · 0.95
SetMethod · 0.95
NewShardedMapFunction · 0.92
GetMethod · 0.65
IterateMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected