Questions after completing the 'Tour'

example

(rocqua) #1

Hi,

I’ve just completed the tour of Dgraph, and am left with some questions.
There were some examples where I tried to modify the output slightly, but could not figure out how this was done. I was hoping someone here would be able to help.

The first example is all actors in Jane Campion films that acted together in a film not directed by Jane Campion.
This also returns every actor who acted in a film by Jane Campion, and acted in one other film, since he technically acted in that film together with himself.

I tried to remove those trivial pairs, but nothing worked. My first attempt was the following:

{
  coactors(func:allofterms(name@en, "Jane Campion")) @cascade {
    JC_films as director.film {      # JC_films = all Jane Campion's films
      starting_movie: name@en
      starring {
        JC_actors as performance.actor {      # JC_actors = all actors in all JC films
          actor : name@en
          actor.film {
            performance.film @filter(not uid(JC_films)) {
              film_together : name@en
              starring @ignorereflexive {
                # find a coactor who has been in some JC film
                performance.actor @filter(uid(JC_actors)) {
                  coactor_name: name@en
                }
              }
            }
          }
        }
      }
    }
  }
}

(i.e. adding @ignorereflexive to the relevant edge).
However, that is not a valid place for the directive.
Placing that same directive at the root (i.e. after @cascade) returns no data at all, because all actors have a path towards Jane Campion by definition.

Moving JC_actors to a separate and adding @ignorereflexive does not help either, because alll actors have a path towards themselves.

My next attempt was: to store the name in a variable, and then just filter out duplicate names:

{
  coactors(func:allofterms(name@en, "Jane Campion")) @cascade {
    JC_films as director.film {      # JC_films = all Jane Campion's films
      starting_movie: name@en
      starring {
        JC_actors as performance.actor {      # JC_actors = all actors in all JC films
          actorNames as actor : name@en
          actor.film {
            performance.film @filter(not uid(JC_films)) {
              film_together : name@en
              starring {
                # find a coactor who has been in some JC film
                performance.actor @filter(uid(JC_actors) AND NOT eq(name@en, val(actorNames))) {
                  coactor_name: name@en
                }
              }
            }
          }
        }
      }
    }
  }
}

But that returns an error I cannot figure out how to fix.

This all brought me to the popular request of having @cascade, @normalize or @ignorerecursiveon sub-querries. I am mostly left with the question of how to achieve the effects of this without this feature.
I don’t really care about the aesthetics of the syntax, I just want the results.

Finally, in another example I get the output below.

What I don’t understand is why the predicate name@en for the director is not included, since obviously Cherie Nowlan has a name predicate. It is how we identifiy him.

  "data": {
    "q": [
      {
        "director.film": [
          {
            "name@en": "Underbelly Files: The Man Who Got Away",
            "name@it": "Underbelly Files: The Man Who Got Away",
            "name@de": "Underbelly Files: The Man Who Got Away",
            "initial_release_date": "2011-02-21T00:00:00Z"
          },
          {
            "name@en": "Marking Time",
            "name@it": "Marking Time",
            "name@de": "Marking Time",
            "initial_release_date": "2003-01-01T00:00:00Z"
          },
          {
            "name@en": "Clubland",
            "name@it": "Il matrimonio è un affare di famiglia",
            "name@de": "Clubland",
            "initial_release_date": "2007-01-21T00:00:00Z"
          },
          {
            "name@en": "Thank God He Met Lizzie",
            "name@it": "Thank God He Met Lizzie",
            "name@de": "Thank God He Met Lizzie",
            "initial_release_date": "1997-01-01T00:00:00Z"
          }
        ]
      }
    ]
  }
}

Any help would be appreciated!


(Michel Conrado) #2

in general you can’t use those type of directive in nested blocks. Only at root. And the right one is “@ignorereflex” see docs https://docs.dgraph.io/query-language/#ignorereflex-directive

Well the second query is wrong, you can’t use var in the same query or sub query.

By the way, it does not make sense to filter with “not uid (JC_films)” in a query that will only come from JC_films directors. That is, this filter will do nothing. Actually you’re capturing UIDs of directors and trying to use them on actors. Obviously it will not filter anything. Because directors are not actors for sure.

You have to create other query blocks for those. e.g:

{
  var(func:allofterms(name@en, "Jane Campion")) @cascade {
    director.film {
      starting_movie: name@en
      starring {
         performance.actor {
          actorNames as actor : name@en
         
          }
        }
      }
    }

        
        secondquery(func: eq(name@en, val(actorNames))){
          uid
          coactor_name: name@en
        }
}

Result

{
  "data": {
    "secondquery": [
      {
        "uid": "0xf6a8b",
        "coactor_name": "Kerry Walker"
      },
      {
        "uid": "0xf6bab",
        "coactor_name": "Theresa Watson"
      },
      {
        "uid": "0xf9250",
        "coactor_name": "Mary-Louise Parker"
      },
      {
        "uid": "0xf92e1",
        "coactor_name": "Holly Hunter"
      },
      {
        "uid": "0xfb7c5",
        "coactor_name": "Ben Whishaw"
      },
      {
        "uid": "0xfb85a",
        "coactor_name": "Edie Martin"
      },
      {
        "uid": "0xfe028",
        "coactor_name": "Di Adams"
      },
      {
        "uid": "0x1053e7",
        "coactor_name": "John Malkovich"
      },
      {
        "uid": "0x105421",
        "coactor_name": "Michelle DiBenedetti"
      },
      {
        "uid": "0x10548b",
        "coactor_name": "Jacinto Taras Riddick"
      },
      {
        "uid": "0x107cee",
        "coactor_name": "Meg Ryan"
      },
      {
        "uid": "0x10a2e5",
        "coactor_name": "Thomas Brodie-Sangster"
      },
      {
        "uid": "0x10c93e",
        "coactor_name": "Shelley Duvall"
      },
      {
        "uid": "0x10c978",
        "coactor_name": "Austen Tayshus"
      },
      {
        "uid": "0x10c9bc",
        "coactor_name": "Cliff Curtis"
      },
      {
        "uid": "0x10cb90",
        "coactor_name": "Valentina Cervi"
      },
      {
        "uid": "0x10cb9c",
        "coactor_name": "Yaani King"
      },
      {
        "uid": "0x113e2a",
        "coactor_name": "Viggo Mortensen"
      },
      {
        "uid": "0x11403a",
        "coactor_name": "Peter Dennett"
      },
      {
        "uid": "0x114053",
        "coactor_name": "Pam Grier"
      },
      {
        "uid": "0x1165a2",
        "coactor_name": "Claudie Blakley"
      },
      {
        "uid": "0x1167c2",
        "coactor_name": "Max H. Maxy"
      },
      {
        "uid": "0x11b58b",
        "coactor_name": "Funda Duval"
      },
      {
        "uid": "0x120242",
        "coactor_name": "Skippy D"
      },
      {
        "uid": "0x1229cb",
        "coactor_name": "Sharrieff Pugh"
      },
      {
        "uid": "0x122b21",
        "coactor_name": "Hal Sherman"
      },
      {
        "uid": "0x12784f",
        "coactor_name": "Paul Goddard"
      },
      {
        "uid": "0x127936",
        "coactor_name": "Roger Ashton-Griffiths"
      },
      {
        "uid": "0x12a036",
        "coactor_name": "Shelley Winters"
      },
      {
        "uid": "0x12c53c",
        "coactor_name": "Harvey Keitel"
      },
      {
        "uid": "0x12ebce",
        "coactor_name": "Paul Schneider"
      },
      {
        "uid": "0x12ed4a",
        "coactor_name": "Sophie Lee"
      },
      {
        "uid": "0x133c2f",
        "coactor_name": "Micheal Nuccio"
      },
      {
        "uid": "0x13884d",
        "coactor_name": "Tungia Baker"
      },
      {
        "uid": "0x13fd41",
        "coactor_name": "Tim Robertson"
      },
      {
        "uid": "0x13fd6c",
        "coactor_name": "Ian Mune"
      },
      {
        "uid": "0x13fe16",
        "coactor_name": "Nalini Krishan"
      },
      {
        "uid": "0x144d41",
        "coactor_name": "Jonathan Aris"
      },
      {
        "uid": "0x147298",
        "coactor_name": "Sein Gay"
      },
      {
        "uid": "0x1472b1",
        "coactor_name": "Kerry Fox"
      },
      {
        "uid": "0x149a34",
        "coactor_name": "Arthur J. Nascarella"
      },
      {
        "uid": "0x149c3d",
        "coactor_name": "Sam Neill"
      },
      {
        "uid": "0x14c1a7",
        "coactor_name": "Justine Clarke"
      },
      {
        "uid": "0x14c1c2",
        "coactor_name": "Sebastian Sozzi"
      },
      {
        "uid": "0x14e841",
        "coactor_name": "Gerard Monaco"
      },
      {
        "uid": "0x14e902",
        "coactor_name": "Alice Englert"
      },
      {
        "uid": "0x14ea13",
        "coactor_name": "Kendra Zimmerman"
      },
      {
        "uid": "0x150fd7",
        "coactor_name": "Nick Damici"
      },
      {
        "uid": "0x151058",
        "coactor_name": "Ian Abdulla"
      },
      {
        "uid": "0x1510b0",
        "coactor_name": "Lars von Trier"
      },
      {
        "uid": "0x1535d7",
        "coactor_name": "Barbara Hershey"
      },
      {
        "uid": "0x155cde",
        "coactor_name": "Dhritiman Chatterjee"
      },
      {
        "uid": "0x155ce0",
        "coactor_name": "Kate Winslet"
      },
      {
        "uid": "0x155f6d",
        "coactor_name": "Genevieve Lemon"
      },
      {
        "uid": "0x1584d7",
        "coactor_name": "George Mangos"
      },
      {
        "uid": "0x15abb8",
        "coactor_name": "Vinny Vella"
      },
      {
        "uid": "0x15d213",
        "coactor_name": "Michelle Hurst"
      },
      {
        "uid": "0x15d488",
        "coactor_name": "Paul Schneider"
      },
      {
        "uid": "0x15d4c3",
        "coactor_name": "Tim House"
      },
      {
        "uid": "0x16499b",
        "coactor_name": "Clayton Jacobson"
      },
      {
        "uid": "0x166fc0",
        "coactor_name": "Bruce Allpress"
      },
      {
        "uid": "0x16704a",
        "coactor_name": "Antonia Campbell-Hughes"
      },
      {
        "uid": "0x167057",
        "coactor_name": "Russell Dykstra"
      },
      {
        "uid": "0x169670",
        "coactor_name": "Sunrise Coigney"
      },
      {
        "uid": "0x16be7a",
        "coactor_name": "Chad Gilkison"
      },
      {
        "uid": "0x16e3f3",
        "coactor_name": "Patrice O'Neal"
      },
      {
        "uid": "0x16e52a",
        "coactor_name": "John Gielgud"
      },
      {
        "uid": "0x170a99",
        "coactor_name": "Abbie Cornish"
      },
      {
        "uid": "0x1731c1",
        "coactor_name": "Daniel Wyllie"
      },
      {
        "uid": "0x1731e7",
        "coactor_name": "Harry Weaving"
      },
      {
        "uid": "0x1731f4",
        "coactor_name": "Konkona Sen Sharma"
      },
      {
        "uid": "0x1733cb",
        "coactor_name": "Chris Haywood"
      },
      {
        "uid": "0x175a6d",
        "coactor_name": "Kevin Bacon"
      },
      {
        "uid": "0x17815e",
        "coactor_name": "Lou Martini Jr."
      },
      {
        "uid": "0x17ceab",
        "coactor_name": "Daniel T. Booth"
      },
      {
        "uid": "0x17f5c8",
        "coactor_name": "Nicole Kidman"
      },
      {
        "uid": "0x17f689",
        "coactor_name": "Olly Alexander"
      },
      {
        "uid": "0x17f6a3",
        "coactor_name": "Sandy Vital"
      },
      {
        "uid": "0x17f767",
        "coactor_name": "Ranvir Shorey"
      },
      {
        "uid": "0x181ce7",
        "coactor_name": "Frank Harts"
      },
      {
        "uid": "0x181dc6",
        "coactor_name": "Leslie Dayman"
      },
      {
        "uid": "0x181e33",
        "coactor_name": "Cassia Jurcevic"
      },
      {
        "uid": "0x186b25",
        "coactor_name": "Allison Nega"
      },
      {
        "uid": "0x18b8a5",
        "coactor_name": "Theo Kogan"
      },
      {
        "uid": "0x18ba78",
        "coactor_name": "Te Whatanui Skipwith"
      },
      {
        "uid": "0x19064c",
        "coactor_name": "Mark Ruffalo"
      },
      {
        "uid": "0x192dc5",
        "coactor_name": "Dominick Aries"
      },
      {
        "uid": "0x197db2",
        "coactor_name": "Ami Goodheart"
      },
      {
        "uid": "0x19a398",
        "coactor_name": "Carla Rupuha"
      },
      {
        "uid": "0x19cac7",
        "coactor_name": "Richard E. Grant"
      },
      {
        "uid": "0x19cb69",
        "coactor_name": "Karen Riggins"
      },
      {
        "uid": "0x19f0e9",
        "coactor_name": "Julie Hamilton"
      },
      {
        "uid": "0x1a18c7",
        "coactor_name": "Jennifer Jason Leigh"
      },
      {
        "uid": "0x1a18e0",
        "coactor_name": "Michael Ienna"
      },
      {
        "uid": "0x1a19ef",
        "coactor_name": "Sebastian Armesto"
      },
      {
        "uid": "0x1a6631",
        "coactor_name": "Samuel Barnett"
      },
      {
        "uid": "0x1a668d",
        "coactor_name": "Martin Donovan"
      },
      {
        "uid": "0x1a66cc",
        "coactor_name": "Miranda Jakich"
      },
      {
        "uid": "0x1a67a0",
        "coactor_name": "Nicole Spruill"
      },
      {
        "uid": "0x1a8ef9",
        "coactor_name": "Sharon Riggins"
      },
      {
        "uid": "0x1ab46d",
        "coactor_name": "Susan Monson"
      },
      {
        "uid": "0x1ab588",
        "coactor_name": "Christian Bale"
      },
      {
        "uid": "0x1addf7",
        "coactor_name": "James Firo"
      },
      {
        "uid": "0x1b5158",
        "coactor_name": "Yosra El Lozy"
      },
      {
        "uid": "0x1b5263",
        "coactor_name": "Samantha Murray"
      },
      {
        "uid": "0x1b7849",
        "coactor_name": "Dana Lubotsky"
      },
      {
        "uid": "0x1bc5ed",
        "coactor_name": "Edie Martin"
      },
      {
        "uid": "0x1bc62e",
        "coactor_name": "Zach Wegner"
      },
      {
        "uid": "0x1bc700",
        "coactor_name": "Anna Paquin"
      },
      {
        "uid": "0x1c152b",
        "coactor_name": "Mahina Tunui"
      },
      {
        "uid": "0x1c8a8b",
        "coactor_name": "Cordell Clyde Lochin"
      },
      {
        "uid": "0x1c8b3d",
        "coactor_name": "Panicker Upendran"
      },
      {
        "uid": "0x1c8b4e",
        "coactor_name": "Samuel Roukin"
      },
      {
        "uid": "0x1cb281",
        "coactor_name": "Simon Anderson"
      },
      {
        "uid": "0x1cd926",
        "coactor_name": "Heather Litteer"
      },
      {
        "uid": "0x1d4c80",
        "coactor_name": "Angela Frye"
      },
      {
        "uid": "0x1d4d0c",
        "coactor_name": "Susan Gardner"
      },
      {
        "uid": "0x1d4ddf",
        "coactor_name": "Pete Smith"
      },
      {
        "uid": "0x1d74ca",
        "coactor_name": "Isidore Tillers"
      },
      {
        "uid": "0x1d9ae8",
        "coactor_name": "Vincent Franklin"
      },
      {
        "uid": "0x1d9b7f",
        "coactor_name": "Nancy La Scala"
      },
      {
        "uid": "0x1e6025",
        "coactor_name": "Tintin Marova Kelly"
      },
      {
        "uid": "0x1e84f6",
        "coactor_name": "Julius LeFlore"
      }
    ]
  }
}

The query uses "expand(_all_) this function will expand any directive or pred in a block. That’s why you see lang preds.


(system) closed #3

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