Using GraphFrames (Scala) to compute hierarchy

251 views Asked by At

I have a dataframe below:

employee_id|employee_name|manager_employee_id|
----------------------------------------------
    1           eric (ceo)      1
    2           edward          1
    3           john            1
    4           james           2
    5           ella            4

I would like to use spark (scala) graphframe logic to achieve the following:

employee_id|employee_name|manager_employee_id|level|hierarchy
-------------------------------------------------------------
    1           eric            1                0    /1
    2           edward          1                1    /1/2
    3           john            1                1    /1/3
    4           james           2                2    /1/2/4
    5           ella            3                3    /1/2/4/5

Any help would be much appreciated

1

There are 1 answers

0
ironhide96 On

I think the answer you are looking for is more or less related to this.

The only modification required at your end will be aggregating the messages to get the complete hierarchy . For that part you can refer to this.

A combination of above two will get you the desired results.