(fix/dgraph): (Cherrypick-v20.07) Fix facets response with normalize (#5690) #5910
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #5241
Fixes: DGRAPH-1670
This PR fixes issue with facets when it is retrieved in a query containing @normalize directive.
While forming @normalize response, we flatten a fastJsonNode and make its grand children,
direct children of it. This should be valid in all of cases except when fastJsonNode is parent of
facets nodes. For example consider below data:
<0x1> "Alice" .
<0x1> "Bob" (from="college") .
<0x1> "Roman" (from="school") .
Also consider below query:
q(func: uid(0x1)) @normalize {
name: name
friend: friends @facets
}
Expected response is:
{
"data": {
"q": [
{
"name": "Alice",
"friends|from": {
"0": "college",
"1": "school"
},
"friends": [
"Bob",
"Roman"
]
}
]
}
}
But actual response is:
{
"data": {
"q": [
{
"0": "college",
"1": "school",
"friends": [
"Bob",
"Roman"
],
"name": "Alice"
}
]
}
}
Its happening because we are flattening facet parent node friends|from as well which have node
"0" and "1" as children.
We are solving it by having extra information in the node if it is a facets parent.
(cherry picked from commit f4c28b8)
This change is
Docs Preview: