MichelDiz commented :
I was analyzing this issue. This issue in relation to #2001 is a duplicate of it and not the other way around. This issue was created 9 days after #2001
. Anyway.
The lack of depth in the text of this issue could unintentionally, lost some important information in the discussion. Manish had already commented on a possible solution there for this. He mentioned that would be adding a directive called @post
. To support “function edges” (Which means in value edges). But he did not get deep on it.
BTW, not sure what ‘post’ means. Would it be like “Post process”? i guess tho.
I’m going to write possible syntax ideas here for anyone working on this feature in the future. Taking into account both issues.
Syntax Examples:
Return True or False.
- predicate @post(eq("value"))
- predicate @post(eq(null)) #Check if the predicate has value returns true if false.
- predicate @post(eq(val(varName)))
- predicate @post(eq[val1, val2, ..., valN])
- predicate @post(eq[$var1, "value", ..., $varN])
- predicate @post(IE("value")) #for inequality
- myAlias: predicate @post(lt(54))
- predicate @post(count(value)) #It is exactly equal to eq, but check if it is Int or float.
- predicate @post(if(var1 >= var2))
- predicate @post(if(count(value) > var2))
Returns computed values.
# Returns "predicate": "String1 String2 String3"
- predicate @post(concat(var1, " ", var2, " ", var3))
- predicate @post(concat(var1, var2, var3), separator) #Optionally include a separator
- predicate @post(concat($var1, $name))
Using as value variable can be useful for upsert blocks.
# Returns "predicate": "String1 String2"
- value0 as predicate @post(concat(var1, var2))
- value1 as predicate @post(concat($var1, $name))
“Anonymous predicate” using an alias.
- myAlias: @post(count(value)) #This is equivalent to "myAlias: math(number)"
- myAlias: @post(if(var1 >= var2)) #This is equivalent to "myAlias: math(if(var1 >= var2))"
- value2 as myAlias: @post(if(var1 >= var2)) #Using the computed value in a variable.
Covering the issue query:
{
allNodes(func: type("DP")){
sd as supplyDate
cd as consumeDate
status
issueBehindSchedule: math(sd > cd)
noSupplyDate: supplyDate @post(eq(null))
atRisk: status @post(eq("Okay"))
}
}
The problem with this query is in the case of “null”. Dgraph does not currently support undefined or null. There is no way to check them. Perhaps issue #4619 would cover that.
Instead of issueBehindSchedule: math(sd > cd)
(which works, but it is “hacky”). we could do issueBehindSchedule: @post(if(sd > cd))
Covering the other issue
{
me(func: uid(0xabcd)) {
f as firstName@en
l as lastName@en
fullName: @post(concat( f, ' ', l))
}
}
{
me(func: uid(0xabcd)) {
f as firstName@en
l as lastName@en
fullName : @post(concat( f, ' ', l))
isMarriedTo {
fm as firstName@en
lm as lastName@en
fullName : @post(concat( fm, ' ', lm))
}
is as count(isMarriedTo)
married: @post(if(is > 0))
}
}