I want to select the first common boss for two employees in draph.
My model is simple:
name: string boss_of: uids
Lets assume the following data where each arrow denotes the boss_of edge:
A -> B
A -> C
B -> D
C -> E
E -> F
E -> G
So, given F And D the query should return A, for F and G the result is obviously E.
I tried using allofterms but found no solution as there may be a different number of nodes between the co-workers and their common boss. Is it possible at all to formulate such a query?
I am trying to explore dgraph (or graph databases at all), so maybe I am just overseeing something.
{
var(func: uid(0x9c672c)) {
A_BOSS as ~boss_of # In this case you have to use reverse edges
}
var(func: uid(0x9c672b)) {
B_BOSS as ~boss_of
}
query(func: uid(A_BOSS)) @filter(uid(B_BOSS)){
uid
boss_of {
uid
}
}
}
This query above will return only if the bosses are the same. Otherwise will be “Your query did not return any results”.
Other case
If you have the boss UID and wanna check who has him as boss. You could use “uid_in”. e.g:
The boss UID is 0x679de1
{
q(func: eq(section_company, "payment"))
@filter(uid_in(~boss_of, 0x679de1)){
# Now you can filter at root by the parent node via "boss_of" edge.
# In this case you have to use reverse edges
name
somethingElse
}
}
that looks fine if both employees have the same boss. But what if the first boss in common is the CEO because A works in IT dept with the department head as boss and B works for accounting and is the CFO - the CEO is his boss. I don’t see how this is solved.
Well the “CEO” is one level above “A” and “B”? if so, is the same logic above. If You wanna compare bosses at distant levels you query gets bigger. Because you need to solve the traverse way until there. Isn’t that hard, but needs work.
Sorry the delay. Well, I think there’s no other way. You may have to improve the resources of your instances to get better results. In terms of query language there’s no other way I can think of.
It is not the case of graph analysis.
we do have requirement of common followers for particular set of users, which we are trying to achieve with dgraph.
If the followers are too many, calc the common followers in realtime is too expensive, may you can pre-calc the common followers use offline analysis like spark graphx and then serve as an online service.