简体   繁体   中英

How do you use either Databricks Job Task parameters or Notebook variables to set the value of each other?

The goal is to be able to use 1 script to create different reports based on a filter.

I want my Databricks Job Task parameters and Notebook variables to share the same value for filtering purposes.

This is how I declared these widgets and stored in a variable:

 dbutils.widgets.text(name='field', defaultValue='', label='field') f1= dbutils.widgets.get('field')

任务参数设置

There are two methods to use with widgets [.text() +.get()]. One to create the widget the first time and one to grab the value from the widget.

Here is some sample screen shots from a class I teach.

在此处输入图像描述

The.text method creates the widget and sets the value. It only has to be executed once. It can be commented out afterwards. This has to be recreated if you move the code from one Databricks workspace to another.

In this example, I have a notebook that reads a csv file and performs a full load of a delta table. The source file, destination path, debug flag, file schema and partition count as passed as parameters.

在此处输入图像描述

I am using the adventure works data files.

在此处输入图像描述

The parent notebook calls the child notebook 15 times to load and create hive tables for the adventure works schema.

The same can be done for report file creation. I hope this explains and shows how to use widgets effectively and call a notebook using the dutils.notebook.run() method.

You can translate the.run() method calls to tasks in a databricks job. What I do not like is the interface. There is a lot of clicking and entering vs cut/paste when using a notebook. I guess you can use the JSON tab to the right.

To be honest, I usually use ADF for scheduling since most of my clients data is hybrid in nature.

Here is a screen shot of a sample job with at task to load the accounts hive table.

在此处输入图像描述

Last but not least, the job runs to success.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM