cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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! 

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.