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

GroupBy uid shouldn't panic, and other logic fixes. #2952

Merged
merged 6 commits into from
Feb 2, 2019

Conversation

srfrog
Copy link
Contributor

@srfrog srfrog commented Jan 30, 2019

This PR fixes an issue with queries using @groupby(uid) directive that would cause Alpha to panic.

  1. The @groupby panic was due to the fact that we don't create tasks for children subgraphs using uid as attribute. Therefore, we don't generate DestUIDs list for them. When the groupby is processed the field is nil and we panic when it tries to access the uids from that list.
  • I have added an extra check that DestUIDs isn't nil. This will move the result list to use SrcUIDs instead which is expected.
  • No breaking changes expected from this change.

Closes #2936


This change is Reviewable

Copy link
Contributor

@codexnull codexnull left a 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 4 files reviewed, 1 unresolved discussion (waiting on @srfrog)


query/groupby.go, line 222 at r1 (raw file):

				srcUid := child.SrcUIDs.Uids[i]
				// Ignore uids which are not part of srcUid.
				if algo.IndexOf(ul, srcUid) == -1 {

Am I missing something or is this change is a no-op? algo.IndexOf() returns an index 0..n if found, -1 otherwise. If not found, both -1 < 0 and -1 == -1 evaluate to TRUE. If found at position 0, both 0 < 0 and 0 == -1 evaluate to FALSE.

In that case, I think the original test is better since it would continue working if IndexOf() were to return other error codes in the future.

Copy link
Contributor Author

@srfrog srfrog left a 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 4 files reviewed, 1 unresolved discussion (waiting on @codexnull)


query/groupby.go, line 222 at r1 (raw file):

Previously, codexnull (Javier Alvarado) wrote…

Am I missing something or is this change is a no-op? algo.IndexOf() returns an index 0..n if found, -1 otherwise. If not found, both -1 < 0 and -1 == -1 evaluate to TRUE. If found at position 0, both 0 < 0 and 0 == -1 evaluate to FALSE.

In that case, I think the original test is better since it would continue working if IndexOf() were to return other error codes in the future.

Maybe, but the issue is that 0 is a valid index value and the test ignores it. If we actually return -2, for example, then we would have to consider all test cases individually.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Reviewable status: 0 of 4 files reviewed, 1 unresolved discussion (waiting on @codexnull)


query/groupby.go, line 222 at r1 (raw file):

Previously, srfrog (Gus) wrote…

Maybe, but the issue is that 0 is a valid index value and the test ignores it. If we actually return -2, for example, then we would have to consider all test cases individually.

Agree with @codexnull . Looks like a no-op. Here and elsewhere. All negative values should be treated as index not found.

Copy link
Contributor Author

@srfrog srfrog left a 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 3 files reviewed, 1 unresolved discussion (waiting on @codexnull)


query/groupby.go, line 222 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Agree with @codexnull . Looks like a no-op. Here and elsewhere. All negative values should be treated as index not found.

Done.

Copy link
Contributor

@codexnull codexnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 0 of 3 files reviewed, all discussions resolved

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 4 files at r1, 2 of 3 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@srfrog srfrog merged commit 2b943ca into master Feb 2, 2019
@srfrog srfrog deleted the srfrog/issue-2936_query_groupby_uid_causes_panic branch February 2, 2019 03:51
@danielmai danielmai mentioned this pull request Mar 29, 2019
dna2github pushed a commit to dna2fork/dgraph that referenced this pull request Jul 19, 2019
* added check for nil destuid in child sg. also fixed a couple of logic bugs.

* fixed another logic bug related to algo.IndexOf

* fixed logic bug, made algo.ApplyFilter clearer, and simplified appendDummyValues a bit.

* added tests

* change algo.IndexOf to less explicit form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Query with @groupby(uid) causes Alpha to panic
3 participants