Expected a value variable in cond but missing

{
  var(func:allofterms([email protected], "steven spielbeABC")) {
    films as director.film {
      p as count(starring)
      q as count(genre)
      date as initial_release_date
      years as math(since(date)/(365*24*60*60))
      score as math(cond(years > 10, 0, ln(p)+q-ln(years)))
    }
  }

  TopMovies(func: uid(films), orderdesc: val(score)) @filter(gt(val(score), 2)){
    [email protected]
    val(score)
    val(date)
  }
}

Search keyword “steven spielbeABC” , return empty but show error :
“: Expected a value variable in cond but missing.”

The issue is. The “steven spielbeABC” doesn’t exist and the logic func “cond” in math needs a value in the first param. In this case is waiting for “years” variable. And it’s empty.

it must return empty, but it throw exception, so i can not join this list to other list , and all job is stop with this exception,please help, thanks
i’m going to replace all redis cluster+ elsticsearch by use dgraph database for store and search score, so help me

this code not run , it thow exception. if ls1 not found.


{
 
  ls1 as  var(func: has(product_category ))  
 @filter(
      regexp(product_productname, /samsung-nonExits data.*/i) 
 ) 
 { 
   product_category{
     uid
     
   }
  
   uid ,
   
    cat1 as  product_categoryid,
    r1 as math(cond(cat1 == 42, 1,0 )),
    score1  as math(100+r1)
   } 
   ls2 as  var(func: has(product_category ))  
 @filter(
       alloftext(product_productname, "samsung")  
 ) 
 {  product_category{
     uid
     
   }
   uid ,
 
    cat2 as  product_categoryid,
    r2 as  math(cond(cat2 == 42, 1,0 )),
     score2  as math(10+r2)
   } 
  ls3 as  var(func: has(product_category))  
 @filter(
     anyoftext(product_productname, "samsung")  
 ) 
 { 
     product_category{
     uid
     
   }
   uid ,
   cat3 as  product_categoryid,
    r3 as  math(cond(cat3 == 42, 1,0 )),
     score3  as math(3+r3)
   } 
 
  lsall as var(func: uid(  ls1,ls3, ls2)   )    {  
   
    
uid,
 score as  math(score1+score2+score3) ,
  catlistX as  product_category {
  category_categoryid,
   uid
 }
 
}
 
 #----------------
  
 
 
 rs as var(func:  uid( catlistX )    ) {

   uid,
  ~product_category  @filter( uid( lsall) )     
     { 
  
        m1  as product_productid
      # m0  as math(product_productid)
   c as  count(product_productid),
  r as math(1)#cond(m1 == 23369, 1,0)),
  #  scorex  as math(score) 
 }
   m  as  min(val(m1)),
 xx as  sum(val(c)) ,
   sr as  sum(val(r)) 
 }
   
   
   catelist(func: uid(  rs ) 
 
   ,first:100   ,orderdesc: val(xx) ) # @filter(   eq(val(sr), 0) #filter again

     {    
category_categoryid,
  category_categoryname
 uid,
 val(xx),
     val(m),
        val(sr)
}
 
 sanpham(func: uid(  lsall ) 
 
   ,first:15  ,orderdesc: val(score ) ) 
   
   
   {    
     product_categoryid
product_productname,
  product_contentsrh
 uid,
      val(score),
      product_category {
       category_categoryname
       category_categoryid
     }
}
   
 
} 

Although I agree that the result of this could be “empty”. I think an error is way better than empty. If you have an error you know that something is wrong in the query. If you have an empty response you just know that the Root query is wrong (Meaning that there is no such node).

But Imagine the following situation. You have multiple blocks that depend on each other. And one of them returns empty, there will be a new error because the blocks that depend on that first empty block. It will request the variable of the block that is empty. That way you will get an error. Either way there is an easier solution than fixing the query Root params.

The best way is for you to take both empty and error responses as well as valid ones. Valid on the case for you to check your typo or take the result as “false”.

If you are doing a cascading query I believe you’d be better doing first:

1- Gather all nodes without doing any conditional validation. Thus eliminating the empty nodes.
2 - In the following queries blocks you can use conditionals and this error will not be present.

eg:

{
 
  # Gather all nodes Herer
  ls1 as  var(func: has(product_category ))  @filter(regexp(product_productname, /samsung-nonExits data.*/i) ) 
  ls2 as  var(func: has(product_category )) @filter(alloftext(product_productname, "samsung")) 
  ls3 as  var(func: has(product_category)) @filter(anyoftext(product_productname, "samsung")) 

  lsall as var(func: uid(  ls1,ls3, ls2)   )    {  
    #Do whatever you need here
  }
 
}
2 Likes

OK, thanks you very much .

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