From 3596e860acc6f92d790f5876b21b3ad0695b1fd0 Mon Sep 17 00:00:00 2001 From: Rohan Prasad Date: Wed, 7 Apr 2021 18:35:53 +0530 Subject: [PATCH 1/2] fix(pagination): Fix after for regexp, match functions --- query/query1_test.go | 28 ++++++++++++++++++++++++++++ query/query3_test.go | 14 ++++++++++++++ worker/match.go | 1 + worker/task.go | 3 +++ worker/trigram.go | 1 + 5 files changed, 47 insertions(+) diff --git a/query/query1_test.go b/query/query1_test.go index 7ad83ae8e77..65fe183825a 100644 --- a/query/query1_test.go +++ b/query/query1_test.go @@ -2545,3 +2545,31 @@ func TestExpandAll_empty_panic(t *testing.T) { js := processQueryNoErr(t, query) require.JSONEq(t, `{"data":{"me":[]}}`, js) } + +func TestMatchFuncWithAfter(t *testing.T) { + query := ` + { + q(func: match(name, Ali, 5), after: 0x2710) { + uid + name + } + } + ` + + js := processQueryNoErr(t, query) + require.JSONEq(t, `{"data": {"q": [{"name": "Alice", "uid": "0x2712"}, {"name": "Alice", "uid": "0x2714"}]}}`, js) +} + +func TestCompareFuncWithAfter(t *testing.T) { + query := ` + { + q(func: eq(name, Alice), after: 0x2710) { + uid + name + } + } + ` + + js := processQueryNoErr(t, query) + require.JSONEq(t, `{"data": {"q": [{"name": "Alice", "uid": "0x2712"}, {"name": "Alice", "uid": "0x2714"}]}}`, js) +} \ No newline at end of file diff --git a/query/query3_test.go b/query/query3_test.go index 1c225a55eaa..6ceeb784f77 100644 --- a/query/query3_test.go +++ b/query/query3_test.go @@ -3216,3 +3216,17 @@ func TestMultiRegexInFilter2(t *testing.T) { require.JSONEq(t, `{"data": {"q": [{"firstName": "Han", "lastName":"Solo"}]}}`, res) } } + +func TestRegexFuncWithAfter(t *testing.T) { + query := ` + { + q(func: regexp(name, /^Ali/i), after: 0x2710) { + uid + name + } + } + ` + + res := processQueryNoErr(t, query) + require.JSONEq(t, `{"data": {"q": [{"name": "Alice", "uid": "0x2712"}, {"name": "Alice", "uid": "0x2714"}]}}`, res) +} \ No newline at end of file diff --git a/worker/match.go b/worker/match.go index fc354159434..21e6fa2a640 100644 --- a/worker/match.go +++ b/worker/match.go @@ -83,6 +83,7 @@ func uidsForMatch(attr string, arg funcArgs) (*roaring64.Bitmap, error) { opts := posting.ListOptions{ ReadTs: arg.q.ReadTs, First: int(arg.q.First), + AfterUid: arg.q.AfterUid, } uidsForNgram := func(ngram string) (*roaring64.Bitmap, error) { key := x.IndexKey(attr, ngram) diff --git a/worker/task.go b/worker/task.go index 60983b2eea8..660a3d4b2fa 100644 --- a/worker/task.go +++ b/worker/task.go @@ -1545,6 +1545,9 @@ func (qs *queryState) filterGeoFunction(ctx context.Context, arg funcArgs) error } var tv pb.TaskValue err = pl.Iterate(arg.q.ReadTs, 0, func(p *pb.Posting) error { + if uid < arg.q.AfterUid { + return nil + } tv.ValType = p.ValType tv.Val = p.Value if types.MatchGeo(&tv, arg.srcFn.geoQuery) { diff --git a/worker/trigram.go b/worker/trigram.go index cce3d36ef1e..bd35fbb54f6 100644 --- a/worker/trigram.go +++ b/worker/trigram.go @@ -37,6 +37,7 @@ func uidsForRegex(attr string, arg funcArgs, opts := posting.ListOptions{ ReadTs: arg.q.ReadTs, First: int(arg.q.First), + AfterUid: arg.q.AfterUid, } // TODO: Unnecessary conversion here. Avoid if possible. if !intersect.IsEmpty() { From 21a938ed2ccbcefdb1608791aa694981e898628f Mon Sep 17 00:00:00 2001 From: Rohan Prasad Date: Thu, 8 Apr 2021 20:47:39 +0530 Subject: [PATCH 2/2] Add test for Geo function --- query/query2_test.go | 13 +++++++++++++ worker/task.go | 3 --- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/query/query2_test.go b/query/query2_test.go index 74e98b0d75a..6642474cc4a 100644 --- a/query/query2_test.go +++ b/query/query2_test.go @@ -3133,3 +3133,16 @@ func TestLangDotInFunction(t *testing.T) { `{"data": {"me":[{"name@pl":"Borsuk europejski","name@en":"European badger"},{"name@en":"Honey badger"},{"name@en":"Honey bee"}]}}`, js) } + +func TestGeoFuncWithAfter(t *testing.T) { + + query := `{ + me(func: near(geometry, [-122.082506, 37.4249518], 1000), after: 0x13ee) { + name + } + }` + + js := processQueryNoErr(t, query) + expected := `{"data": {"me":[{"name": "SF Bay area"}, {"name": "Mountain View"}]}}` + require.JSONEq(t, expected, js) +} diff --git a/worker/task.go b/worker/task.go index 660a3d4b2fa..60983b2eea8 100644 --- a/worker/task.go +++ b/worker/task.go @@ -1545,9 +1545,6 @@ func (qs *queryState) filterGeoFunction(ctx context.Context, arg funcArgs) error } var tv pb.TaskValue err = pl.Iterate(arg.q.ReadTs, 0, func(p *pb.Posting) error { - if uid < arg.q.AfterUid { - return nil - } tv.ValType = p.ValType tv.Val = p.Value if types.MatchGeo(&tv, arg.srcFn.geoQuery) {