MCPcopy
hub / github.com/dgraph-io/dgraph / addAggregations

Method addAggregations

query/outputnode.go:1040–1065  ·  view source on GitHub ↗
(enc *encoder, fj fastJsonNode)

Source from the content-addressed store, hash-verified

1038}
1039
1040func (sg *SubGraph) addAggregations(enc *encoder, fj fastJsonNode) error {
1041 for _, child := range sg.Children {
1042 aggVal, ok := child.Params.UidToVal.Get(0)
1043 if !ok {
1044 if len(child.Params.NeedsVar) == 0 {
1045 return errors.Errorf("Only aggregated variables allowed within empty block.")
1046 }
1047 // the aggregation didn't happen, most likely was called with unset vars.
1048 // See: query.go:fillVars
1049 // In this case we do nothing. The aggregate value in response will be returned as NULL.
1050 }
1051 if child.Params.Normalize && child.Params.Alias == "" {
1052 continue
1053 }
1054 fieldName := child.aggWithVarFieldName()
1055 n1 := enc.newNode(enc.idForAttr(sg.Params.Alias))
1056 if err := enc.AddValue(n1, enc.idForAttr(fieldName), aggVal); err != nil {
1057 return err
1058 }
1059 enc.AddListChild(fj, n1)
1060 }
1061 if enc.IsEmpty(fj) {
1062 enc.AddListChild(fj, enc.newNode(enc.idForAttr(sg.Params.Alias)))
1063 }
1064 return nil
1065}
1066
1067func (sg *SubGraph) handleCountUIDNodes(enc *encoder, n fastJsonNode, count int) (bool, error) {
1068 addedNewChild := false

Callers 1

processNodeUidsFunction · 0.80

Calls 8

aggWithVarFieldNameMethod · 0.80
newNodeMethod · 0.80
idForAttrMethod · 0.80
AddValueMethod · 0.80
AddListChildMethod · 0.80
GetMethod · 0.65
ErrorfMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected