From e423c6406cf81fd937ee70e026d0ee3091b827ba Mon Sep 17 00:00:00 2001 From: Neeraj Battan Date: Wed, 2 Sep 2020 08:21:05 +0530 Subject: [PATCH 1/3] added the second test --- query/query.go | 5 +++++ query/query1_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/query/query.go b/query/query.go index ba7dfb407df..bf9d0e00a30 100644 --- a/query/query.go +++ b/query/query.go @@ -2010,6 +2010,11 @@ func ProcessGraph(ctx context.Context, sg, parent *SubGraph, rch chan error) { return sg.DestUIDs.Uids[i] < sg.DestUIDs.Uids[j] }) } + if sg.Params.AfterUID > 0 { + i := sort.Search(len(sg.DestUIDs.Uids), func(i int) bool { return sg.DestUIDs.Uids[i] > sg.Params.AfterUID }) + sg.DestUIDs.Uids = sg.DestUIDs.Uids[i:] + } + case sg.Attr == "": // This is when we have uid function in children. if sg.SrcFunc != nil && sg.SrcFunc.Name == "uid" { diff --git a/query/query1_test.go b/query/query1_test.go index 93877330de3..ceac1c21d79 100644 --- a/query/query1_test.go +++ b/query/query1_test.go @@ -669,6 +669,42 @@ func TestHasFuncAtRootWithAfter(t *testing.T) { require.JSONEq(t, `{"data": {"me":[{"friend":[{"count":1}],"name":"Rick Grimes","uid":"0x17"},{"friend":[{"count":1}],"name":"Andrea","uid":"0x1f"}]}}`, js) } +func TestHasFuncAtRootWithAfterOnUIDs(t *testing.T) { + + query := ` + { + var(func: has(name)) { + uids as uid + } + me(func: uid(uids), first: 2, after: 0x5) { + uid + } + } + ` + + js := processQueryNoErr(t, query) + require.JSONEq(t, `{"data": {"me":[{"uid":"0x6"},{"uid":"0x7"}]}}`, js) +} + +func TestHasFuncAtRootWithAfterOnUIDsOtherThanRoot(t *testing.T) { + + query := ` + { + var(func: has(name)) { + uids as uid + } + me(func: has(name), first: 2, after: 0x5) { + uid @filter(uid(uids)) { + uid + } + } + } + ` + + js := processQueryNoErr(t, query) + require.JSONEq(t, `{"data": {"me":[{"uid":"0x6"},{"uid":"0x7"}]}}`, js) +} + func TestHasFuncAtRootFilter(t *testing.T) { query := ` From be5109a7545362106a55461ee7a5b8c27d587e12 Mon Sep 17 00:00:00 2001 From: Neeraj Battan Date: Wed, 2 Sep 2020 12:44:40 +0530 Subject: [PATCH 2/3] updated the second test --- query/query1_test.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/query/query1_test.go b/query/query1_test.go index ceac1c21d79..b1b0de91fd8 100644 --- a/query/query1_test.go +++ b/query/query1_test.go @@ -690,19 +690,20 @@ func TestHasFuncAtRootWithAfterOnUIDsOtherThanRoot(t *testing.T) { query := ` { - var(func: has(name)) { - uids as uid - } - me(func: has(name), first: 2, after: 0x5) { - uid @filter(uid(uids)) { - uid - } + var(func: has(name)) { + uids as uid + } + me(func: uid(0x1, 0x1f)) { + uid + friend(first:2, after:0x5) @filter(uid(uids)) { + uid } + } } ` js := processQueryNoErr(t, query) - require.JSONEq(t, `{"data": {"me":[{"uid":"0x6"},{"uid":"0x7"}]}}`, js) + require.JSONEq(t, `{"data": {"me":[{"uid":"0x1","friend":[{"uid": "0x17"},{"uid": "0x18"}]},{"uid": "0x1f","friend": [{"uid": "0x18"}]}]}`, js) } func TestHasFuncAtRootFilter(t *testing.T) { From 7327a02f5efe9862eeffd70f6d5044c1caf96518 Mon Sep 17 00:00:00 2001 From: Neeraj Battan Date: Wed, 2 Sep 2020 13:09:12 +0530 Subject: [PATCH 3/3] updated the json for second test --- query/query1_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query/query1_test.go b/query/query1_test.go index b1b0de91fd8..80cf6ad044e 100644 --- a/query/query1_test.go +++ b/query/query1_test.go @@ -703,7 +703,7 @@ func TestHasFuncAtRootWithAfterOnUIDsOtherThanRoot(t *testing.T) { ` js := processQueryNoErr(t, query) - require.JSONEq(t, `{"data": {"me":[{"uid":"0x1","friend":[{"uid": "0x17"},{"uid": "0x18"}]},{"uid": "0x1f","friend": [{"uid": "0x18"}]}]}`, js) + require.JSONEq(t, `{"data": {"me":[{"uid":"0x1","friend":[{"uid": "0x17"},{"uid": "0x18"}]},{"uid": "0x1f","friend": [{"uid": "0x18"}]}]}}`, js) } func TestHasFuncAtRootFilter(t *testing.T) {