recursive cte in spark SQL

SQLGirl picture SQLGirl · Sep 28, 2018 · Viewed 8.5k times · Source
; WITH  Hierarchy as 
        (
            select distinct PersonnelNumber
            , Email
            , ManagerEmail 
            from dimstage
            union all
            select e.PersonnelNumber
            , e.Email           
            , e.ManagerEmail 
            from dimstage  e
            join Hierarchy as  h on e.Email = h.ManagerEmail
        )
        select * from Hierarchy

Can you help acheive the same in SPARK SQL

Answer

thebluephantom picture thebluephantom · Sep 29, 2018

This is not possible using SPARK SQL. The WITH clause exists, but not for CONNECT BY like in, say, ORACLE, or recursion in DB2.