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): Make sort consistent for indexed and without indexed predicates #7241

Merged
merged 20 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 17 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
23 changes: 22 additions & 1 deletion query/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ noindex_salary : float .
language : [string] .
score : [int] @index(int) .
average : [float] @index(float) .
gender : string .
gender : string .
pred : string @index(exact) .
predname : string .
`

func populateCluster() {
Expand Down Expand Up @@ -758,6 +760,25 @@ func populateCluster() {
<20001> <average> "49.33" .
<20001> <pet_name> "mahi" .
<20001> <pet_name> "ms" .

# data for testing consistency of sort
<61> <pred> "A" .
<62> <pred> "B" .
<63> <pred> "C" .
<64> <pred> "D" .
<65> <pred> "E" .

<61> <predname> "nameA" .
<62> <predname> "nameB" .
<63> <predname> "nameC" .
<64> <predname> "nameD" .
<65> <predname> "nameE" .
<66> <predname> "nameF" .
<67> <predname> "nameG" .
<68> <predname> "nameH" .
<69> <predname> "nameI" .
<70> <predname> "nameJ" .

`)
if err != nil {
panic(fmt.Sprintf("Could not able add triple to the cluster. Got error %v", err.Error()))
Expand Down
189 changes: 189 additions & 0 deletions query/query1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,195 @@ func TestMultiSort7Paginate(t *testing.T) {
require.JSONEq(t, `{"data": {"me":[{"name":"Alice","age":25},{"name":"Alice","age":75},{"name":"Alice","age":75},{"name":"Bob","age":25},{"name":"Bob","age":75},{"name":"Colin","age":25},{"name":"Elizabeth","age":25}]}}`, js)
}

func TestSortNull1(t *testing.T) {

query := `{
me(func: uid(61, 62, 63, 64, 65, 66, 67, 68, 69, 70), orderasc: pred) {
predname
pred
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[{"predname":"nameA","pred":"A"},
{"predname":"nameB","pred":"B"},
{"predname":"nameC","pred":"C"},
{"predname":"nameD","pred":"D"},
{"predname":"nameE","pred":"E"},
{"predname":"nameF"},
{"predname":"nameG"},
{"predname":"nameH"},
{"predname":"nameI"},
{"predname":"nameJ"}]}}`, js)
}

func TestSortNull1Desc(t *testing.T) {

query := `{
me(func: uid(61, 62, 63, 64, 65, 66, 67, 68, 69, 70), orderdesc: pred) {
predname
pred
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[
{"predname":"nameE","pred":"E"},
{"predname":"nameD","pred":"D"},
{"predname":"nameC","pred":"C"},
{"predname":"nameB","pred":"B"},
{"predname":"nameA","pred":"A"},
{"predname":"nameF"},
{"predname":"nameG"},
{"predname":"nameH"},
{"predname":"nameI"},
{"predname":"nameJ"}]}}`, js)
}

func TestSortNull2(t *testing.T) {

query := `{
me(func: uid(61, 62, 63, 64, 65, 66, 67, 68, 69, 70), orderasc: pred, first: 7) {
predname
pred
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[
{"predname":"nameA","pred":"A"},
{"predname":"nameB","pred":"B"},
{"predname":"nameC","pred":"C"},
{"predname":"nameD","pred":"D"},
{"predname":"nameE","pred":"E"},
{"predname":"nameF"},
{"predname":"nameG"}]}}`, js)
}

func TestSortNull2Desc(t *testing.T) {

query := `{
me(func: uid(61, 62, 63, 64, 65, 66, 67, 68, 69, 70), orderdesc: pred, first: 7) {
predname
pred
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[
{"predname":"nameE","pred":"E"},
{"predname":"nameD","pred":"D"},
{"predname":"nameC","pred":"C"},
{"predname":"nameB","pred":"B"},
{"predname":"nameA","pred":"A"},
{"predname":"nameF"},
{"predname":"nameG"}]}}`, js)
}

func TestSortNull3(t *testing.T) {

query := `{
me(func: uid(61, 62, 63, 64, 65, 66, 67, 68, 69, 70), orderasc: pred, first: 7, offset: 2) {
predname
pred
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[
{"predname":"nameC","pred":"C"},
{"predname":"nameD","pred":"D"},
{"predname":"nameE","pred":"E"},
{"predname":"nameF"},
{"predname":"nameG"},
{"predname":"nameH"},
{"predname":"nameI"}]}}`, js)
}

func TestSortNull3Desc(t *testing.T) {

query := `{
me(func: uid(61, 62, 63, 64, 65, 66, 67, 68, 69, 70), orderdesc: pred, first: 7, offset: 2) {
predname
pred
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[
{"predname":"nameC","pred":"C"},
{"predname":"nameB","pred":"B"},
{"predname":"nameA","pred":"A"},
{"predname":"nameF"},
{"predname":"nameG"},
{"predname":"nameH"},
{"predname":"nameI"}]}}`, js)
}

func TestSortNull4(t *testing.T) {

query := `{
me(func: uid(61, 62, 63, 64, 65, 66, 67, 68, 69, 70), orderasc: pred, first: 4, offset: 5) {
predname
pred
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[
{"predname":"nameF"},
{"predname":"nameG"},
{"predname":"nameH"},
{"predname":"nameI"}]}}`, js)
}

func TestSortNull4Desc(t *testing.T) {

query := `{
me(func: uid(61, 62, 63, 64, 65, 66, 67, 68, 69, 70), orderdesc: pred, first: 4, offset: 5) {
predname
pred
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[
{"predname":"nameF"},
{"predname":"nameG"},
{"predname":"nameH"},
{"predname":"nameI"}]}}`, js)
}

func TestSortNull5(t *testing.T) {

query := `{
me(func: uid(61, 62, 63, 64, 65, 66, 67, 68, 69, 70), orderasc: pred, first: 2) {
predname
pred
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[
{"predname":"nameA", "pred": "A"},
{"predname":"nameB","pred":"B"}]}}`, js)
}

func TestSortNull5Desc(t *testing.T) {

query := `{
me(func: uid(61, 62, 63, 64, 65, 66, 67, 68, 69, 70), orderdesc: pred, first: 2) {
predname
pred
}
}`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[
{"predname":"nameE", "pred":"E"},
{"predname":"nameD", "pred": "D"}]}}`, js)
}

func TestMultiSortPaginateWithOffset(t *testing.T) {
t.Parallel()
tests := []struct {
Expand Down
16 changes: 14 additions & 2 deletions query/query2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,13 @@ func TestLanguageOrderIndexed3(t *testing.T) {
require.JSONEq(t,
`{
"data": {
"q": []
"q": [{
"name_lang_index@de": "öffnen",
"name_lang_index@sv": "zon"
}, {
"name_lang_index@de": "zumachen",
"name_lang_index@sv": "öppna"
}]
}
}`,
js)
Expand All @@ -993,7 +999,13 @@ func TestLanguageOrderIndexed4(t *testing.T) {
require.JSONEq(t,
`{
"data": {
"q": []
"q": [{
"name_lang_index@de": "öffnen",
"name_lang_index@sv": "zon"
}, {
"name_lang_index@de": "zumachen",
"name_lang_index@sv": "öppna"
}]
}
}`,
js)
Expand Down
6 changes: 4 additions & 2 deletions query/rdf_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,13 @@ func TestDateRDF(t *testing.T) {
`
rdf, err := processQueryRDF(context.Background(), t, query)
require.NoError(t, err)
require.Equal(t, rdf, `<0x1> <name> "Michonne" .
expected := `<0x1> <name> "Michonne" .
<0x1> <gender> "female" .
<0x1> <friend> <0x19> .
<0x1> <friend> <0x18> .
<0x1> <friend> <0x17> .
<0x1> <friend> <0x1f> .
<0x1> <friend> <0x65> .
<0x17> <name> "Rick Grimes" .
<0x18> <name> "Glenn Rhee" .
<0x19> <name> "Daryl Dixon" .
Expand All @@ -233,5 +234,6 @@ func TestDateRDF(t *testing.T) {
<0x18> <film.film.initial_release_date> "1909-05-05T00:00:00Z" .
<0x19> <film.film.initial_release_date> "1929-01-10T00:00:00Z" .
<0x1f> <film.film.initial_release_date> "1801-01-15T00:00:00Z" .
`)
`
require.Equal(t, expected, rdf)
}
Loading