-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(Query): Support variables inside uid_in function #5320
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichelDiz No, currently it will only support one variable inside uid function. I have added tests (TestUidInWithErrors) specifically which checks the behavior which you asked for and throw an error. I have added a TODO to look into this later.
@jarifibrahim Added tests and description.
Reviewable status: 0 of 3 files reviewed, 3 unresolved discussions (waiting on @manishrjain, @martinmr, @parasssh, @pawanrawal, and @vvbalaji-dgraph)
gql/parser.go, line 1728 at r1 (raw file):
Previously, martinmr (Martin Martinez Rivera) wrote…
needs test at the parser level as well.
Yes, have added more tests and edge case handling to prevent panics.
query/query.go, line 1658 at r1 (raw file):
Previously, martinmr (Martin Martinez Rivera) wrote…
I think you can remove this special logic and simplify. Simply create a new array to store the args and set sg.SrcFunc.Args to point to that array after the for loop. That way the first item doesn't have to be handled differently.
Done.
query/query.go, line 1659 at r1 (raw file):
Previously, parasssh wrote…
add comment about the base 10.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you estimate how much additional work is it for the request by @MichelDiz above? Also, run this by Pawan. Add / Move UT to the parser_test.go.
Reviewable status: 0 of 4 files reviewed, 3 unresolved discussions (waiting on @manishrjain, @martinmr, @parasssh, @pawanrawal, and @vvbalaji-dgraph)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to do what @MichelDiz suggested but it probably should be done in another PR.
I added some comments but they are all related to the tests. Once those are fixed it .
Reviewed 4 of 4 files at r2.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @anurags92, @manishrjain, @parasssh, @pawanrawal, and @vvbalaji-dgraph)
query/query1_test.go, line 1142 at r2 (raw file):
}, { description: "query with uid variable where school uid for <31> is <5001> and <25> is <5000>",
the description should be more general. Don't mention specific uids. It should say what general case is being tested.
Same for the other tests that contain specific numbers.
The descriptions of the tests in TestUidInWithErrors are good examples.
query/query1_test.go, line 1179 at r2 (raw file):
} } func TestUidInWithErrors(t *testing.T) {
All these are parser tests so they should be moved there.
Also, the parser test should include tests to verify valid queries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @manishrjain, @martinmr, @parasssh, @pawanrawal, and @vvbalaji-dgraph)
query/query1_test.go, line 1142 at r2 (raw file):
Previously, martinmr (Martin Martinez Rivera) wrote…
the description should be more general. Don't mention specific uids. It should say what general case is being tested.
Same for the other tests that contain specific numbers.The descriptions of the tests in TestUidInWithErrors are good examples.
Done.
query/query1_test.go, line 1179 at r2 (raw file):
Previously, martinmr (Martin Martinez Rivera) wrote…
All these are parser tests so they should be moved there.
Also, the parser test should include tests to verify valid queries.
Moved the TestUidInWithErrors to parser_test.go
For the second point -- wouldn't the working queries be sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @manishrjain, @martinmr, @parasssh, @pawanrawal, and @vvbalaji-dgraph)
…work after this feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 4 files at r2, 2 of 2 files at r3.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @anurags92, @manishrjain, @martinmr, @parasssh, and @vvbalaji-dgraph)
gql/parser_test.go, line 4920 at r3 (raw file):
query: `{ me(func: uid(1, 23, 24 )) { friend @filter(uid_in(school, uid(5000))) {
Its a bit weird that we don't support this case as it's the same as
friend @filter(uid_in(school, 5000))
We support passing a constant uid using the uid function at other places.
Should we support it?
query/query.go, line 1659 at r3 (raw file):
srcFuncArgs := sg.SrcFunc.Args[:0] if l.Uids != nil { for _, uid := range l.Uids.Uids {
Could you just range over using l.Uids.GetUids() without checking l.Uids != nil as it takes care of nil
query/query.go, line 1663 at r3 (raw file):
arg := gql.Arg{ Value: strconv.FormatUint(uid, 10), IsValueVar: false,
Don't need to pass in false values, they are the default.
query/query1_test.go, line 1061 at r3 (raw file):
description: "query at top level with nested UID variable", query: `{ uidVar as q(func: uid(5001, 5000))
This can be a var query so that its not returned in the results.
query/query1_test.go, line 1142 at r3 (raw file):
}, { description: "query inside root with nested uid variable uid variable which resolves to two uids",
extra uid variable can be removed
query/query1_test.go, line 1192 at r3 (raw file):
} }` expectedErr := errors.New("rpc error: code = Unknown desc = : Function 'uid_in' requires atleast 1 argument, but got 0 ([])")
hmm, this shouldn't be a runtime error, if the uid variable returns a null set we should just consider the intersection to be []. It would be weird if for the user some of the queries failed and some passed depending on which node they were starting with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @manishrjain, @martinmr, @parasssh, @pawanrawal, and @vvbalaji-dgraph)
gql/parser_test.go, line 4920 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Its a bit weird that we don't support this case as it's the same as
friend @filter(uid_in(school, 5000))We support passing a constant uid using the
uidfunction at other places.
Should we support it?
Will create a JIRA to extend support.
query/query.go, line 1659 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Could you just range over using
l.Uids.GetUids()without checkingl.Uids != nilas it takes care of nil
Okay, thanks. Didnt know that.
query/query.go, line 1663 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Don't need to pass in false values, they are the default.
Cool, makes sense.
query/query1_test.go, line 1061 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
This can be a
varquery so that its not returned in the results.
Yes, thanks for pointing this out.
query/query1_test.go, line 1142 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
extra uid variable can be removed
Ok.
query/query1_test.go, line 1192 at r3 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
hmm, this shouldn't be a runtime error, if the uid variable returns a null set we should just consider the intersection to be
[]. It would be weird if for the user some of the queries failed and some passed depending on which node they were starting with.
Agree, need to be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 5 files reviewed, 11 unresolved discussions (waiting on @jarifibrahim, @manishrjain, @martinmr, @parasssh, @pawanrawal, and @vvbalaji-dgraph)
gql/parser.go, line 1745 at r4 (raw file):
function.Args = append(function.Args, Arg{Value: nestedFunc.NeedsVar[0].Name}) default: return nil, itemInFunc.Errorf("Only val/count/len/uid allowed as function "+
Created a JIRA ticket since this change might allow nested uid inside other functions too. https://dgraph.atlassian.net/browse/DGRAPH-1918
gql/parser_test.go, line 4920 at r3 (raw file):
friend @filter(uid_in(school, 5000))
This JIRA ticket should be able to handle the above requirement. https://dgraph.atlassian.net/browse/DGRAPH-1919
gql/parser_test.go, line 4349 at r4 (raw file):
} func TestEqUidFunctionErr(t *testing.T) {
This JIRA ticket should investigate this: https://dgraph.atlassian.net/browse/DGRAPH-1918
query/query.go, line 1659 at r3 (raw file):
Previously, anurags92 (Anurag) wrote…
Okay, thanks. Didnt know that.
Done.Done
query/query.go, line 1663 at r3 (raw file):
Previously, anurags92 (Anurag) wrote…
Cool, makes sense.
Done.
query/query1_test.go, line 1061 at r3 (raw file):
Previously, anurags92 (Anurag) wrote…
Yes, thanks for pointing this out.
Done.
query/query1_test.go, line 1192 at r3 (raw file):
Previously, anurags92 (Anurag) wrote…
Agree, need to be changed.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 4 files at r4, 4 of 4 files at r5.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @jarifibrahim, @manishrjain, @martinmr, @parasssh, @pawanrawal, and @vvbalaji-dgraph)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 3 of 5 files reviewed, 5 unresolved discussions (waiting on @jarifibrahim, @manishrjain, @martinmr, @parasssh, @pawanrawal, and @vvbalaji-dgraph)
gql/parser_test.go, line 4920 at r3 (raw file):
Previously, anurags92 (Anurag) wrote…
friend @filter(uid_in(school, 5000))
This JIRA ticket should be able to handle the above requirement. https://dgraph.atlassian.net/browse/DGRAPH-1919
Done.
gql/parser_test.go, line 4349 at r4 (raw file):
Previously, anurags92 (Anurag) wrote…
This JIRA ticket should investigate this: https://dgraph.atlassian.net/browse/DGRAPH-1918
Done.
query/query1_test.go, line 1179 at r2 (raw file):
Previously, anurags92 (Anurag) wrote…
Moved the TestUidInWithErrors to parser_test.go
For the second point -- wouldn't the working queries be sufficient?
Done.
Motivation
This PR adds support for queries which use variable inside
uid_infunction:Components affected by this PR
Nested
uid_infunction calls.Does this PR break backwards compatibility?
No.
Testing
Added following tests in
query1_test.go:uid_intests to work with variablesTestUidInWithParseErrorsto check that program gracefully returns error in case of malformed input and does not crashFixes
Fixes DGRAPH-549
Fixes #3066
This change is
Docs Preview: