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

(fix/dgraph): (Cherrypick-v20.07) Fix facets response with normalize (#5690) #5910

Merged
merged 3 commits into from
Jul 10, 2020

Conversation

ashish-goswami
Copy link
Contributor

@ashish-goswami ashish-goswami commented Jul 9, 2020

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 Reviewable

Docs Preview: Dgraph Preview

Copy link
Contributor

@harshil-goel harshil-goel left a 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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @pawanrawal)

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)
@ashish-goswami ashish-goswami force-pushed the ashish/v20.07-normalize branch from be77f74 to d260053 Compare July 10, 2020 15:02
@parasssh parasssh merged commit c6de96c into release/v20.07 Jul 10, 2020
@NamanJain8 NamanJain8 deleted the ashish/v20.07-normalize branch May 20, 2021 08:11
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.

3 participants