โ10-03-2023 09:54 PM
Hi Team,
How to write recrusive cte in databricks SQL.
Please let me know any one have solution for this
โ10-03-2023 11:24 PM
need to run below query in databricks ql but it showing error as UserCTE table not found.
WITH UserCTE AS ( SELECT userId, userName, managerId, 0 AS EmpLevel FROM Users where managerId IS NULL UNION ALL SELECT usr.userId, usr.userName, usr.managerId, mgr.[EmpLevel]+1 FROM Users AS usr INNER JOIN UserCTE AS mgr ON usr.managerId = mgr.userId where usr.managerId IS NOT NULL ) SELECT * FROM UserCTE AS u where u.ManagerId=3 ORDER BY EmpLevel
Please help me on this
โ10-04-2023 07:47 AM
recursive CTE is not supported in spark. but there is a workaround using python:
https://medium.com/@24chynoweth/recursive-cte-on-databricks-2ac0dff8ca06
โ10-06-2023 12:18 AM
Thanks for update .
We have frame work restrictions in databricks in my organisation and we need to use only scala code
โ10-06-2023 12:58 AM
the code is easily translated to scala.
There is nothing python specific about it.
a week ago
Did you find a solution? I have an almost identical CTE query to pull employee hierarchy info and I am receiving the same error
a week ago
It is still not supported. Not sure when it will be (if ever).
a week ago
Weirdly, if you ask the Databricks assistant, it tells you it does support recursive CTE and will give you sample code for it. If you follow up and press it on details it doubles down and says it supports it, but tell you the runtime version information.
I'm wondering if support is in development.