dgraph-docs icon indicating copy to clipboard operation
dgraph-docs copied to clipboard

[Documentation]: DQL requires a specific order when using @count with @recurse

Open rahst12 opened this issue 2 years ago • 0 comments

What version of Dgraph is the target?

v21.03.01

Documentation.

DQL requires a specific order when using @count with @recurse. The below examples illustrate the behavior based on DGraph Tour examples.

The @count documentation page should reflect the changed/abnormal behavior when used in conjunction with @recurse.

When returning a Predicate AND counting the same Predicate - the DQL Query must have the @count(predicate) ordered below the predicate in the DQL query.

The below examples can be replicated by following the steps 1-6 in the DGraph Tour: Graphs | Intro | Dgraph Tour

The query returns wrong data: Note: The count of friend is above the predicate friend

{
  michael(func: eq(name, "Michael")) @recurse(depth:10){
    name
    age
    owns_pet
    friend~
    count(friend @filter(NOT eq(name, "Sarah")))
    friend @filter(NOT eq(name, "Sarah")) 
  }
}

image

The query returns correct data: Note: The count of friend is below the predicate friend

{
  michael(func: eq(name, "Michael")) @recurse(depth:10){
    name
    age
    owns_pet
    friend~
    friend @filter(NOT eq(name, "Sarah"))
    count(friend @filter(NOT eq(name, "Sarah")))
  }
}

image

Details are in this discuss post: https://discuss.dgraph.io/t/does-order-in-a-dql-query-matter/18274/4

Additional information.

I honestly think this is a bug as well. The discus post had some conversation about what is correct vs. incorrect behavior of DGraph. I think at least DGraph should throw an error stating you can't put a count above a predicate when counting the same predicate. Ideally, the order of where the count is in the DQL shouldn't matter.

rahst12 avatar Feb 14 '23 17:02 rahst12