Skip to content

Commit

Permalink
Revert "Fix(Dgraph): Fix how visited nodes are detected in recurse qu…
Browse files Browse the repository at this point in the history
…eries. (#6272) (#6276)" (#6306)

This reverts commit 9df9f92.
  • Loading branch information
martinmr authored Aug 28, 2020
1 parent 6618758 commit eb04d17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions query/query3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestRecurseNestedError2(t *testing.T) {
}

func TestRecurseQuery(t *testing.T) {

query := `
{
me(func: uid(0x01)) @recurse {
Expand All @@ -89,7 +90,7 @@ func TestRecurseQuery(t *testing.T) {
}`
js := processQueryNoErr(t, query)
require.JSONEq(t,
`{"data": {"me":[{"name":"Michonne", "friend":[{"name":"Rick Grimes", "friend":[{"name":"Michonne"}]},{"name":"Glenn Rhee"},{"name":"Daryl Dixon"},{"name":"Andrea"}]}]}}`, js)
`{"data": {"me":[{"name":"Michonne", "friend":[{"name":"Rick Grimes", "friend":[{"name":"Michonne"}]},{"name":"Glenn Rhee"},{"name":"Daryl Dixon"},{"name":"Andrea", "friend":[{"name":"Glenn Rhee"}]}]}]}}`, js)
}

func TestRecurseExpand(t *testing.T) {
Expand Down Expand Up @@ -131,7 +132,7 @@ func TestRecurseQueryOrder(t *testing.T) {
}`
js := processQueryNoErr(t, query)
require.JSONEq(t,
`{"data": {"me":[{"dob":"1910-01-01T00:00:00Z","friend":[{"dob":"1910-01-02T00:00:00Z","friend":[{"dob":"1910-01-01T00:00:00Z","name":"Michonne"}],"name":"Rick Grimes"},{"dob":"1909-05-05T00:00:00Z","name":"Glenn Rhee"},{"dob":"1909-01-10T00:00:00Z","name":"Daryl Dixon"},{"dob":"1901-01-15T00:00:00Z","name":"Andrea"}],"name":"Michonne"}]}}`,
`{"data": {"me":[{"dob":"1910-01-01T00:00:00Z","friend":[{"dob":"1910-01-02T00:00:00Z","friend":[{"dob":"1910-01-01T00:00:00Z","name":"Michonne"}],"name":"Rick Grimes"},{"dob":"1909-05-05T00:00:00Z","name":"Glenn Rhee"},{"dob":"1909-01-10T00:00:00Z","name":"Daryl Dixon"},{"dob":"1901-01-15T00:00:00Z","friend":[{"dob":"1909-05-05T00:00:00Z","name":"Glenn Rhee"}],"name":"Andrea"}],"name":"Michonne"}]}}`,
js)
}

Expand All @@ -146,7 +147,7 @@ func TestRecurseQueryAllowLoop(t *testing.T) {
}
}`
js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data":{"me":[{"friend":[{"friend":[{"dob":"1910-01-01T00:00:00Z","name":"Michonne"}],"dob":"1910-01-02T00:00:00Z","name":"Rick Grimes"},{"dob":"1909-05-05T00:00:00Z","name":"Glenn Rhee"},{"dob":"1909-01-10T00:00:00Z","name":"Daryl Dixon"},{"dob":"1901-01-15T00:00:00Z","name":"Andrea"}],"dob":"1910-01-01T00:00:00Z","name":"Michonne"}]}}`, js)
require.JSONEq(t, `{"data":{"me":[{"friend":[{"friend":[{"dob":"1910-01-01T00:00:00Z","name":"Michonne"}],"dob":"1910-01-02T00:00:00Z","name":"Rick Grimes"},{"dob":"1909-05-05T00:00:00Z","name":"Glenn Rhee"},{"dob":"1909-01-10T00:00:00Z","name":"Daryl Dixon"},{"friend":[{"dob":"1909-05-05T00:00:00Z","name":"Glenn Rhee"}],"dob":"1901-01-15T00:00:00Z","name":"Andrea"}],"dob":"1910-01-01T00:00:00Z","name":"Michonne"}]}}`, js)
}

func TestRecurseQueryAllowLoop2(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions query/recurse.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func (start *SubGraph) expandRecurse(ctx context.Context, maxDepth uint64) error {
// Note: Key format is - "attr|toUID"
// Note: Key format is - "attr|fromUID|toUID"
reachMap := make(map[string]struct{})
allowLoop := start.Params.RecurseArgs.AllowLoop
var numEdges uint64
Expand Down Expand Up @@ -118,15 +118,15 @@ func (start *SubGraph) expandRecurse(ctx context.Context, maxDepth uint64) error
sg.updateUidMatrix()
}

for mIdx := range sg.SrcUIDs.Uids {
for mIdx, fromUID := range sg.SrcUIDs.Uids {
if allowLoop {
for _, ul := range sg.uidMatrix {
numEdges += uint64(len(ul.Uids))
}
} else {
algo.ApplyFilter(sg.uidMatrix[mIdx], func(uid uint64, i int) bool {
key := fmt.Sprintf("%s|%d", sg.Attr, uid)
_, seen := reachMap[key]
key := fmt.Sprintf("%s|%d|%d", sg.Attr, fromUID, uid)
_, seen := reachMap[key] // Combine fromUID here.
if seen {
return false
}
Expand Down

0 comments on commit eb04d17

Please sign in to comment.