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

@recurse query not fetching entire subgraph from root node #2555

Closed
danielmai opened this issue Aug 28, 2018 · 6 comments
Closed

@recurse query not fetching entire subgraph from root node #2555

danielmai opened this issue Aug 28, 2018 · 6 comments
Labels
kind/bug Something is broken.

Comments

@danielmai
Copy link
Contributor

Bug report

This issue comes from https://discuss.dgraph.io/t/modeling-a-tree-and-getting-a-subtree-from-a-node/3087.

Desktop:

  • OS: macOS High Sierra 10.13.6 (Running Dgraph via Docker)
  • Browser: Chrome
  • Dgraph Version: v1.0.7
  • Dgraph Client: Ratel/curl HTTP

Containerization:

  • Main Container Software: Docker v18.06.0-ce
  • Integration (if applicable): Docker for Mac
  • Dgraph TAG Version: v1.0.7

Describe the bug:

Running a query with @recurse doesn't return the expected subgraph results.

Steps to reproduce the behavior:

  1. Start a new Dgraph (1 Zero, 1 Server) running with default ports accessible via localhost.

  2. Run the following mutation:

    curl -i -XPOST -H 'X-Dgraph-CommitNow: true' -H 'X-Dgraph-MutationType: json' http://localhost:8080/mutate -d '{
      "set": [
        {
          "jungle": {
            "animals": {
              "lion": {
                "name": "Simba"
              },
              "elephant": {
                "name": "Ele"
              }
            },
            "birds":{
              "parrot": {
                "name": "Zuzu"
              },
              "chicken": {
                "name": "Chica"
              }
            }
          }
        }
      ]
    }'
    

    Response:

    {
      "data": {
        "code": "Success",
        "message": "Done",
        "uids": {
          "blank-0": "0x40",
          "blank-1": "0x39",
          "blank-2": "0x3a",
          "blank-3": "0x3b",
          "blank-4": "0x3c",
          "blank-5": "0x3d",
          "blank-6": "0x3e",
          "blank-7": "0x3f"
        }
      },
      "extensions": {
        "server_latency": {
          "parsing_ns": 21640,
          "processing_ns": 10257181
        },
        "txn": {
          "start_ts": 47,
          "commit_ts": 48,
          "lin_read": {
            "ids": {
              "1": 71
            }
          }
        }
      }
    }
  3. Run this query to double-check that the data mutation inserted the data as we expected:

    $ curl -s -XPOST http://localhost:8080/query -d '{
      parent as p(func: has(jungle)) {}
    
      me(func: uid(parent)) {
        uid
        expand(_all_) {
          uid
          expand(_all_) {
            uid
            expand(_all_) {
              uid
              name
            }
          }
        }
      }
    }' | jq '.'
    

    Response:

    {
      "data": {
        "p": [],
        "me": [
          {
            "uid": "0x40",
            "jungle": [
              {
                "uid": "0x39",
                "animals": [
                  {
                    "uid": "0x3a",
                    "lion": [
                      {
                        "uid": "0x3b",
                        "name": "Simba"
                      }
                    ],
                    "elephant": [
                      {
                        "uid": "0x3c",
                        "name": "Ele"
                      }
                    ]
                  }
                ],
                "birds": [
                  {
                    "uid": "0x3d",
                    "parrot": [
                      {
                        "uid": "0x3e",
                        "name": "Zuzu"
                      }
                    ],
                    "chicken": [
                      {
                        "uid": "0x3f",
                        "name": "Chica"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      "extensions": {
        "server_latency": {
          "parsing_ns": 34528,
          "processing_ns": 2238479,
          "encoding_ns": 750501
        },
        "txn": {
          "start_ts": 57,
          "lin_read": {
            "ids": {
              "1": 81
            }
          }
        }
      }
    }
    
  4. Add @recurse to the me query from Step 4 and see that the query isn't the same.

    $ curl -s -XPOST http://localhost:8080/query -d '{
      parent as p(func: has(jungle)) {}
    
      me(func: uid(parent)) @recurse {
        uid
        expand(_all_) {
          uid
          expand(_all_) {
            uid
            expand(_all_) {
              uid
              name
            }
          }
        }
      }
    }' | jq '.'
    

    Response:

    {
      "data": {
        "p": [],
        "me": [
          {
            "uid": "0x40",
            "jungle": [
              {
                "uid": "0x39"
              }
            ]
          }
        ]
      },
      "extensions": {
        "server_latency": {
          "parsing_ns": 45068,
          "processing_ns": 2554408,
          "encoding_ns": 456431
        },
        "txn": {
          "start_ts": 58,
          "lin_read": {
            "ids": {
              "1": 82
            }
          }
        }
      }
    }
    

Expected behavior:

The @recurse keyword recursively get the subgraph from the root node.

@danielmai danielmai added the kind/bug Something is broken. label Aug 28, 2018
@jpacik
Copy link
Contributor

jpacik commented Sep 12, 2018

@danielmai @manishrjain I propose we close this issue and (perhaps) turn this into a feature request. But I don't believe it is a bug. The current implementation of expandRecurse

func (start *SubGraph) expandRecurse(ctx context.Context, maxDepth uint64) error {

does not support multi-level predicates. Because of this, the following query:

  me(func: uid(parent)) @recurse {
      uid
      expand(_all_) {
          uid
          expand(_all_) {
              uid
              expand(_all_) {
                  uid
                  name
              }
          }
      }
  }

is equivalent to

  me(func: uid(parent)) @recurse {
      uid
      jungle
  }

The expected result of this query is exactly the final result shown in the above comment.

@danielmai
Copy link
Contributor Author

@srfrog can you update this issue report with the changes you're planning to make?

@srfrog
Copy link
Contributor

srfrog commented Sep 13, 2018

i agree with @manishrjain (from video chat) and @jlapacik this is a new feature.

@danielmai
Copy link
Contributor Author

Discussed with @manishrjain. expand(_all_) with @recurse should really be equivalent to expand(_all_) at every depth. So a query like this gets all the predicates:

{
  me(func: uid(parent)) @recurse {
    uid
    expand(_all_)
  }
}

Should get the jungle predicate for the first uid, animals in the second uid, and so on.

Will keep this issue open as a bug.


Query:

{
  parent as p(func: has(jungle)) {}

  me(func: uid(parent)) @recurse {
    uid
    expand(_all_)
  }
}

Actual Response:

{
  "data": {
    "p": [],
    "me": [
      {
        "uid": "0x40",
        "jungle": [
          {
            "uid": "0x39"
          }
        ]
      }
    ]
  }
}

Expected Response:

{
  "data": {
    "p": [],
    "me": [
      {
        "uid": "0x40",
        "jungle": [
          {
            "uid": "0x39",
            "animals": [
              {
                "uid": "0x3a",
                "lion": [
                  {
                    "uid": "0x3b",
                    "name": "Simba"
                  }
                ],
                "elephant": [
                  {
                    "uid": "0x3c",
                    "name": "Ele"
                  }
                ]
              }
            ],
            "birds": [
              {
                "uid": "0x3d",
                "parrot": [
                  {
                    "uid": "0x3e",
                    "name": "Zuzu"
                  }
                ],
                "chicken": [
                  {
                    "uid": "0x3f",
                    "name": "Chica"
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  }

@asadm
Copy link

asadm commented Sep 29, 2018

OP of the original issue here. Thanks for this!
So I can play with this in the next release I guess?

@srfrog
Copy link
Contributor

srfrog commented Sep 29, 2018

That hasn't been decided yet, but it's likely. Thanks for submitting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something is broken.
Development

No branches or pull requests

4 participants