Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(release/v20.07) Revert "Fix(Dgraph): Fix how visited nodes are detected in recurse qu… #6306

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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