Skip to content

Commit

Permalink
Change flattenResult signature
Browse files Browse the repository at this point in the history
Change the signature so that it can show multiple results
from a subquery.
  • Loading branch information
animesh2049 committed Sep 23, 2019
1 parent eb55112 commit 9dd6cda
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions query/outputnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,10 @@ func processNodeUids(fj *fastJsonNode, sg *SubGraph) error {

hasChild = true

if err := flattenResult(n1.(*fastJsonNode)); err != nil {
fj.AddListChild(sg.Params.Alias, n1)
if err := flattenResult(n1.(*fastJsonNode), fj, len(fj.attrs)-1); err != nil {
return err
}
fj.AddListChild(sg.Params.Alias, n1)
}

if !hasChild {
Expand Down Expand Up @@ -810,22 +810,21 @@ func (sg *SubGraph) preTraverse(uid uint64, dst outputNode) error {
return nil
}

func flattenResult(node *fastJsonNode) error {
func flattenResult(node, parent *fastJsonNode, childIdx int) error {
if node.isNormalized {
attrList, err := node.normalize()
if err != nil {
return err
}

var allAttrs []*fastJsonNode
parent.attrs[childIdx] = &fastJsonNode{attr: node.attr, attrs: attrList[0]}
attrList = attrList[1:]
for _, attrs := range attrList {
allAttrs = append(allAttrs, attrs...)
parent.attrs = append(parent.attrs, &fastJsonNode{attr: node.attr, attrs: attrs})
}

node.attrs = allAttrs
} else {
for _, child := range node.attrs {
if err := flattenResult(child); err != nil {
for idx, child := range node.attrs {
if err := flattenResult(child, node, idx); err != nil {
return err
}
}
Expand Down

0 comments on commit 9dd6cda

Please sign in to comment.