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

**URL:** <https://discuss.dgraph.io/t/cannot-do-the-eq-in-https-dgraph-io-tour-blocksvars-11/6821>\
**Category:** Dgraph\
**Created:** [May 24, 2020, 6:47am UTC](https://discuss.dgraph.io/t/cannot-do-the-eq-in-https-dgraph-io-tour-blocksvars-11/6821 "2020-05-24T06:47:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![questiondgraph](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/questiondgraph/32/3041_2.png) [@questiondgraph](https://discuss.dgraph.io/u/questiondgraph)\
**Post date:** [May 24, 2020, 6:47am UTC](https://discuss.dgraph.io/t/cannot-do-the-eq-in-https-dgraph-io-tour-blocksvars-11/6821/1 "2020-05-24T06:47:35Z")

</div>

in [Exercise : Latest Movies | Blocksvars | Dgraph Tour](https://dgraph.io/tour/blocksvars/11),

```auto
{
  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

```auto
    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…

```auto
{
  "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?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [May 25, 2020, 5:44pm UTC](https://discuss.dgraph.io/t/cannot-do-the-eq-in-https-dgraph-io-tour-blocksvars-11/6821/2 "2020-05-25T17:44:08Z")

</div>

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:

```auto
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 [Feature: Add foreach() function. · Issue #5335 · dgraph-io/dgraph · GitHub](https://github.com/dgraph-io/dgraph/issues/5335)

---

<div class="post-metadata">

**Author:** ![questiondgraph](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/questiondgraph/32/3041_2.png) [@questiondgraph](https://discuss.dgraph.io/u/questiondgraph)\
**Post date:** [May 25, 2020, 6:48pm UTC](https://discuss.dgraph.io/t/cannot-do-the-eq-in-https-dgraph-io-tour-blocksvars-11/6821/3 "2020-05-25T18:48:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [May 25, 2020, 7:32pm UTC](https://discuss.dgraph.io/t/cannot-do-the-eq-in-https-dgraph-io-tour-blocksvars-11/6821/4 "2020-05-25T19:32:08Z")

</div>

Run this at [https://play.dgraph.io/?latest](https://play.dgraph.io/?latest)

```auto
{
  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 - #4 by MichelDiz - Dgraph - Discuss Dgraph](http://discuss.hypermode.com/t/standard-deviation/6241/4?u=micheldiz)

> [@questiondgraph](#):
>
> will return a value which correspond/map to the current matching director in that block, isn’t it?

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

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

```

---

<div class="post-metadata">

**Author:** ![questiondgraph](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/questiondgraph/32/3041_2.png) [@questiondgraph](https://discuss.dgraph.io/u/questiondgraph)\
**Post date:** [May 26, 2020, 9:12am UTC](https://discuss.dgraph.io/t/cannot-do-the-eq-in-https-dgraph-io-tour-blocksvars-11/6821/5 "2020-05-26T09:12:53Z")

</div>

wow, i have luck 🙂 to encounter this bug 🙂

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 🙂

---

<div class="post-metadata">

**Author:** ![zura](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/zura/32/3046_2.png) [@zura](https://discuss.dgraph.io/u/zura)\
**Post date:** [May 26, 2020, 9:31am UTC](https://discuss.dgraph.io/t/cannot-do-the-eq-in-https-dgraph-io-tour-blocksvars-11/6821/6 "2020-05-26T09:31:57Z")

</div>

@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**.

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

```

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [May 26, 2020, 4:36pm UTC](https://discuss.dgraph.io/t/cannot-do-the-eq-in-https-dgraph-io-tour-blocksvars-11/6821/7 "2020-05-26T16:36:56Z")

</div>

> [@zura](#):
>
> 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**.

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

> [@zura](#):
>
> Do you know of a different way to accomplish what he is trying to do perhaps with differently structured query?

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [June 25, 2020, 4:41pm UTC](https://discuss.dgraph.io/t/cannot-do-the-eq-in-https-dgraph-io-tour-blocksvars-11/6821/8 "2020-06-25T16:41:29Z")

</div>

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