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

fix(pagination): Fix after for regexp, match functions #7700

Merged
merged 2 commits into from
Apr 13, 2021
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
28 changes: 28 additions & 0 deletions query/query1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 13 additions & 0 deletions query/query2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 14 additions & 0 deletions query/query3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions worker/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions worker/trigram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down