AirFlow DatabricksSubmitRunOperator不接受笔记本参数

时间:2020-05-01 12:37:00

标签: airflow databricks azure-databricks

我正在尝试从Airflow触发笔记本电脑。笔记本的参数定义为小部件,我试图通过notebook_params参数将值传递给它,尽管它触发了,但是当我查看提交的作业时,似乎没有传递参数。

例如代码

new_cluster = {'spark_version': '6.5.x-cpu-ml-scala2.11',
                        'node_type_id': 'Standard_DS3_v2',
                        'num_workers': 4
                        }

notebook_task = DatabricksSubmitRunOperator(task_id='notebook_task',
             json={'new_cluster': new_cluster,
                                'notebook_task': {
                                    'notebook_path': '/Users/abc@test.com/Demo',
                                    'notebook_parameters':'{"fromdate":"20200420","todate":"20200420", "datalakename":"exampledatalake", "dbname": "default", "filesystem":"refined" , "tablename":"ntcsegmentprediction", "modeloutputpath":"curated"}'
                                },
                            })

但是,DatabricksRunNowOperator支持它,并且可以运行

notebook_run = DatabricksRunNowOperator(task_id='notebook_task',
            job_id=24,
            notebook_params={"fromdate":"20200420","todate":"20200420", "datalakename":"exampledatalake", "dbname": "default", "filesystem":"refined" , "tablename":"ntcsegmentprediction", "modeloutputpath":"curated"}
        )

here中的DatabricksSubmitRunOperator的文档和源代码中

它说它可以接受notebook_task。如果可以,请不确定为什么不能接受参数

我想念什么?

如果需要更多信息,我也可以提供。

2 个答案:

答案 0 :(得分:2)

您应该使用base_parameters而不是notebook_params

https://docs.databricks.com/dev-tools/api/latest/jobs.html#jobsnotebooktask

答案 1 :(得分:1)

要将它与 DatabricksSubmitRunOperator 一起使用,您需要将其添加为 json 参数中的额外参数:ParamPair

notebook_task_params = {
    'new_cluster': cluster_def,
    'notebook_task': {
        'notebook_path': 'path',
        'base_parameters':{
            "param1": "**",
            "param2": "**"}            
    }   
}
notebook_task = DatabricksSubmitRunOperator(
    task_id='id***',
    dag=dag,
    trigger_rule=TriggerRule.ALL_DONE,
    json=notebook_task_params)

然后您可以使用 dbutils.widgets.get 来检索值或设置默认值。

param1 = getArgument("param1", "default")
param2 = getArgument("param2", "default")

getArgument > (DEPRECATED) 等价于 get