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

Function processNodeUids

query/outputnode.go:1096–1171  ·  view source on GitHub ↗
(fj fastJsonNode, enc *encoder, sg *SubGraph)

Source from the content-addressed store, hash-verified

1094}
1095
1096func processNodeUids(fj fastJsonNode, enc *encoder, sg *SubGraph) error {
1097 if sg.Params.IsEmpty {
1098 return sg.addAggregations(enc, fj)
1099 }
1100
1101 enc.curSize += uint64(len(sg.Params.Alias))
1102
1103 attrID := enc.idForAttr(sg.Params.Alias)
1104 if sg.uidMatrix == nil {
1105 enc.AddListChild(fj, enc.newNode(attrID))
1106 return nil
1107 }
1108
1109 hasChild, err := sg.handleCountUIDNodes(enc, fj, len(sg.DestUIDs.Uids))
1110 if err != nil {
1111 return err
1112 }
1113 if sg.Params.IsGroupBy {
1114 if len(sg.GroupbyRes) == 0 {
1115 return errors.Errorf("Expected GroupbyRes to have length > 0.")
1116 }
1117 return sg.addGroupby(enc, fj, sg.GroupbyRes[0], sg.Params.Alias)
1118 }
1119
1120 lenList := len(sg.uidMatrix[0].Uids)
1121 for i := range lenList {
1122 uid := sg.uidMatrix[0].Uids[i]
1123 if algo.IndexOf(sg.DestUIDs, uid) < 0 {
1124 // This UID was filtered. So Ignore it.
1125 continue
1126 }
1127
1128 n1 := enc.newNode(attrID)
1129 enc.setAttr(n1, enc.idForAttr(sg.Params.Alias))
1130 if err := sg.preTraverse(enc, uid, n1); err != nil {
1131 if err.Error() == "_INV_" {
1132 continue
1133 }
1134 return err
1135 }
1136
1137 if enc.IsEmpty(n1) {
1138 continue
1139 }
1140
1141 hasChild = true
1142 if !sg.Params.Normalize {
1143 enc.AddListChild(fj, n1)
1144 continue
1145 }
1146
1147 // With the new changes we store children in reverse order(check addChildren method). This
1148 // leads to change of order of field responses for existing Normalize test cases. To
1149 // minimize the changes of existing tests case we are fixing order of node children before
1150 // calling normalize() on it. Also once we have fixed order for children, we don't need to
1151 // fix its order again. Hence mark the newly created node visited immediately.
1152 enc.fixOrder(n1)
1153 // Lets normalize the response now.

Callers 1

toFastJSONMethod · 0.85

Calls 15

IndexOfFunction · 0.92
addAggregationsMethod · 0.80
idForAttrMethod · 0.80
AddListChildMethod · 0.80
newNodeMethod · 0.80
handleCountUIDNodesMethod · 0.80
addGroupbyMethod · 0.80
setAttrMethod · 0.80
preTraverseMethod · 0.80
fixOrderMethod · 0.80
normalizeMethod · 0.80
setVisitedMethod · 0.80

Tested by

no test coverage detected