需要帮助编写PySpark Azure Databricks中的CTE递归,格式如下SQL。

huangapple go评论157阅读模式
英文:

needs assistance in writing cte recursive in py spark azure databricks which is in below sql format

问题

  1. WITH RECURSIVE dates(dt) AS
  2. (
  3. SELECT to_date('2023-03-05') - 181 as dt
  4. UNION ALL
  5. SELECT dt + 1
  6. FROM dates d
  7. WHERE d.dt < to_date('2023-03-05')
  8. )

我已经尝试了下面的SQL代码在SQL框架中,但在Databricks中无法工作。

  1. WITH RECURSIVE dates(dt) AS
  2. (
  3. SELECT to_date('2023-03-05') - 181 as dt
  4. UNION ALL
  5. SELECT dt + 1
  6. FROM dates d
  7. WHERE d.dt < to_date('2023-03-05')
  8. )
英文:
  1. WITH RECURSIVE dates(dt) AS
  2. (
  3. SELECT to_date(&#39;2023-03-05&#39;) -181 as dt
  4. UNION ALL
  5. SELECT dt + 1
  6. FROM dates d
  7. WHERE d.dt &lt; to_date(&#39;2023-03-05&#39;)
  8. )

I have tried with below code under sql frame work its not working in databricks

  1. WITH RECURSIVE dates(dt) AS
  2. (
  3. SELECT to_date(&#39;2023-03-05&#39;) -181 as dt
  4. UNION ALL
  5. SELECT dt + 1
  6. FROM dates d
  7. WHERE d.dt &lt; to_date(&#39;2023-03-05&#39;)
  8. )

答案1

得分: 0

Apache Spark不支持原生递归CTE语法。您可以使用Jira SPARK-24497来跟踪状态。

在它被实现之前,您需要使用一些解决方法,如在以下文章中描述的 - 您可以结合使用常规CTE和联合。

英文:

Apache Spark doesn't support native recursive CTE syntax. You can track the status using the SPARK-24497 Jira.

Until it's implemented you will need to use some workarounds, like, described in the following article - where you can do a combination of normal CTE and unions.

huangapple
  • 本文由 发表于 2023年6月27日 18:20:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76563880.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定