diff --git a/dql/parser.go b/dql/parser.go index b04a48dc732..7ad4f9fc500 100644 --- a/dql/parser.go +++ b/dql/parser.go @@ -2948,6 +2948,17 @@ loop: } } if isSortkey(key) { + + // we dont support variable + predicate sorting + for _, order := range gq.Order { + for _, needVar := range gq.NeedsVar { + if needVar.Name == order.Attr { + return nil, it.Errorf("Val() is not allowed in multiple sorting."+ + " Got: [%v]", needVar.Name) + } + } + } + if order[val] { return nil, it.Errorf("Sorting by an attribute: [%s] can only be done once", val) } diff --git a/ee/acl/acl_test.go b/ee/acl/acl_test.go index 533b813a3ba..f5cbee348eb 100644 --- a/ee/acl/acl_test.go +++ b/ee/acl/acl_test.go @@ -1433,7 +1433,7 @@ func (asuite *AclTestSuite) TestValQueryWithACLPermissions() { n as name a as age } - q2(func: uid(f), orderdesc: val(a), orderasc: name) { + q2(func: uid(f), orderdesc: val(a)) { name val(n) val(a) diff --git a/query/query4_test.go b/query/query4_test.go index 93e85faad6a..80f5f7cedbe 100644 --- a/query/query4_test.go +++ b/query/query4_test.go @@ -1850,3 +1850,64 @@ func TestBigFloatConnectingFilters(t *testing.T) { expectedRes := `{"data":{"me":[{"uid":"0x666"}]}}` require.JSONEq(t, js, expectedRes) } + +func TestMultiplesSortingOrderWithVarAndPredicate(t *testing.T) { + s1 := testSchema + "\n" + `type Hostel { + hosteslName: String! + sections + } + + type Section { + section_id + hostel + } + hosteslName: string @index(exact) . + section_id: string @index(exact) . + sections: [uid] @count . + hostel:uid .` + "\n" + + setSchema(s1) + triples := ` + _:hostel1 "Hostel Alpha" . + _:hostel1 _:section1 . + _:hostel1 _:section2 . + + _:section1 "S1" . + _:section2 "S2" . + + _:hostel2 "Hostel Beta" . + _:hostel2 _:section3 . + + _:section3 "S3" . + + _:hostel3 "Hostel Gamma" . + _:hostel3 _:section4 . + _:hostel3 _:section5 . + _:hostel3 _:section6 . + + _:section4 "S4" . + _:section5 "S5" . + _:section6 "S6" . + ` + addTriplesToCluster(triples) + + query := `{ + var(func: has(name)) { + SECTIONS_COUNT as count(sections) + } + + allHostels(func: has(name), orderdesc: + val(SECTIONS_COUNT), orderasc: name) { + uid + name + sections { + section_id + } + totalSections: val(SECTIONS_COUNT) + } + }` + + // should return error + _, err := processQuery(context.Background(), t, query) + require.ErrorContains(t, err, "Val() is not allowed in multiple sorting. Got: [SECTIONS_COUNT]") +}