Uid_in can't use variables

I tried
uid_predicate{myvar as uid}, and later on uid_in(predicate, val(myvar))
I get : Wrong variable type encountered for var(myvar) 2.

I also tried
myvar as uid_predicate {xxxx}, and later on uid_in(predicate, myvar)
I get : Some variables are defined but not used Defined:[myvar] Used:

Is there a way to use uid variable with uid_in?

By the way, are the two ways of assigning uid variables (uid_predicate{myvar as uid} AND myvar as uid_predicate {xxxx}) identical to each other? What’s their difference?

variable type should use only in two ways, val(…) or uid(…).

you should know the mean of the root node, if you are in the view of the root node, you can only see what you can see from the root node’s view.

when you use myvar to query:

  1. uid variables (uid_predicate{myvar as uid} ---- the root node is uid_predicate’s child node
  2. myvar as uid_predicate {xxxx}) ---- the root node is uid_predicate

that’s the difference

If I use myvar as uid, what’s the type of the variable myvar? is it uid or value variable?

but even if I use uid_predicate{myvar as some_value_predicate},
I could always extract the uid_predicate by using uid(myvar),
since value variable stores a Map<UID, VALUE>.

Can the my var in myvar as uid also be regarded as a value variable and be used in the above way?

yes, it can be used in the above way . have you tried ?

uid_in(some_predicate, uid(myvar))

Only val/count allowed as function within another. Got: uid`

Still can’t use uid_in with variables

can you just use uid(myvar)

uid_in only used in @filter
https://docs.dgraph.io/query-language/#uid-in

predicateA{
predicateB @filter(uid_in(predicateC, myvar)){
some_property
predicateC{
}
}
}

In this case I don’t want those predicateB’s that don’t have a matching predicateC.
Do you know a way to realize this need using uid() ?

I know there’s the cascade directive, but I need some properties of predicateB to be included in result.

don’t use uid_in for variable. pls use uid(…) for variable
predicate @filter(uid(a)) for variable a

ref:
{
var(func: allofterms(name@en, “Taraji Henson”)) {
actor.film {
F as performance.film {
G as genre
}
}
}

Taraji_films_by_genre(func: uid(G)) {
genre_name : name@en
films : ~genre @filter(uid(F)) {
film_name : name@en
}
}
}

you should first understand what’s wrong with you query and try to fix it.

otherwise give some data to test your query

I know my query is syntactically wrong, I just want to illustrate why I need uid_in, do you get the idea?

{
  set{
    _:bookA  <title> "A smart dog"  .
    _:bookA  <price> "3"  .
     _:bookB  <title>  "Beat the bill"  .
    _:bookB  <price> "4"  .
    _:bookC <title> "Coming soon" .
    _:bookC  <price> "5"  .
    
    _:booklist1 <haveBook> _:bookA .
    _:booklist2 <haveBook> _:bookB .
    _:booklist3 <haveBook> _:bookC  .
    
    _:alice <starring> _:booklist1 .
    _:alice <starring> _:booklist2 .
    _:alice <starring> _:booklist3 .
  }  
}

mutate result:

"data": {
    "code": "Success",
    "message": "Done",
    "uids": {
      "alice": "0x45",
      "bookA": "0x46",
      "bookB": "0x40",
      "bookC": "0x41",
      "booklist1": "0x42",
      "booklist2": "0x43",
      "booklist3": "0x44"
    }
  }

and then i try to filter books: only with the price is 3,
use this query , it seems to like your situation with predicateB matching predicateC

{
  var(func:uid(0x45)) @cascade {
    uid
    booklist as  starring {
        haveBook @filter(eq(price, 3)) {
          
        }
      }
  }
  query(func:uid(0x45)) {
    uid
   starring @filter(uid(booklist)) {
     haveBook {
      title
      price
    }
   }
  }
}

and the query result here:

"data": {
    "query": [
      {
        "uid": "0x45",
        "starring": [
          {
            "haveBook": [
              {
                "title": "A smart dog",
                "price": 3
              }
            ]
          }
        ]
      }
    ]
  }

god bless

thanks, that seems to work, I’ll do more testing

No problem, good to hear that

1 Like