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

Function ProcessGraph

query/query.go:2156–2490  ·  view source on GitHub ↗

ProcessGraph processes the SubGraph instance accumulating result for the query from different instances. Note: taskQuery is nil for root node.

(ctx context.Context, sg, parent *SubGraph, rch chan error)

Source from the content-addressed store, hash-verified

2154// ProcessGraph processes the SubGraph instance accumulating result for the query
2155// from different instances. Note: taskQuery is nil for root node.
2156func ProcessGraph(ctx context.Context, sg, parent *SubGraph, rch chan error) {
2157 var suffix string
2158 if len(sg.Params.Alias) > 0 {
2159 suffix += "." + sg.Params.Alias
2160 }
2161 if len(sg.Attr) > 0 {
2162 suffix += "." + sg.Attr
2163 }
2164 span := trace.SpanFromContext(ctx)
2165 stop := x.SpanTimer(span, "query.ProcessGraph"+suffix)
2166 defer stop()
2167
2168 if sg.Attr == "uid" {
2169 // We dont need to call ProcessGraph for uid, as we already have uids
2170 // populated from parent and there is nothing to process but uidMatrix
2171 // and values need to have the right sizes so that preTraverse works.
2172 sg.appendDummyValues()
2173 rch <- nil
2174 return
2175 }
2176 var err error
2177 switch {
2178 case parent == nil && sg.SrcFunc != nil && sg.SrcFunc.Name == "uid":
2179 // I'm root and I'm using some variable that has been populated.
2180 // Retain the actual order in uidMatrix. But sort the destUids.
2181 if sg.SrcUIDs != nil && len(sg.SrcUIDs.Uids) != 0 {
2182 // I am root. I don't have any function to execute, and my
2183 // result has been prepared for me already by list passed by the user.
2184 // uidmatrix retains the order. SrcUids are sorted (in newGraph).
2185 sg.DestUIDs = sg.SrcUIDs
2186 } else {
2187 // Populated variable.
2188 o := append(sg.DestUIDs.Uids[:0:0], sg.DestUIDs.Uids...)
2189 sg.uidMatrix = []*pb.List{{Uids: o}}
2190 sort.Slice(sg.DestUIDs.Uids, func(i, j int) bool {
2191 return sg.DestUIDs.Uids[i] < sg.DestUIDs.Uids[j]
2192 })
2193 }
2194 if sg.Params.AfterUID > 0 {
2195 i := sort.Search(len(sg.DestUIDs.Uids),
2196 func(i int) bool { return sg.DestUIDs.Uids[i] > sg.Params.AfterUID })
2197 sg.DestUIDs.Uids = sg.DestUIDs.Uids[i:]
2198 }
2199
2200 case sg.Attr == "":
2201 // This is when we have uid function in children.
2202 if sg.SrcFunc != nil && sg.SrcFunc.Name == "uid" {
2203 // If its a uid() filter, we just have to intersect the SrcUIDs with DestUIDs
2204 // and return.
2205 if err := sg.fillVars(sg.Params.ParentVars); err != nil {
2206 rch <- err
2207 return
2208 }
2209 algo.IntersectWith(sg.DestUIDs, sg.SrcUIDs, sg.DestUIDs)
2210 rch <- nil
2211 return
2212 }
2213

Callers 3

expandOutMethod · 0.85
ProcessQueryMethod · 0.85
expandRecurseMethod · 0.85

Calls 15

SpanTimerFunction · 0.92
IntersectWithFunction · 0.92
ConvertFunction · 0.92
CompareValsFunction · 0.92
ProcessTaskOverNetworkFunction · 0.92
IntersectSortedFunction · 0.92
MergeSortedFunction · 0.92
AssertTrueFunction · 0.92
DifferenceFunction · 0.92
isInequalityFnFunction · 0.85
createTaskQueryFunction · 0.85
expandSubgraphFunction · 0.85

Tested by

no test coverage detected