cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Can assign a default value for job parameter from the widget?

fuselessmatt
Contributor

The Databricks widget (dbutils) provides the get function for accessing the job parameters of a job.​

dbutils.widgets.get('my_param')

Unlike Python dict, where get returns None or an optional argument if the dict doesn't contain the parameter, the widget get will raise an error if there is no such parameter. The benefit of this design I guess is to promote failing early.

However, if you want an optional parameter in a PySpark script, is there a better way to implement this than to try to catch this error and defaulting from there? I noticed that there is a deprecated getArgument that does exactly this. However it is deprecated.

It also says that it is equivalent to get, but this is clearly not true as getArgument has the option of a default value.

dbutils.widgets.help()
get(name: String): String -> Retrieves current value of an input widget
getArgument(name: String, optional: String): String -> (DEPRECATED) Equivalent to get
 
test = dbutils.widgets.getArgument('test2', 'bla2')
print(test)

That seems like a bug.

2 REPLIES 2

pvignesh92
Honored Contributor

@Mattias P​ Hi. You can set the default parameter while giving dbutils.widgets.text('my_param',default_Value).

Anonymous
Not applicable

Hi @Mattias P​ 

Thank you for posting your question in our community! We are happy to assist you.

To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?

This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance! 

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!