Forum Discussion
%%tsql magic in spark notebook
- 7 months ago
HI woldea ,
You can use Spark Synapse SQL connector for your usecase.
adding same code for your reference.
# IMPORTSimport com.microsoft.spark.fabric
from com.microsoft.spark.fabric.Constants import Constants
# Code
spark.read.option(Constants.DatabaseName, "<warehouse/lakeshouse name>").synapsesql("<T-SQL Query>")
You can these docs for refernce.
https://learn.microsoft.com/en-us/fabric/data-engineering/spark-data-warehouse-connector?tabs=pyspark
Hope this helps. Let me know if you have any other questions.
Hello woldea
You're not meant to mix Spark and TSQL. If you're applying transformations in a Lakehouse, you can use a Spark notebook with %%pyspark or %%sql magic commands.
On the other hand, if you're applying transformation into a Warehouse, you can use a Python notebook with %%tsql magic command.