Skip to content

Commit

Permalink
fix(worker): fix eq filter for non-index predicates. (#6986) (#6988)
Browse files Browse the repository at this point in the history
* fix eq function with non indexed predicate

* remove tests for between function

(cherry picked from commit 54ef639)

Co-authored-by: minhaj-shakeel <[email protected]>
  • Loading branch information
OmarAyo and minhaj-shakeel authored Nov 25, 2020
1 parent 69a002e commit 4624bdd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
24 changes: 24 additions & 0 deletions query/query0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2908,6 +2908,30 @@ func TestFilterNonIndexedPredicate(t *testing.T) {
}
}

func TestEqFilterWithoutIndex(t *testing.T) {
test := struct {
name string
query string
result string
}{
`Test eq filter on Non Indexed Predicate`,
`
{
me(func: type(CarModel)) @filter(eq(year,2008,2009)){
make
model
year
}
}
`,
`{"data":{"me":[{"make":"Ford","model":"Focus","year":2008},{"make":"Ford","model":"Focus","year":2009},{"make":"Toyota","model":"Prius","year":2009}]}}`,
}

js := processQueryNoErr(t, test.query)
require.JSONEq(t, js, test.result)

}

var client *dgo.Dgraph

func TestMain(m *testing.M) {
Expand Down
16 changes: 13 additions & 3 deletions worker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,20 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
if val, err = types.Convert(val, srcFn.atype); err != nil {
return err
}
if types.CompareVals(srcFn.fname, val, srcFn.ineqValue) {
uidList.Uids = append(uidList.Uids, q.UidList.Uids[i])
break
switch srcFn.fname {
case "eq":
for _, eqToken := range srcFn.eqTokens {
if types.CompareVals(srcFn.fname, val, eqToken) {
uidList.Uids = append(uidList.Uids, q.UidList.Uids[i])
break
}
}
default:
if types.CompareVals(srcFn.fname, val, srcFn.eqTokens[0]) {
uidList.Uids = append(uidList.Uids, q.UidList.Uids[i])
}
}

} else {
vl.Values = append(vl.Values, newValue)
}
Expand Down

0 comments on commit 4624bdd

Please sign in to comment.