Facet encoding breaks with loop:false

Moved from GitHub dgraph/4168

Posted by campoy:

What version of Dgraph are you using?

1.1.0

Have you tried reproducing the issue with the latest release?

yes

What is the hardware spec (RAM, OS)?

n/a

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

Given this fully connected graph:


{
  set {
    _:a <name> "A" .
    _:b <name> "B" .
    _:c <name> "C" .
    _:d <name> "D" .

    _:a <connects> _:b  (number=1) .
    _:a <connects> _:c  (number=2) .
    _:a <connects> _:d  (number=3) .

    _:c <connects> _:a  (number=4) .
    _:c <connects> _:b  (number=5) .
    _:c <connects> _:d  (number=6) .

    _:b <connects> _:a  (number=7) .
    _:b <connects> _:c  (number=8) .
    _:b <connects> _:d  (number=9) .

    _:d <connects> _:a  (number=10) .
    _:d <connects> _:b  (number=11) .
    _:d <connects> _:c  (number=12) .
  }
}

Run the following query (assuming “A” was given uid 0x1)

{
  dcs(func: uid(0x1)) @recurse(depth: 4, loop:false) {
    dcname
    connects @facets(number)
  }
}

Expected behaviour and actual result.

I would expect to see all of the nodes connected to each other with unique number values for their facets. Instead I get this:

{
  "data": {
    "dcs": [
      {
        "connects": [
          {
            "connects": [
              {
                "connects|number": [
                  1,
                  7
                ]
              },
              {
                "connects|number": [
                  4,
                  8
                ]
              },
              {
                "connects|number": [
                  10,
                  9
                ]
              }
            ],
            "connects|number": 1
          },
          {
            "connects": [
              {
                "connects|number": [
                  1,
                  4
                ]
              },
              {
                "connects|number": [
                  7,
                  5
                ]
              },
              {
                "connects|number": [
                  10,
                  6
                ]
              }
            ],
            "connects|number": 2
          },
          {
            "connects": [
              {
                "connects|number": [
                  1,
                  10
                ]
              },
              {
                "connects|number": [
                  7,
                  11
                ]
              },
              {
                "connects|number": [
                  4,
                  12
                ]
              }
            ],
            "connects|number": 3
          }
        ]
      }
    ]
  }
}

Note that adding a second facet fixes the issue.

kesor commented :

When a @recurse query stops because of loop:false, it DOES return the facets but DOES NOT return the predicate that is associated with these facets.

Example:

{
  set {
    _:a <name> "A" .
    _:a <dgraph.type> "Example" .
    _:b <name> "B" .
    _:b <dgraph.type> "Example" .
    _:a <connects> _:b  (number=1) .
    _:b <connects> _:a  (number=7) .
  }
}
query {
  example(func:type("Example"))
  @recurse {
    name
    connects @facets
  }
}

Notice how example[0].connects[0] is missing connects[] but has the facets for that predicate!

{
  "data": {
    "example": [
      {
        "name": "A",
        "connects": [
          {
            "name": "B",
            "connects|number": {
              "0": 7
            }
          }
        ],
        "connects|number": {
          "0": 1
        }
      }

On the other hand, when loop:true is enabled (with depth) it appears that the bug is not there.

query {
  example(func:type("Example"))
  @recurse(loop:true,depth:4) {
    name
    connects @facets
  }
}
{
  "data": {
    "example": [
      {
        "name": "A",
        "connects": [
          {
            "name": "B",
            "connects": [
              {
                "name": "A",
                "connects": [
                  {
                    "name": "B"
                  }
                ],
                "connects|number": {
                  "0": 1
                }
              }
            ],
            "connects|number": {
              "0": 7
            }
          }
        ],
        "connects|number": {
          "0": 1
        }
      },