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

Method populateUidValVar

query/query.go:1550–1667  ·  view source on GitHub ↗

populateUidValVar populates the value of the variable into doneVars.

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

Source from the content-addressed store, hash-verified

1548
1549// populateUidValVar populates the value of the variable into doneVars.
1550func (sg *SubGraph) populateUidValVar(doneVars map[string]varValue, sgPath []*SubGraph) error {
1551 if sg.Params.Var == "" {
1552 return nil
1553 }
1554
1555 var v varValue
1556 var ok bool
1557
1558 switch {
1559 case len(sg.counts) > 0:
1560 // 1. When count of a predicate is assigned a variable, we store the mapping of uid =>
1561 // count(predicate).
1562
1563 // This implies it is a value variable.
1564 doneVars[sg.Params.Var] = varValue{
1565 Vals: types.NewShardedMap(),
1566 path: sgPath,
1567 strList: sg.valueMatrix,
1568 }
1569 for idx, uid := range sg.SrcUIDs.Uids {
1570 val := types.Val{
1571 Tid: types.IntID,
1572 Value: int64(sg.counts[idx]),
1573 }
1574 doneVars[sg.Params.Var].Vals.Set(uid, val)
1575 }
1576 case sg.Params.DoCount && sg.Attr == "uid" && sg.IsInternal():
1577 // 2. This is the case where count(uid) is requested in the query and stored as variable.
1578 // In this case there is just one value which is stored corresponding to the uid
1579 // math.MaxUint64 which isn't entirely correct as there could be an actual uid with that
1580 // value.
1581 doneVars[sg.Params.Var] = varValue{
1582 Vals: types.NewShardedMap(),
1583 path: sgPath,
1584 strList: sg.valueMatrix,
1585 }
1586
1587 // Because we are counting the number of UIDs in parent
1588 // we use the length of SrcUIDs instead of DestUIDs.
1589 val := types.Val{
1590 Tid: types.IntID,
1591 Value: int64(len(sg.SrcUIDs.Uids)),
1592 }
1593 doneVars[sg.Params.Var].Vals.Set(math.MaxUint64, val)
1594 case len(sg.DestUIDs.Uids) != 0 || (sg.Attr == "uid" && sg.SrcUIDs != nil):
1595 // 3. A uid variable. The variable could be defined in one of two places.
1596 // a) Either on the actual predicate.
1597 // me(func: (...)) {
1598 // a as friend
1599 // }
1600 //
1601 // b) Or on the uid edge
1602 // me(func:(...)) {
1603 // friend {
1604 // a as uid
1605 // }
1606 // }
1607

Callers 1

updateVarsMethod · 0.95

Calls 6

IsInternalMethod · 0.95
NewShardedMapFunction · 0.92
MergeSortedFunction · 0.92
convertWithBestEffortFunction · 0.85
SetMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected