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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Copy link
Contributor

MichelDiz commented Oct 23, 2018

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

This comment has been minimized.

Copy link
Member

manishrjain commented Nov 6, 2018

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

@manishrjain manishrjain closed this Nov 6, 2018

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