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

Method preTraverse

query/outputnode.go:1346–1622  ·  view source on GitHub ↗

This method gets the values and children for a subprotos.

(enc *encoder, uid uint64, dst fastJsonNode)

Source from the content-addressed store, hash-verified

1344
1345// This method gets the values and children for a subprotos.
1346func (sg *SubGraph) preTraverse(enc *encoder, uid uint64, dst fastJsonNode) error {
1347 if sg.Params.IgnoreReflex {
1348 if alreadySeen(sg.Params.ParentIds, uid) {
1349 // A node can't have itself as the child at any level.
1350 return nil
1351 }
1352 // Push myself to stack before sending this to children.
1353 sg.Params.ParentIds = append(sg.Params.ParentIds, uid)
1354 }
1355
1356 var invalidUids map[uint64]bool
1357 // We go through all predicate children of the subprotos.
1358 for _, pc := range sg.Children {
1359 if pc.Params.IgnoreResult {
1360 continue
1361 }
1362 if pc.IsInternal() {
1363 if pc.Params.Expand != "" {
1364 continue
1365 }
1366 if pc.Params.Normalize && pc.Params.Alias == "" {
1367 continue
1368 }
1369 if err := pc.addInternalNode(enc, uid, dst); err != nil {
1370 return err
1371 }
1372 continue
1373 }
1374
1375 if len(pc.uidMatrix) == 0 {
1376 // Can happen in recurse query.
1377 continue
1378 }
1379 if len(pc.facetsMatrix) > 0 && len(pc.facetsMatrix) != len(pc.uidMatrix) {
1380 return errors.Errorf("Length of facetsMatrix and uidMatrix mismatch: %d vs %d",
1381 len(pc.facetsMatrix), len(pc.uidMatrix))
1382 }
1383
1384 idx := algo.IndexOf(pc.SrcUIDs, uid)
1385 if idx < 0 {
1386 continue
1387 }
1388 if pc.Params.IsGroupBy {
1389 if len(pc.GroupbyRes) <= idx {
1390 return errors.Errorf("Unexpected length while adding Groupby. Idx: [%v], len: [%v]",
1391 idx, len(pc.GroupbyRes))
1392 }
1393 if err := pc.addGroupby(enc, dst, pc.GroupbyRes[idx], pc.fieldName()); err != nil {
1394 return err
1395 }
1396 continue
1397 }
1398
1399 fieldName := pc.fieldName()
1400 switch {
1401 case len(pc.counts) > 0:
1402 if err := pc.addCount(enc, uint64(pc.counts[idx]), dst); err != nil {
1403 return err

Callers 1

processNodeUidsFunction · 0.80

Calls 15

IndexOfFunction · 0.92
alreadySeenFunction · 0.85
convertWithBestEffortFunction · 0.85
IsInternalMethod · 0.80
addInternalNodeMethod · 0.80
addGroupbyMethod · 0.80
fieldNameMethod · 0.80
addCountMethod · 0.80
addCheckPwdMethod · 0.80
idForAttrMethod · 0.80
newNodeMethod · 0.80
SetUIDMethod · 0.80

Tested by

no test coverage detected