Forum Discussion
Read view data using notebook
- 1 year ago
Try this
import com.microsoft.spark.fabric.tds.implicits.read.FabricSparkTDSImplicits._
import com.microsoft.spark.fabric.Constantst_sql_query = """
SELECT * FROM your_view_name
"""wsid = spark.conf.get("ws_id")
lh_name = spark.conf.get("lh_name")df = spark.read.option(Constants.WorkspaceId, wsid).option(Constants.DatabaseName, lh_name).synapsesql(t_sql_query)
df.createOrReplaceTempView("view_data")
- 1 year ago
Hi UdaySutar ,
It appears that this approach might not work as expected because views created in a SQL Analytics Endpoint aren’t visible on the Lakehouse side. The metadata sync only happens from the Lakehouse to the SQL Endpoint, not the other way around.
As an alternative,
1. Use a JDBC connector in your notebook to directly query the view from the SQL Endpoint, or
2. Recreate the view within the Lakehouse using Spark so that it becomes accessible in your notebook.
If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
Try this
import com.microsoft.spark.fabric.tds.implicits.read.FabricSparkTDSImplicits._
import com.microsoft.spark.fabric.Constants
t_sql_query = """
SELECT * FROM your_view_name
"""
wsid = spark.conf.get("ws_id")
lh_name = spark.conf.get("lh_name")
df = spark.read.option(Constants.WorkspaceId, wsid).option(Constants.DatabaseName, lh_name).synapsesql(t_sql_query)
df.createOrReplaceTempView("view_data")