Forum Discussion

UdaySutar's avatar
UdaySutar
Frequent Visitor
1 year ago
Solved

Read view data using notebook

We are seeking to use a view within a SQL analytics Endpoint as a source of data for a dataframe in a notebook. When we seek to query it, we see an error like  [TABLE_OR_VIEW_NOT_FOUND] code lo...
  • nilendraFabric's avatar
    1 year ago

    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")

  • V-yubandi-msft's avatar
    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.