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(DQL): unsupported ordering should raise an error #9173

Merged
merged 1 commit into from
Sep 19, 2024
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
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) {
shivaji-kharse marked this conversation as resolved.
Show resolved Hide resolved
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]")
}
Loading