dgraph icon indicating copy to clipboard operation
dgraph copied to clipboard

Query graph with empty string values.

Open sboorlagadda opened this issue 8 years ago • 1 comments

As per this discussion there could be some use cases where attribute values are empty strings. Dgraph should allow querying in such cases.

Data

{
  "data": {
    "rooms": [
      {
        "name": "room 1"
      },
      {
        "name": "room 2"
      },
      {
        "name": ""
      }
    ]
  }
}

Query

{
  rooms(func: has(room)) {
    count(room @filter(eq(room, "")))
  }
}

sboorlagadda avatar Feb 10 '18 21:02 sboorlagadda

I'm the OP.....I've been away all week so have only just had a chance to look at this and noticed you'd raised the issue....thanks.

I realised my example was really bad, but the issue is still there. I've just replicated it on 1.0.3.

Schema

office: string @index(hash) .
room: string @index(term) .
office.room: uid @count @reverse .

Data

{
  set {
    _:o <office> "office 1" .
    _:o <office.room> _:x .
    _:o <office.room> _:y .
    _:o <office.room> _:z .
    _:x <room> "room 1" .
    _:y <room> "room 2" .
    _:z <room> "" .
  }
}

Query

{
  offices(func: has(office)) {
    count(office.room @filter(eq(room, "_nil_")))
    office.room {
      room
    }
  }
}

The above query should return 1, but instead it returns 0. I tried it with an empty string and received an error: Empty argument received

The plainer query below returns 3 as expected.

{
  offices(func: has(office)) {
    count(office.room)
    office.room {
      room
    }
  }
}

rokett avatar Feb 10 '18 23:02 rokett