-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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/dgraph): Fix facets response with normalize #5690
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.
Reviewed 2 of 2 files at r1.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ashish-goswami)
query/outputnode.go, line 169 at r1 (raw file):
// 3. List => Stores boolean value, true if this node is part of list. // 4. FacetsParent => Stores boolean value, true if this node is a facetsParent. facetsParent is // node which is parent for facets values for a scalar list predicaite. Eg: node "country|city"
city|country
predicate
query/outputnode.go, line 662 at r1 (raw file):
// Here we are counting all non-scalar attributes of fj. If there are any such // attributes, we will flatten it, otherwise we will return all attributes. // We should only consider those nodes for falttening which have children and are not
flatenning
query/query_facets_test.go, line 2118 at r1 (raw file):
} func TestFacetValueListPredicateWithNormalize(t *testing.T) {
TestFacetValuePredicateWithNormalize
query/query_facets_test.go, line 2121 at r1 (raw file):
populateClusterWithFacets() query := `{ q(func: uid(1, 12000)) @normalize {
Also add a test where value is nested like
func: uid(1, 12000) @normalize {
name
friends {
name @facets
}
}
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, 5 unresolved discussions (waiting on @ashish-goswami)
query/outputnode.go, line 263 at r1 (raw file):
(
I don't think you need the outer parenteses
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.
lgtm. Thanks for adding the tests
Fixes: #5241 Fixes: DGRAPH-1670 This PR is related to #5690. It issues with facets response when facets are retrieved with @normalize directive. Below two cases are covered: Fixing facets response with uid/uid list predicates. Fixing facets response with scalard list predicates.
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> <name> "Alice" . <0x1> <friend> "Bob" (from="college") . <0x1> <friend> "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)
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> <name> "Alice" . <0x1> <friend> "Bob" (from="college") . <0x1> <friend> "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)
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> <name> "Alice" . <0x1> <friend> "Bob" (from="college") . <0x1> <friend> "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)
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> <name> "Alice" . <0x1> <friend> "Bob" (from="college") . <0x1> <friend> "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.
Fixes: dgraph-io#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> <name> "Alice" . <0x1> <friend> "Bob" (from="college") . <0x1> <friend> "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.
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 afastJsonNode
and make its grand children,direct children of it. This should be valid in all of cases except when
fastJsonNode
is parent offacets nodes. For example consider below data:
Also consider below query:
Expected response is:
But actual response is:
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
.This change is
Docs Preview: