有没有办法遍历完整的 Databricks notebook (pySpark)?

Is there a way to loop through a complete Databricks notebook (pySpark)?

举个例子。我正在处理一个大型数据集,并希望每周对我的治疗进行减量。我的进程现在分为多个块/命令。

我的问题是,是否可以在所有笔记本上循环,或者我应该将所有 code/treatment 重新组合在同一个块中?

例如,在 2021 年 1 月工作。我想每周制作代码 运行,给他 starting date,运行ning 从这个日期到 day+7,应用所有处理并存储结果,从 day+8 更新我的 start 变量,直到它达到固定的限制,例如 31-1 月。

有没有办法在不将所有代码重新组合到同一个块中的情况下做到这一点?作为 « run all above // all below 行中的命令 ? »

您可以通过更改您的笔记本以通过 widgets, and then you can trigger this notebook, for example, as Databricks job or using dbutils.notebook.run from another notebook that will implement loop (doc 接受参数来实现这一点),将必要的日期作为参数传递。

这将是:

  • 在你原来的笔记本中:
starting_date = dbutils.widgets.get("starting_date")
.... your code
  • 在调用笔记本中(60 是超时,可能会更高,具体取决于转换量):
dbutils.notebooks.run("path_to_orginal_notebook", 60, 
   {"starting_date": "2021-01-01"})