【发布时间】:2019-11-07 11:35:41
【问题描述】:
我正在使用 Airflow、Databricks 和 PySpark。我想知道当我想通过 Airflow 执行 Databricks Notebook 时是否可以添加更多参数。
我在 Python 中编写了名为 MyETL 的下一个代码:
def main(**kwargs):
spark.sql("CREATE TABLE {0} {1}".format(table, columns))
print("Running my ETL!")
if __name__== "__main__":
main(arg1, arg2)
我想定义其他任务参数来运行具有更多参数的 Databricks 笔记本,我想添加方法的名称以及这些方法的参数。例如,当我想在 Airflow 中的 DAG 中注册任务时:
notebook_task_params = {
'new_cluster': new_cluster,
'notebook_task': {
'notebook_path': '/Users/airflow@example.com/MyETL',
'method_name': 'main',
'params':'[{'table':'A'},{'columns':['a', 'b']}]'
},
}
我不知道这是否可能,因为我没有找到类似的例子。
# Example of using the JSON parameter to initialize the operator.
notebook_task = DatabricksSubmitRunOperator(
task_id='notebook_task',
dag=dag,
json=notebook_task_params)
换句话说,我想使用 Airflow 执行带有参数的笔记本。我的问题是我该怎么做?
【问题讨论】:
标签: python apache-spark airflow databricks