Forum Discussion
Temp views don't work when selecting tables with a schema name using Spark SQL
I created a new temporary view using Spark SQL. Code is below
Then, I got this error:
"ErrorHi homanz ,
Thanks for reaching out to Microsoft Fabric Community.At the moment, this appears to be the current behavior of Spark SQL in schema enabled Lakehouses rather than an issue that can be resolved through an immediate hotfix. The PySpark approach you identified is currently the recommended workaround.
Microsoft has also indicated that schema enabled Lakehouses in Spark still have some limitations, with additional support and improvements expected to roll out gradually over the coming months.
Lakehouse Schemas (Generally Available) - Microsoft Fabric Community
For more details: Spark views in lakehouses - Microsoft Fabric | Microsoft Learn
You may also consider raising this as an enhancement request through the Fabric Ideas - Microsoft Fabric Community so the product team can review and prioritize support for this scenario in future updates.
Hope this helps. Please reach out for further assistance.
Thank you.
6 Replies
- deborshi_nagSuper User
Hello homanz
Fabric relies on an internal session database for Spark session and lakehouse binding. If you run SELECT current_database() as current_db, you'll notice a temporary database name appears.
To resolve this, always use a four-part name with backticks—`<Your Workspace Name>`.Lakehouse.Schema.Table—when referencing tables. You can find your schema's namespace by running the SQL below and checking the "namespace" column.
SHOW TABLES in IM; - ati_puriResolver III
HI homanz ,
These are known issues and solution have bene provided in this Fabric Community before for the same issue. Pls find the link here: Solved: Re: Issue with SparkSQL Schema Behavior in Fabric - Microsoft Fabric Community
For more details on information around Lakehouse Schema behaviour, pls find the link below.
Lakehouse schemas - Microsoft Fabric | Microsoft Learn
Thanks
Ati Puri
- homanzAdvocate I
Hi ati_puri and deborshi_nag, thanks both for your sugguestion.
Using the schema name works only for joining tables within a single schema, but we have tables from different schemas. So, this solution won’t work for us.
Using the full four-part table name also works, but we have to parameterise the workspace name in all our SQL code for CI/CD deployment, which makes the code very messy and hard to read.
One solution I found is to wrap the SQL code in the PySpark createOrReplaceTempView function. It’s surprising that PySpark can somehow resolve all the schema names from different tables, but SparkSQL cannot.
%%pysparkspark.sql("""--insert SQL code belowSELECT*fromIM.test t1left joinref.testref t2on t1.key= t2.key""").createOrReplaceTempView("tmp_python_view")Do you know if this issue will be fixed by MS soon?
- v-veshwara-msftCommunity Support
Hi homanz ,
Thanks for reaching out to Microsoft Fabric Community.At the moment, this appears to be the current behavior of Spark SQL in schema enabled Lakehouses rather than an issue that can be resolved through an immediate hotfix. The PySpark approach you identified is currently the recommended workaround.
Microsoft has also indicated that schema enabled Lakehouses in Spark still have some limitations, with additional support and improvements expected to roll out gradually over the coming months.
Lakehouse Schemas (Generally Available) - Microsoft Fabric Community
For more details: Spark views in lakehouses - Microsoft Fabric | Microsoft Learn
You may also consider raising this as an enhancement request through the Fabric Ideas - Microsoft Fabric Community so the product team can review and prioritize support for this scenario in future updates.
Hope this helps. Please reach out for further assistance.
Thank you.