Skip to content
Snippets Groups Projects
Unverified Commit daf62d60 authored by Manish R Jain's avatar Manish R Jain
Browse files

Add comments to clarify how ToJson works.

parent 86510f1d
No related branches found
No related tags found
No related merge requests found
...@@ -180,6 +180,17 @@ func postTraverse(g *SubGraph) (result map[uint64]interface{}, rerr error) { ...@@ -180,6 +180,17 @@ func postTraverse(g *SubGraph) (result map[uint64]interface{}, rerr error) {
r.ValuesLength(), q.UidsLength()) r.ValuesLength(), q.UidsLength())
} }
// Generate a matrix of maps
// Row -> .....
// Col
// |
// v
// map{_uid_ = uid}
// If some result is present from children results, then merge.
// Otherwise, this would only contain the _uid_ property.
// result[uid in row] = map[cur attribute ->
// list of maps of {uid, uid + children result}]
//
var ul task.UidList var ul task.UidList
for i := 0; i < r.UidmatrixLength(); i++ { for i := 0; i < r.UidmatrixLength(); i++ {
if ok := r.Uidmatrix(&ul, i); !ok { if ok := r.Uidmatrix(&ul, i); !ok {
...@@ -201,6 +212,7 @@ func postTraverse(g *SubGraph) (result map[uint64]interface{}, rerr error) { ...@@ -201,6 +212,7 @@ func postTraverse(g *SubGraph) (result map[uint64]interface{}, rerr error) {
m[g.Attr] = l m[g.Attr] = l
result[q.Uids(i)] = m result[q.Uids(i)] = m
} }
// TODO(manish): Check what happens if we handle len(l) == 1 separately.
} }
var tv task.Value var tv task.Value
...@@ -210,6 +222,9 @@ func postTraverse(g *SubGraph) (result map[uint64]interface{}, rerr error) { ...@@ -210,6 +222,9 @@ func postTraverse(g *SubGraph) (result map[uint64]interface{}, rerr error) {
} }
val := tv.ValBytes() val := tv.ValBytes()
if bytes.Equal(val, nil) { if bytes.Equal(val, nil) {
// We do this, because we typically do set values, even though
// they might be nil. This is to ensure that the index of the query uids
// and the index of the results can remain in sync.
continue continue
} }
...@@ -217,7 +232,7 @@ func postTraverse(g *SubGraph) (result map[uint64]interface{}, rerr error) { ...@@ -217,7 +232,7 @@ func postTraverse(g *SubGraph) (result map[uint64]interface{}, rerr error) {
glog.WithField("prev", pval). glog.WithField("prev", pval).
WithField("_uid_", q.Uids(i)). WithField("_uid_", q.Uids(i)).
WithField("new", val). WithField("new", val).
Fatal("Previous value detected.") Fatal("Previous value detected. A uid -> list of uids / value. Not both.")
} }
m := make(map[string]interface{}) m := make(map[string]interface{})
m["_uid_"] = fmt.Sprintf("%#x", q.Uids(i)) m["_uid_"] = fmt.Sprintf("%#x", q.Uids(i))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment