Skip to content

@normalize does not flatten always #4198

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

Closed
sayeed-anjum opened this issue Oct 20, 2019 · 5 comments
Closed

@normalize does not flatten always #4198

sayeed-anjum opened this issue Oct 20, 2019 · 5 comments
Labels
area/querylang/normalize Related to the normalize directive. area/querylang Issues related to the query language specification and implementation. kind/bug Something is broken. status/accepted We accept to investigate/work on it.

Comments

@sayeed-anjum
Copy link

#3751 # What version of Dgraph are you using?

v1.1.0

Have you tried reproducing the issue with the latest release?

NA

What is the hardware spec (RAM, OS)?

MacOS 10.14.6, 16 GB

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

{
  logs(func: uid(0x50)) @normalize {
    userId: uid
    logs: ~log_for(orderdesc: created) {
        logId: uid
        title: title
        createdOn: created
        type_of {
          	typeId: uid                                 
        }
    }
  }
}

Expected behaviour

{
  "data": {
    "logs": [
      {
        "createdOn": "2019-10-20T16:26:12.206897Z",
        "logId": "0x51",
        "title": "normalize does not flatten",
        "typeId": "0x4d"
        "userId": "0x50"
      }
    ]
  }
}

actual result.

{
  "data": {
    "logs": [
      {
        "createdOn": "2019-10-20T16:26:12.206897Z",
        "logId": "0x51",
        "title": "normalize does not flatten",
        "type_of": {
          "typeId": "0x4d"
        },
        "userId": "0x50"
      }
    ]
  }
}

The @normalize clause was working fine when I was using the following declaration:

type_of: [uid] @reverse .

It stopped working when I changed it to:

type_of: uid @reverse .
@MichelDiz
Copy link
Contributor

I can't reproduce it in master. So probably it is fixed if it was something. Also, there have been some changes recently in @normalize.

Dgraph version   : 
Dgraph SHA-256   : e15cdaa38af3866ceb56d4b99e46fca946a7d915cb8fef8a089547ba560bee5d
Commit SHA-1     : 
Commit timestamp : 
Branch           : 
Go version       : go1.13.3
<log_for>: uid @reverse .
<type_of>: [uid] .
<title>: string .
<created>: string .
{
    "set": [{
        "created": "2019-10-20T16:26:12.206897Z",
        "title": "normalize does not flatten",
        "log_for": {
         "user": ""
        },
        "type_of": {
         "type": "test"
        }
      }
    ]
  }
{
  logs(func: has(~log_for)) @normalize {
    userId: uid
    logs: ~log_for {
        logId: uid
        title: title
        createdOn: created
        type_of {
          	typeId: uid                  
        }
    }
  }
}

Result

{
  "data": {
    "logs": [
      {
        "createdOn": "2019-10-20T16:26:12.206897Z",
        "logId": "0x7535",
        "title": "normalize does not flatten",
        "typeId": "0x7537",
        "userId": "0x7536"
      }
    ]
  }

@sayeed-anjum
Copy link
Author

@MichelDiz Did you also try with the declaration:

<log_for>: uid @reverse .
<type_of>: uid .
<title>: string .
<created>: string .

plain uid instead of [uid] for type_of predicate.

@MichelDiz
Copy link
Contributor

Yep, same response, no issues.
Captura de Tela 2019-10-20 às 21 58 54

@danielmai
Copy link
Contributor

danielmai commented Oct 21, 2019

This is reproducible on v1.1.0, and not on master. As @asa511 reported, this happens with predicates with the one-to-one uid schema type.

Steps to reproduce the issue:

  1. Run fresh Dgraph cluster.

  2. Set the following schema with a uid predicate:

    name: string @index(hash) .
    friend: uid .
    
  3. Set the following mutation, which connects two nodes to each other using the friend predicate:

    [
      {
        "uid": "_:p1",
        "name": "p1",
        "friend": {
          "uid": "_:p2"
        }
      },
      {
        "uid": "_:p2",
        "name": "p2",
        "friend": {
          "uid": "_:p1"
        }
      }
    ]
    
  4. Run the following query:

    {
      everyone(func: eq(name, "p1")) @normalize {
        name1: name
        friend {
          name2: name
        }
      }
    }
    

    Response:

    {
      "data": {
        "everyone": [
          {
            "name1": "p1",
            "friend": {
              "name2": "p2"
            }
          }
        ]
      }
    }
    

    name1 and name2 should be in the same level without the "friend" key in the response.

Steps to get expected response

  1. To reproduce the expected response, re-do the steps but set the schema
    type for friend predicate [uid].

    Schema:

    name: string @index(hash) .
    friend: [uid] .
    

    Mutation:

    [
      {
        "uid": "_:p1",
        "name": "p1",
        "friend": {
          "uid": "_:p2"
        }
      },
      {
        "uid": "_:p2",
        "name": "p2",
        "friend": {
          "uid": "_:p1"
        }
      }
    ]
    

    Query:

    {
      everyone(func: eq(name, "p1")) @normalize {
        name1: name
        friend {
          name2: name
        }
      }
    }
    

    Response:

    {
      "data": {
        "everyone": [
          {
            "name1": "p1",
            "name2": "p2"
          }
        ]
      }
    }
    

@danielmai danielmai added area/querylang Issues related to the query language specification and implementation. area/querylang/normalize Related to the normalize directive. kind/bug Something is broken. status/accepted We accept to investigate/work on it. labels Oct 21, 2019
@danielmai
Copy link
Contributor

I'll close this issue since this is fixed in master. The next Dgraph release will contain the fix. For now, you can use the master version as of #4042 if you need this fix. We can also cut a release-candidate version for you if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/querylang/normalize Related to the normalize directive. area/querylang Issues related to the query language specification and implementation. kind/bug Something is broken. status/accepted We accept to investigate/work on it.
Development

No branches or pull requests

3 participants