-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(Mutation): Deeply-nested uid facets #7455
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(Mutation): Deeply-nested uid facets #7455
Conversation
|
Hello, I'm looking into this. Just leaving some notes here.
|
|
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 2 files at r3, 2 of 2 files at r4.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @karlmcguire and @nelsonpecora)
go.mod, line 17 at r4 (raw file):
github.com/blevesearch/bleve v1.0.13 github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd github.com/davecgh/go-spew v1.1.1
What's go-spew? I don't see it used in this PR, so why is this dependency added?
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, 1 unresolved discussion (waiting on @karlmcguire and @nelsonpecora)
go.mod, line 17 at r4 (raw file):
Previously, danielmai (Daniel Mai) wrote…
What's go-spew? I don't see it used in this PR, so why is this dependency added?
Nevermind, I see you're using it for debugging.
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: 2 of 4 files reviewed, all discussions resolved (waiting on @danielmai and @karlmcguire)
* only run `parseMapFacets` for JSON scalar arrays (cherry picked from commit 5049092)
Between v20.03 and v20.11 (with #5424), dgraph lost the ability to handle deeply-nested uid facets. A JSON mutation with non-nested uid facets looks like this:
{ "set": [{ "title": "parent", "children": [{ "title": "child", "children|position": 1 }] }] }A mutation with deeply-nested uid facets looks like this:
{ "set": [{ "title": "parent", "children": [{ "title": "child", "children|position": 1, "children": [{ "title": "grandchild", "children|position": 1 }] }] }] }There's something about trying to set both
childrenandchildren|positionon the same JSON object that's causing it to error. The equivalent mutation in RDF succeeds:Fix(karl): The short explanation is there was an old TODO mentioning that we should only run
parseMapFacetsif we are within a JSON scalar array, but we were running it from within JSON object arrays as well. Only running it from within JSON scalar arrays fixed the issue.Longer explanation: By calling
parseMapFacetsfrom within a JSON object array, the"friend|close": truefacet was correctly assumed to have an object (map) value rather than its scalar value, and this error was returned.The reason
"another_friend|close": trueworked despite this is becauseparseScalarMaplooks for facets on the same level as the predicate. For example, here's how map facets should look:{ "nickname": ["alice", "bob", "josh"], "nickname|kind": { "0": "friends", "2": "official" } }So in the working
another_friendexample,parseMapFacetsis called two times (once for each named JSON array declaration):parseMapFacets(map[string]interface{}{}, "friend|")mapToNquadsencounters"friend": [on the current level and callsparseMapFacetswith all facets found on the current level (none) and"friend" + "|"as theprefixparameter.mis empty andparseMapFacetsreturnsnil.parseMapFacets(map[string]interface{}{"friend|close": true}, "another_friend|")mapToNquadsencounters"another_friend": [on the current level and callsparseMapFacetswith all facets found on the current level and"another_friend" + "|"as theprefixparameter.prefix(in this case,another_friend|) is in the facet name (in this case,friend|close) andparseMapFacetsreturnsnil.So
parseMapFacetsis only called two times, both times returningnil, and we pick up the facets withparseScalarFacetslater.With this PR fix, we only call
parseMapFacetsfor JSON scalar arrays and avoid everything mentioned above.This change is