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

Method populateVarMap

query/query.go:1445–1527  ·  view source on GitHub ↗

populateVarMap stores the value of the variable defined in this SubGraph into req.Vars so that it is available to other queries as well. It is called after a query has been executed. TODO (pawan) - This function also transforms the DestUids and uidMatrix if the query is a cascade query which should

(doneVars map[string]varValue, sgPath []*SubGraph)

Source from the content-addressed store, hash-verified

1443// TODO (pawan) - This function also transforms the DestUids and uidMatrix if the query is a cascade
1444// query which should probably happen before.
1445func (sg *SubGraph) populateVarMap(doneVars map[string]varValue, sgPath []*SubGraph) error {
1446 if sg.DestUIDs == nil || sg.IsGroupBy() {
1447 return nil
1448 }
1449
1450 cascadeArgMap := make(map[string]bool)
1451 for _, pred := range sg.Params.Cascade.Fields {
1452 cascadeArgMap[pred] = true
1453 }
1454 cascadeAllPreds := cascadeArgMap["__all__"]
1455
1456 out := make([]uint64, 0, len(sg.DestUIDs.Uids))
1457 if sg.Params.Alias == "shortest" {
1458 goto AssignStep
1459 }
1460
1461 if len(sg.Filters) > 0 {
1462 sg.updateUidMatrix()
1463 }
1464
1465 for _, child := range sg.Children {
1466 sgPath = append(sgPath, sg) // Add the current node to path
1467 if err := child.populateVarMap(doneVars, sgPath); err != nil {
1468 return err
1469 }
1470 sgPath = sgPath[:len(sgPath)-1] // Backtrack
1471 if len(child.Params.Cascade.Fields) == 0 {
1472 continue
1473 }
1474
1475 // Intersect the UidMatrix with the DestUids as some UIDs might have been removed
1476 // by other operations. So we need to apply it on the UidMatrix.
1477 child.updateUidMatrix()
1478
1479 // Apply pagination after the @cascade.
1480 if len(child.Params.Cascade.Fields) > 0 &&
1481 (child.Params.Cascade.First != 0 || child.Params.Cascade.Offset != 0) {
1482
1483 for i := range child.uidMatrix {
1484 start, end := x.PageRange(child.Params.Cascade.First,
1485 child.Params.Cascade.Offset, len(child.uidMatrix[i].Uids))
1486 child.uidMatrix[i].Uids = child.uidMatrix[i].Uids[start:end]
1487 }
1488 }
1489 }
1490
1491 if len(sg.Params.Cascade.Fields) == 0 {
1492 goto AssignStep
1493 }
1494
1495 // Filter out UIDs that don't have atleast one UID in every child.
1496 for i, uid := range sg.DestUIDs.Uids {
1497 var exclude bool
1498 for _, child := range sg.Children {
1499 // For uid we dont actually populate the uidMatrix or values. So a node asking for
1500 // uid would always be excluded. Therefore we skip it.
1501 if child.Attr == "uid" {
1502 continue

Callers 1

ProcessQueryMethod · 0.80

Calls 5

IsGroupByMethod · 0.95
updateUidMatrixMethod · 0.95
updateVarsMethod · 0.95
PageRangeFunction · 0.92
IsInternalMethod · 0.80

Tested by

no test coverage detected