I'm trying to convert some statements from Qlikview into a Databricks notebook. I used the Hierarchy Load a lot in Qlikview and it really helped me to build a parent/child relationship in one table and building also a path. Now I want to use this functionality in a notebook, but I can't find this 'Hierarchy'-function in SQL, pandas or pyspark.
Hierarchy load documentation of QlikView: https://help.qlik.com/en-US/qlikview/April2020/Subsystems/Client/Content/QV_QlikView/Scripting/ScriptPrefixes/Hierarchy.htm
My table is (e.g.):
NodeID ParentID NodeName
0 1 4 London
1 2 3 Munich
2 3 5 Germany
3 4 5 UK
4 5 Europe
My output should be:
+----+---------+-----------+-----------+-------------+------------+------------+------------+------------------------+-------+
| | NodeID | NodeName | ParentID | ParentName | NodeName1 | NodeName2 | NodeName3 | PathName | Depth |
+----+---------+-----------+-----------+-------------+------------+------------+------------+------------------------+-------+
| 0 | 5 | Europe | | - | - | - | Europe | Europe | 1 |
| 1 | 3 | Germany | 5 | Europe | Europe | Germany | - | Europe\Germany | 2 |
| 2 | 2 | Munich | 3 | Germany | Europe | Germany | Munich | Europe\Germany\Munich | 3 |
| 3 | 4 | UK | 5 | Europe | Europe | UK | - | Europe\UK | 2 |
| 4 | 1 | London | 4 | UK | Europe | UK | London | Europe\UK\London | 3 |
+----+---------+-----------+-----------+-------------+------------+------------+------------+------------------------+-------+
Can you please help me to build this function in Pandas/Python? Thank you very much!