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

Sorting By int ot date field, filter results #2686

Closed
TomLevvv opened this issue Oct 22, 2018 · 2 comments
Closed

Sorting By int ot date field, filter results #2686

TomLevvv opened this issue Oct 22, 2018 · 2 comments

Comments

@TomLevvv
Copy link

TomLevvv commented Oct 22, 2018

Hi,

I am using dgraph 1.0.9
I run a query to get objects, and use order by for sorting the results,
If I order by an optional fields, there is unconsistent behavior:
for 'text' fields - all objects return , the objects w/o that fields return at the end of the list
for 'int' or 'date' fields, - the list return when the objects w/o that field are filtered!

example:

Prepare the data:

 `{
  set{
    _:bookA  <title> "A smart dog"  .
     _:bookA  <isBook> "true"  .
    _:bookA  <price> "3"  .
     _:bookB  <title>  "Beat the bill"  .
    _:bookB  <isBook> "true"  .
    _:bookC  <price> "5" .
     _:bookC <isBook> "true"  .
  }  
}`

Query for all books, order by title ->

`{
  Query(func: has(isBook), orderasc: title )
  {
    count(uid)
    title
    price
  }
}`

Result - all boos are return:

  `"data": {
    "Query": [
      {
        "count": 3
      },
      {
        "title": "A smart dog",
        "price": 3,
        "uid": "0x26"
      },
      {
        "title": "Beat the bill",
        "uid": "0x27"
      },
      {
        "price": 5,
        "uid": "0x28"
      }
    ]
  }`

Query for all books, order by price->

`{
  Query(func: has(isBook), orderasc: price )
  {
    count(uid)
    title
    price
  }
}'

Result - Query without price are filtered!!!

`{
  "data": {
    "Query": [
      {
        "count": 2
      },
      {
        "title": "A smart dog",
        "price": 3,
        "uid": "0x26"
      },
      {
        "price": 5,
        "uid": "0x28"
      }
    ]
  }`

@MichelDiz
Copy link
Contributor

Please also take a read https://discuss.dgraph.io/t/orderasc-desc-by-object-that-is-missing-the-field-data/3389/12

To get around this you should add U$ 0 to the price. The "price" predicate can not be empty. Because empty predicates by logic are not part of the index. So, not sortable for now.

@manishrjain
Copy link
Contributor

As Michel mentioned, the price must be set. We can't assume that a property must exist for a node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants