Skip to content

Sorting By int ot date field, filter results #2686

Closed
@TomLevvv

Description

@TomLevvv

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"
      }
    ]
  }`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions