QuestionQ210

VerifiedDeveloping Code for Data Processing using Python and SQL

An upstream system is configured to pass the date for a particular data batch to the Databricks Jobs API as a parameter. The scheduled notebook will use that parameter to load data with the following code:

df = spark.read.format("parquet").load(f"/mnt/source/(date)")  

Which code block should create the date Python variable used in the preceding code block?

Explanation

Databricks notebook-task parameters are accessed by name through dbutils.widgets.get. Defining dbutils.widgets.text("date", "null") supplies a default widget value, and dbutils.widgets.get("date") retrieves the value passed by the job as the date string. This value can be interpolated into the Parquet source path.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!