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

@normalize broken for >=v1.2.0 when using @facets #5241

Closed
dkjii-g opened this issue Apr 19, 2020 · 1 comment · Fixed by #5690
Closed

@normalize broken for >=v1.2.0 when using @facets #5241

dkjii-g opened this issue Apr 19, 2020 · 1 comment · Fixed by #5690
Labels
area/facets Issues related to face handling, querying, etc. kind/bug Something is broken. status/accepted We accept to investigate/work on it.

Comments

@dkjii-g
Copy link

dkjii-g commented Apr 19, 2020

Description

@facets used to work when being normalized, but v1.2.0 introduced some nesting behavior, which gives a weird result when using @normalize with @facets

What version of Dgraph are you using?

v1.2.0

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, OS)?

4G, Linux

Steps to reproduce the issue (command/config used to run Dgraph).

Go to https://dgraph.io/docs/query-language/#facets-on-scalar-predicates
Try this query:

curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d '
{
   data(func: eq(name, "Alice")) @normalize {
     name: name
     friend @facets(close) {
       nameTo: name
     }
   }
}' | python -m json.tool | less

in the facets playground
Result:

{
  "data": {
    "data": [
      {
        "0": true,
        "1": false,
        "2": true,
        "name": "Alice",
        "nameTo": "Bob"
      },
      {
        "0": true,
        "1": false,
        "2": true,
        "name": "Alice",
        "nameTo": "Charlie"
      },
      {
        "0": true,
        "1": false,
        "2": true,
        "name": "Alice",
        "nameTo": "Dave"
      }
    ]
  }
}

Expected behaviour and actual result.

This is what used to happen on v1.1.1:

{
  "data": {
    "data": [
      {
       "friend|close": true,
        "name": "Alice",
        "nameTo": "Bob"
      },
      {
       "friend|close": false,
        "name": "Alice",
        "nameTo": "Charlie"
      },
      {
       "friend|close": true,
        "name": "Alice",
        "nameTo": "Dave"
      }
    ]
  }
}
@MichelDiz MichelDiz added area/facets Issues related to face handling, querying, etc. kind/bug Something is broken. labels Apr 20, 2020
@MichelDiz
Copy link
Contributor

@ashish-goswami this is related to #4907

@lgalatin lgalatin added the status/accepted We accept to investigate/work on it. label Jun 9, 2020
ashish-goswami added a commit that referenced this issue Jul 9, 2020
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.
ashish-goswami added a commit that referenced this issue 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> <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.
ashish-goswami added a commit that referenced this issue 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> <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 added a commit that referenced this issue Jul 10, 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> <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)
parasssh pushed a commit that referenced this issue Jul 10, 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> <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)
arijitAD pushed a commit that referenced this issue Jul 14, 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> <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.
dna2github pushed a commit to dna2fork/dgraph that referenced this issue Jul 18, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/facets Issues related to face handling, querying, etc. kind/bug Something is broken. status/accepted We accept to investigate/work on it.
Development

Successfully merging a pull request may close this issue.

3 participants