2017-06-01 54 views
1

試想一下,我有這樣的樹:大廈層次使用星火

- One 
    - One one 
    - One two 
    - One two one 
    - One two two 
    - One two three 
     - One two three one 
    - One three 
    - One three one 
    - One three two 
    - One three three 
    - One four 
    - One five 

數據明智它很簡單也只是一個父子關係:

+-------------------+---------------+ 
|  Child  | Parent  | 
+-------------------+---------------+ 
| One    |    | 
| One one   | One   | 
| One two   | One   | 
| One two one  | One two  | 
| One two two  | One two  | 
| One two three  | One two  | 
| One two three one | One two three | 
| One three   | One   | 
| One three one  | One three  | 
| One three two  | One three  | 
| One three three | One three  | 
| One four   | One   | 
| One five   | One   | 
+-------------------+---------------+ 

現在想什麼,我做的是:

  • 我有兩個項目的列表,讓我們說One three threeOne two three one
  • 我想建造樹父母的休息根級別

在RDBMS中,我會簡單地寫使用CTE和UNION ALL,但是我無法找到使用是否有可能在星火遞歸查詢數據集或DataFrame,可能是由於缺乏Scala/Python知識。任何幫助,將不勝感激。

輸出應該如下:

- One 
    - One two 
    - One two three 
     - One two three one 
    - One three 
    - One three three 

回答