Cannot do the eq in https://dgraph.io/tour/blocksvars/11

in https://dgraph.io/tour/blocksvars/11,

{
  directorids as var(func: has(director.film)) {
    director.film {
      initdate as initial_release_date
    }
    recently_release as max(val(initdate))
    directorname as name@.
  }
  
  hello(func: uid(directorids), orderdesc: val(recently_release)) @cascade{
    director_name : val(directorname)
    recently_release_date : val(recently_release)
    directorfilm : director.film @filter(eq(initial_release_date, val(recently_release) )) {
      name@.
      initial_release_date
    }
  }  
}

i want to display the latest/most-recently movie of the director in the block

    directorfilm : director.film @filter(eq(initial_release_date, val(recently_release) )) {
      name@.
      initial_release_date
    }

however, the result display all of the movie information under that director like…

{
  "data": {
    "hello": [
      {
        "director_name": "James Cameron",
        "recently_release_date": "2017-12-01T00:00:00Z",
        "directorfilm": [
          {
            "name@.": "Piranha II: The Spawning",
            "initial_release_date": "1981-12-01T00:00:00Z"
          },
          {
            "name@.": "T2 3-D:Battle Across Time",
            "initial_release_date": "1996-01-01T00:00:00Z"
          },
          {
            "name@.": "Avatar 3",
            "initial_release_date": "2017-12-01T00:00:00Z"
          },
          {
            "name@.": "Avatar",
            "initial_release_date": "2009-12-10T00:00:00Z"
          },
          {
            "name@.": "Expedition: Bismarck",
            "initial_release_date": "2002-12-08T00:00:00Z"
          },
          {
            "name@.": "The Terminator",
            "initial_release_date": "1984-10-26T00:00:00Z"
          }
        ]
      },
      {
        "director_name": "Espen Sandberg",
        "recently_release_date": "2017-07-06T00:00:00Z",
        "directorfilm": [
          {
            "name@.": "Max Manus: Man of War",
            "initial_release_date": "2008-12-19T00:00:00Z"
          },
          {
            "name@.": "Pirates of the Caribbean: Dead Men Tell No Tales",
            "initial_release_date": "2017-07-06T00:00:00Z"
          }
        ]
      },
....

why is that?

I guess that’s not possible. Aggregations can’t be used in all scenarios. Only for aggregations.

The recently_release variable will collect all possible max values from all nodes found in the query. If you isolate (instead of using “has fun”) to a single node you will get the result you want.

e.g:

director as var(func: gt(count(director.film), 200), first:1)

So, very broad searches tend not to have the desired result when using different features. I have an issue that might solve this case https://github.com/dgraph-io/dgraph/issues/5335

thanks for your answer.

however, the “recently_release_date” will display one value and this value is corresponding/mapping to that particular director. Using this logic, “val(recently_release)” will return a value which correspond/map to the current matching director in that block, isn’t it?

it looks like not consistent of the logic about “val(recently_release)” ?

thanks

Run this at https://play.dgraph.io/?latest

{
  directorids as debug(func: gt(count(director.film), 200), first:10, orderdesc:  name@.) {
     name@.
    director.film @normalize {
      initdate as initial_release_date
    }
    recently_release as max(val(initdate))
  }
    me(){
      test: max(val(initdate))
      test2: max(val(recently_release))
    }
  
  hello(func: uid(directorids), orderdesc:  name@.) @cascade {
    name@.
    recently_release_date : val(recently_release)
    directorfilm : director.film @filter(eq(initial_release_date, val(recently_release) )) @normalize {
     movieName :  name@.
      initial_release_date : initial_release_date
    }
  }  
}

As you can see in the result below, all other queries are “contaminated” with values collected previously.

Your use case has not been thought of before. There was no such intention. For aggregations are used via the empty blocks (As in the case of the “me” block) to apply later on another block.

It may be possible to fix this instead of adding a new feature, as it is obviously similar to a bug (and it is already known), but that is part of the design.

See, other use cases are affected by this design Standard Deviation

No, it won’t work that way, that’s the “bug”.

Overall, I would recommend doing this at the application (Your end) level for now.

Result

{
  "data": {
    "debug": [
      {
        "name@.": "Keith Miller",
        "max(val(initdate))": "2010-05-05T00:00:00Z"
      },
      {
        "name@.": "Georges Méliès",
        "max(val(initdate))": "2007-11-01T00:00:00Z"
      },
      {
        "name@.": "Friz Freleng",
        "max(val(initdate))": "2012-03-06T00:00:00Z"
      },
      {
        "name@.": "D. W. Griffith",
        "max(val(initdate))": "1951-01-01T00:00:00Z"
      },
      {
        "name@.": "Chuck Jones",
        "max(val(initdate))": "2011-12-07T00:00:00Z"
      },
      {
        "name@.": "Chi Chi LaRue",
        "max(val(initdate))": "2010-07-30T00:00:00Z"
      },
      {
        "name@.": "Charles Lamont",
        "max(val(initdate))": "1956-07-20T00:00:00Z"
      }
    ],
    "me": [
      {
        "test": "2012-03-06T00:00:00Z"
      },
      {
        "test2": "2012-03-06T00:00:00Z"
      }
    ],
    "hello": [
      {
        "name@.": "Keith Miller",
        "recently_release_date": "2010-05-05T00:00:00Z",
        "directorfilm": [
          {
            "movieName": "Spanking Curiosity 4",
            "initial_release_date": "2010-05-05T00:00:00Z"
          }
        ]
      },
      {
        "name@.": "Georges Méliès",
        "recently_release_date": "2007-11-01T00:00:00Z",
        "directorfilm": [
          {
            "movieName": "Satan in Prison",
            "initial_release_date": "2007-11-01T00:00:00Z"
          }
        ]
      },
      {
        "name@.": "Friz Freleng",
        "recently_release_date": "2012-03-06T00:00:00Z",
        "directorfilm": [
          {
            "movieName": "Looney Tunes Super Stars' Pepe Le Pew: Zee Best of Zee Best",
            "initial_release_date": "2011-12-07T00:00:00Z"
          },
          {
            "movieName": "Ballot Box Bunny",
            "initial_release_date": "1951-01-01T00:00:00Z"
          },
          {
            "movieName": "The Best of Bugs Bunny",
            "initial_release_date": "2012-03-06T00:00:00Z"
          }
        ]
      },
      {
        "name@.": "D. W. Griffith",
        "recently_release_date": "1951-01-01T00:00:00Z",
        "directorfilm": [
          {
            "movieName": "Footlight Varieties",
            "initial_release_date": "1951-01-01T00:00:00Z"
          }
        ]
      },
      {
        "name@.": "Chuck Jones",
        "recently_release_date": "2011-12-07T00:00:00Z",
        "directorfilm": [
          {
            "movieName": "Drip-Along Daffy",
            "initial_release_date": "1951-01-01T00:00:00Z"
          },
          {
            "movieName": "Looney Tunes Super Stars' Pepe Le Pew: Zee Best of Zee Best",
            "initial_release_date": "2011-12-07T00:00:00Z"
          },
          {
            "movieName": "Rabbit Fire",
            "initial_release_date": "1951-01-01T00:00:00Z"
          }
        ]
      },
      {
        "name@.": "Chi Chi LaRue",
        "recently_release_date": "2010-07-30T00:00:00Z",
        "directorfilm": [
          {
            "movieName": "Falcon Four Hours - Muscle Madness",
            "initial_release_date": "2010-07-30T00:00:00Z"
          }
        ]
      },
      {
        "name@.": "Charles Lamont",
        "recently_release_date": "1956-07-20T00:00:00Z",
        "directorfilm": [
          {
            "movieName": "Francis (the talking mule) in the Haunted House",
            "initial_release_date": "1956-07-20T00:00:00Z"
          }
        ]
      }
    ]
  }
}

wow, i have luck :slight_smile: to encounter this bug :slight_smile:

trying a bit more…

if i change
“directorids as var(func: has(director.film)) {”
to
“directorids as var(func: has(director.film), orderasc : name@., first : 40 ) {”

then it show correctly without contamination…
however, if it change from “first:40” to “first:50” or other value, then the result will not be corrected.
I think this looks a bug to me :slight_smile:

@MichelDiz Do you know of a different way to accomplish what he is trying to do perhaps with differently structured query?

One could in hello query sort director.film descending by initial_release_date and just grab the first one, but that doesn’t seem efficient. Also if initial_release_date is not unique per director’s film, then result won’t return those duplicates, which have the same initial_release_date.

directorfilm : director.film (orderdesc: initial_release_date, first: 1) {
   name@.
   initial_release_date
}

True, there could be other films at the same time.

I tried to imagine something. But I can’t imagine anything that would solve that but “foreach”.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.