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

Add support for multiple uids in uid_in function #5292

Merged
merged 20 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 3 additions & 0 deletions gql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,9 @@ L:
case IsInequalityFn(function.Name):
err = parseIneqArgs(it, function)

case function.Name == "uid_in":
err = parseIneqArgs(it, function)

default:
err = itemInFunc.Errorf("Unexpected character [ while parsing request.")
}
Expand Down
27 changes: 15 additions & 12 deletions worker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ func (qs *queryState) handleUidPostings(
}
var key []byte
switch srcFn.fnType {
//Check with pawan/ashish if this needs any changes
case notAFunction, compareScalarFn, hasFn, uidInFn:
if q.Reverse {
key = x.ReverseKey(q.Attr, q.UidList.Uids[i])
Expand Down Expand Up @@ -757,11 +758,12 @@ func (qs *queryState) handleUidPostings(
tlist := &pb.List{Uids: []uint64{q.UidList.Uids[i]}}
out.UidMatrix = append(out.UidMatrix, tlist)
}
//Check with Pawan/Ashish what this function do? I suppose itreturns the relevant posting/uid list to append to uid matrix
case srcFn.fnType == uidInFn:
if i == 0 {
span.Annotate(nil, "UidInFn")
span.Annotate(nil, "UidInFn") //Check with Pawan/Ashish what does this do?
}
reqList := &pb.List{Uids: []uint64{srcFn.uidPresent}}
reqList := &pb.List{Uids: srcFn.uidsPresent}
topts := posting.ListOptions{
ReadTs: args.q.ReadTs,
AfterUid: 0,
Expand Down Expand Up @@ -1583,7 +1585,7 @@ type functionContext struct {
ineqValueToken string
n int
threshold int64
uidPresent uint64
uidsPresent []uint64
fname string
fnType FuncType
regex *cregexp.Regexp
Expand Down Expand Up @@ -1816,16 +1818,17 @@ func parseSrcFn(ctx context.Context, q *pb.Query) (*functionContext, error) {
}
checkRoot(q, fc)
case uidInFn:
if err = ensureArgsCount(q.SrcFunc, 1); err != nil {
return nil, err
}
fc.uidPresent, err = strconv.ParseUint(q.SrcFunc.Args[0], 0, 64)
if err != nil {
if e, ok := err.(*strconv.NumError); ok && e.Err == strconv.ErrSyntax {
return nil, errors.Errorf("Value %q in %s is not a number",
q.SrcFunc.Args[0], q.SrcFunc.Name)
//TODO (Anurag) Implement an argsCount for min 1 argument
for _, arg := range q.SrcFunc.Args {
uidParsed, err := strconv.ParseUint(arg, 0, 64)
if err != nil {
if e, ok := err.(*strconv.NumError); ok && e.Err == strconv.ErrSyntax {
return nil, errors.Errorf("Value %q in %s is not a number",
arg, q.SrcFunc.Name)
}
return nil, err
}
return nil, err
fc.uidsPresent = append(fc.uidsPresent, uidParsed)
}
checkRoot(q, fc)
if fc.isFuncAtRoot {
Expand Down