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

Bug with count() and facets #4659

Closed
MichelDiz opened this issue Jan 23, 2020 · 0 comments · Fixed by #4751
Closed

Bug with count() and facets #4659

MichelDiz opened this issue Jan 23, 2020 · 0 comments · Fixed by #4751
Labels
area/facets Issues related to face handling, querying, etc. area/querylang/filter Related to the filter 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

@MichelDiz
Copy link
Contributor

MichelDiz commented Jan 23, 2020

What version of Dgraph are you using?

Dgraph version   : v1.1.1
Dgraph SHA-256   : 02f468aaea43acc1b0a1c88f6d465a2d329cad4b69bdff3fe599f910eb284a90
Commit SHA-1     : 8994a5740
Commit timestamp : 2019-12-16 18:24:50 -0800
Branch           : HEAD
Go version       : go1.13.5

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, OS)?

macOS

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

Run this mutation

{
  set {
    _:alice <name> "Alice" (since="2020-01-02T15:04:05") .
    _:alice <dgraph.type> "Person" (since="2020-01-02T15:04:05") .
    _:alice <mobile> "040123456" (since="2020-01-02T15:04:05") .
    _:alice <mycar> _:car (since="2020-01-02T13:01:09", first="true") .

    _:car <model> "MA0123" .
  }
}

Expected behaviour and actual result.

Running this query I got a wrong result.

{
  data(func: eq(name, "Alice"))@filter(has(mycar)) {
     name
     mobile @facets(since)
     mycar @facets {
       uid
      model
    }
     countHasFirst: count(mycar) @facets(eq(first, false)) #It should return 0 count. But returns 1 with true or false value
  }
}

But if I run this query it gives the right result

{
  data(func: eq(name, "Alice"))@filter(has(mycar)) {
     name
     mobile @facets(since)
     mycar @facets {
       uid
      model
    }
     countHasFirst: count(mycar) @filter(has(model)) @facets(eq(first, false)) #Change to true to see the difference
  }
}

Update

Calling @facets before execute the facet filter also doesn't work.

{
  data(func: eq(name, "Alice"))@filter(has(mycar)) {
     name
     mobile @facets(since)
     mycar @facets {
       uid
      model
    }
    counthasfirst0: count(mycar) @facets @facets(eq(first, true))
    countHasFirst0_1: count(mycar) @facets @facets(eq(first, false))

    counthasfirst1: count(mycar) @facets(eq(first, true))
    countHasFirst1_1: count(mycar) @facets(eq(first, false))

    countHasFirst2: count(mycar) @filter(has(model)) @facets(eq(first, true))
    countHasFirst2_1: count(mycar) @filter(has(model)) @facets(eq(first, false))
  }
}

Result

{
  "data": {
    "data": [
      {
        "name": "Alice",
        "mobile|since": "2020-01-02T15:04:05",
        "mobile": "040123456",
        "mycar": [
          {
            "uid": "0x14c096",
            "model": "MA0123",
            "mycar|first": "true",
            "mycar|since": "2020-01-02T13:01:09"
          }
        ],
        "counthasfirst0": 1,
        "countHasFirst0_1": 1, #Should be count = 0
        "counthasfirst1": 1,
        "countHasFirst1_1": 1, #Should be count = 0
        "countHasFirst2": 1, #Should be count = 1 / it is correct!
        "countHasFirst2_1": 0 #Should be count = 0 / it is correct!
      }
    ]
  }
}
@MichelDiz MichelDiz added kind/bug Something is broken. area/querylang Issues related to the query language specification and implementation. area/facets Issues related to face handling, querying, etc. area/querylang/filter Related to the filter directive. labels Jan 23, 2020
@lgalatin lgalatin added the status/accepted We accept to investigate/work on it. label Jan 27, 2020
ashish-goswami added a commit that referenced this issue Feb 25, 2020
Fixes: #4659

Currently count with facets filter is not returning correct result. This is because, while calculating count we use pl.Length() function, which returns length of posting list. This will return correct result if there are no facets filter. But if there are facets filter, we need to filter postings from the
posting list which satisfy facets filter.

This PR fixes above issue.
vardhanapoorv pushed a commit that referenced this issue Mar 3, 2020
Fixes: #4659

Currently count with facets filter is not returning correct result. This is because, while calculating count we use pl.Length() function, which returns length of posting list. This will return correct result if there are no facets filter. But if there are facets filter, we need to filter postings from the
posting list which satisfy facets filter.

This PR fixes above issue.
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. area/querylang/filter Related to the filter 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

Successfully merging a pull request may close this issue.

2 participants