Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
animesh2049 committed Sep 23, 2019
1 parent 0174675 commit eb55112
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions query/outputnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type outputNode interface {
AddListChild(attr string, child outputNode)
New(attr string) outputNode
SetUID(uid uint64, attr string)
SetFlatten(flatten bool)
SetNormalize(isNormalized bool)
IsEmpty() bool

addCountAtRoot(*SubGraph)
Expand All @@ -79,13 +79,13 @@ func makeScalarNode(attr string, isChild bool, val []byte, list bool) *fastJsonN
}

type fastJsonNode struct {
attr string
order int // relative ordering (for sorted results)
isChild bool
scalarVal []byte
attrs []*fastJsonNode
list bool
flatten bool
attr string
order int // relative ordering (for sorted results)
isChild bool
scalarVal []byte
attrs []*fastJsonNode
list bool
isNormalized bool
}

func (fj *fastJsonNode) AddValue(attr string, v types.Val) {
Expand Down Expand Up @@ -145,8 +145,8 @@ func (fj *fastJsonNode) IsEmpty() bool {
return len(fj.attrs) == 0
}

func (fj *fastJsonNode) SetFlatten(flatten bool) {
fj.flatten = flatten
func (fj *fastJsonNode) SetNormalize(isNormalized bool) {
fj.isNormalized = isNormalized
}

func valToBytes(v types.Val) ([]byte, error) {
Expand Down Expand Up @@ -476,11 +476,9 @@ func processNodeUids(fj *fastJsonNode, sg *SubGraph) error {

hasChild = true

err := createAttrs(n1)
if err != nil {
if err := flattenResult(n1.(*fastJsonNode)); err != nil {
return err
}

fj.AddListChild(sg.Params.Alias, n1)
}

Expand Down Expand Up @@ -613,7 +611,7 @@ func (sg *SubGraph) preTraverse(uid uint64, dst outputNode) error {
sg.Params.ParentIds = append(sg.Params.ParentIds, uid)
}

dst.SetFlatten(sg.Params.Normalize)
dst.SetNormalize(sg.Params.Normalize)
var invalidUids map[uint64]bool
// We go through all predicate children of the subprotos.
for _, pc := range sg.Children {
Expand Down Expand Up @@ -812,19 +810,8 @@ func (sg *SubGraph) preTraverse(uid uint64, dst outputNode) error {
return nil
}

func createAttrs(oNode outputNode) error {
node := oNode.(*fastJsonNode)

err := flattenResult(node)
if err != nil {
return err
}

return nil
}

func flattenResult(node *fastJsonNode) error {
if node.flatten {
if node.isNormalized {
attrList, err := node.normalize()
if err != nil {
return err
Expand All @@ -838,7 +825,9 @@ func flattenResult(node *fastJsonNode) error {
node.attrs = allAttrs
} else {
for _, child := range node.attrs {
flattenResult(child)
if err := flattenResult(child); err != nil {
return err
}
}
}

Expand Down

0 comments on commit eb55112

Please sign in to comment.