(enc *encoder, fj fastJsonNode)
| 1038 | } |
| 1039 | |
| 1040 | func (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 | |
| 1067 | func (sg *SubGraph) handleCountUIDNodes(enc *encoder, n fastJsonNode, count int) (bool, error) { |
| 1068 | addedNewChild := false |
no test coverage detected