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(sort): Only filter out nodes with positive offsets. (#8077) #8441

Merged
merged 9 commits into from
Dec 2, 2022
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
13 changes: 13 additions & 0 deletions query/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ type Person {
alive
}
type Person2 {
name2
age2
}
type Animal {
name
}
Expand Down Expand Up @@ -332,6 +337,8 @@ tweet-a : string @index(trigram) .
tweet-b : string @index(term) .
tweet-c : string @index(fulltext) .
tweet-d : string @index(trigram) .
name2 : string @index(term) .
age2 : int @index(int) .
`

func populateCluster() {
Expand Down Expand Up @@ -629,6 +636,7 @@ func populateCluster() {
<5> <dgraph.type> "Pet" .
<6> <dgraph.type> "Animal" .
<6> <dgraph.type> "Pet" .
<23> <dgraph.type> "Person" .
<24> <dgraph.type> "Person" .
<25> <dgraph.type> "Person" .
Expand All @@ -638,6 +646,8 @@ func populateCluster() {
<34> <dgraph.type> "SchoolInfo" .
<35> <dgraph.type> "SchoolInfo" .
<36> <dgraph.type> "SchoolInfo" .
<40> <dgraph.type> "Person2" .
<41> <dgraph.type> "Person2" .
<11100> <dgraph.type> "Node" .
<2> <pet> <5> .
Expand Down Expand Up @@ -851,6 +861,9 @@ func populateCluster() {
<61> <tweet-d> "aaabxxx" .
<62> <tweet-d> "aaacdxx" .
<63> <tweet-d> "aaabcd" .
<40> <name2> "Alice" .
<41> <age2> "20" .
`)
if err != nil {
panic(fmt.Sprintf("Could not able add triple to the cluster. Got error %v", err.Error()))
Expand Down
14 changes: 14 additions & 0 deletions query/query0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,20 @@ func TestCascadeWithSort(t *testing.T) {
require.JSONEq(t, `{"data":{"me":[{"name": "Daryl Dixon","alive": false},{"name": "Rick Grimes","alive": true}]}}`, js)
}

// Regression test for issue described in https://github.com/dgraph-io/dgraph/pull/8441
func TestNegativeOffset(t *testing.T) {
query := `
{
me(func: type(Person2), offset: -1, orderasc: age2) {
name2
age2
}
}
`
js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data":{"me":[{"age2":20},{"name2":"Alice"}]}}`, js)
}

func TestLevelBasedFacetVarAggSum(t *testing.T) {
query := `
{
Expand Down
4 changes: 3 additions & 1 deletion worker/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ BUCKETS:

// Apply the offset on null nodes, if the nodes with value were not enough.
if out[i].offset < len(nullNodes) {
nullNodes = nullNodes[out[i].offset:]
if out[i].offset >= 0 {
nullNodes = nullNodes[out[i].offset:]
}
} else {
nullNodes = nullNodes[:0]
}
Expand Down