Filter UID by val(varName)


(Una Chen) #1

When sorting UID by val(varName), there are 3 results.

  1. If all UIDs contain varName, UIDs will be sorted as expected.
  2. If some UIDs don’t contain varName, they will be ignored and not responded, while others which contain varName are still sorted as expected.
  3. If all UIDs don’t contain varName, all of them are still responded but in disorder.

Take an example.

{
  directors as var(func: allofterms(name@en, "Quentin Tarantino")) {
    director.film (orderdesc:initial_release_date, first:1){
      latestFilm as name@en
    }
    minLatestFilm as max(val(latestFilm))
  }

  byLatestFilm(func: uid(directors), orderasc: val(minLatestFilm)) {
    name@en
    latestFilm: val(minLatestFilm)
  }
}

As mentioned above, the followings are 3 cases.

  1. All directors contain minLatestFilm and are sorted as expected
  2. Some directors which don’t contain minLatestFilm aren’t not appeared in the result, while others are sorted.
  3. All directors don’t contain minLatestFilm, but are still responded in disorder.

I think that the 2nd and 3rd items conflict.
Because when I expect the UIDs without minLatestFilm will be ignored in response according to 2nd item, however, they will show up in the 3rd cases.

I would highly appreciate your explanation on the design concept.
Thank you


(Una Chen) #2

In addition, if I would like to sort UIDs for minLatestFilm and append other UIDs without minLatestFilm to the previous result.

I would appreciate it if you have any advice for me.

Here is my brute-force approach.

# use separate query with Dgraph and merge them with Server
{
  directors as var(func: allofterms(name@en, "Quentin Tarantino")) {
    director.film (orderdesc:initial_release_date, first:1){
      latestFilm as name@en
      cnt as count(name@en)
    }
     minLatestFilm as max(val(latestFilm))
     minCnt as min(val(cnt))
  }

  # get the ordered result
  byLatestFilm(func: uid(directors), orderasc: val(minLatestFilm)) {
    name@en
    latestFilm: val(minLatestFilm)
  }
  # get others which do not contain minLatestFilm
  nonLatestFilm(func: uid(directors)) @filter(not eq(val(minCnt),1)) {
    name@en
  }
}