Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2022 01:06 AM
You can use {} in spark.sql() of pyspark/scala instead of making a sql cell using %sql.
This will result in a dataframe. If you want you can create a view on top of this using createOrReplaceTempView()
Below is an example to use a variable:-
# A variable
var = "Hello World"
# Using f in pyspark spark.sql.
spark.sql(f""" SELECT '{var}' AS Message """)
# Using format
spark.sql(""" SELECT '{}' AS Message """.format(var))