Skip to content

Commit

Permalink
fix sorting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaji-kharse committed Sep 19, 2024
1 parent 0ae4fc8 commit 73e700f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
11 changes: 11 additions & 0 deletions dql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion ee/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
61 changes: 61 additions & 0 deletions query/query4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> "Hostel Alpha" .
_:hostel1 <sections> _:section1 .
_:hostel1 <sections> _:section2 .
_:section1 <section_id> "S1" .
_:section2 <section_id> "S2" .
_:hostel2 <name> "Hostel Beta" .
_:hostel2 <sections> _:section3 .
_:section3 <section_id> "S3" .
_:hostel3 <name> "Hostel Gamma" .
_:hostel3 <sections> _:section4 .
_:hostel3 <sections> _:section5 .
_:hostel3 <sections> _:section6 .
_:section4 <section_id> "S4" .
_:section5 <section_id> "S5" .
_:section6 <section_id> "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]")
}

0 comments on commit 73e700f

Please sign in to comment.