Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2024 08:30 PM
Hi ,
The dbutils.widgets.text() function in Databricks takes three positional arguments. They are:
- name: The programmatic name of the text widget.
- defaultValue: The default value of the text widget.
- label: An optional label for the text widget.
From the above code you are trying to pass a default value, and you are already passing a value to widget var1, that's why the code always returns 'Hello'.
I am not aware of a way to directly manipulate the value of widget, but the below code can help you to take the value from widget and then modify and use in the SQL.
# Get the parameters
dbutils.widgets.text('param1',"Hello") #Default value as Hello
param1 = dbutils.widgets.get("param1")
# Printing value of param1
print(f"Parameter 1: {param1}")
#manupualting the value using python
param1=param1+' World!'
print(param1)
#defining spark varaiable with value of modified variable param1
spark.sql(f"set param1.var='{param1}'")
--------------
%sql
SELECT cast(${param1.var} as string)
Harshit Kesharwani
Data engineer at Rsystema
Data engineer at Rsystema