Forum Discussion
Can we create views in Lakehouse's SQL Endpoint using Fabric Apis?
Hi senthilkannan ,
This is the table I have stored inside lakehouse.
Using PySpark, you can create views in Fabric Lakehouse and then view it inside the SQL endpoint.
from pyspark.sql import SparkSession
# create Spark session
spark = SparkSession.builder \
.appName("Create View in Lakehouse") \
.getOrCreate()
# load data and name column header
df = spark.read.format("csv").option("header", "true").load("Files/products.csv")
# select column and create view
df.select("Month").write.mode("overwrite").saveAsTable("test_view1")
print("create success!")
After running the above code successfully, go to the corresponding SQL endpoint in lakehouse and refresh it to view the view.
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
Anonymous I think the code you provided creates a table, not view.
Also, I don't think you need to create the Spark session in the code, as sessions are managed by Fabric.
However I don't know the answer to the original question - how to create a view in SQL Analytics Endpoint via Fabric API.
senthilkannan could you explain more about why you wish to create views by using Fabric API?
Perhaps you can use jdbc or pyodbc. I'm not experienced with either of them.
Or perhaps you can use the run pipeline API or run notebook API. These API's are currently only in preview status.
The SQL Analytics Endpoint has a SQL connection string so you can connect from client applications like SSMS.