<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Issue with Accessing Tables from Non-dbo Schema in Microsoft Fabric Using PySpark in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4737864#M10296</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="682804" data-lia-user-login="goldenarm253" class="lia-mention lia-mention-user"&gt;goldenarm253&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Sorry for the late response.&lt;BR /&gt;I wanted to follow up since I haven't heard from you in a while. Have you had a chance to try the suggested solutions?&lt;BR /&gt;If your issue is resolved, please consider marking the post as solved. However, if you're still facing challenges, feel free to share the details, and we'll be happy to assist you further.&lt;BR /&gt;Looking forward to your response!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As per Microsoft community guidelines, we will now proceed to close this thread to keep discussions focused and manageable. If you still need assistance, you're &lt;STRONG&gt;welcome to start a new thread in the community at any time.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;We appreciate your understanding and participation.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Cheri Srikanth&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jun 2025 16:00:05 GMT</pubDate>
    <dc:creator>v-csrikanth</dc:creator>
    <dc:date>2025-06-19T16:00:05Z</dc:date>
    <item>
      <title>Issue with Accessing Tables from Non-dbo Schema in Microsoft Fabric Using PySpark</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4347213#M5834</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hello Microsoft Fabric Community,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I am currently working on a data engineering task in Microsoft Fabric that involves retrieving and processing tables from a specific schema in a Lakehouse. While my PySpark script works perfectly when the source schema is dbo, it fails when attempting to retrieve tables from a schema other than dbo. Here’s a breakdown of the issue: (&lt;STRONG&gt;Notebook works correctly for dbo)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;------------------------------------------------------------------------------Remove Columns with complete NULLs in schema-------&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from pyspark.sql.functions import col, sum as _sum
from pyspark.sql.utils import AnalysisException

# Step 1: Retrieve all table names from the SOQL schema in Salesforce_Lakehouse
try:
table_list = spark.sql("SHOW TABLES IN Salesforce_Lakehouse.SOQL").select("tableName").rdd.flatMap(lambda x: x).collect()
except AnalysisException as e:
print(f"Error retrieving tables: {str(e)}")
table_list = []

# Step 2: Loop through each table, process, and create non-null columns
for table_name in table_list:
try:
print(f"Processing table: {table_name}")

# Load table data from SOQL schema
df = spark.sql(f"SELECT * FROM Salesforce_Lakehouse.SOQL.{table_name}")

# Identify non-null columns
non_null_columns = [
c for c in df.columns
if df.select(_sum(col(c).isNotNull().cast("int"))).collect()[0][0] &amp;gt; 0
]

# Create a DataFrame with non-null columns
df_non_null = df.select(*non_null_columns)

# Check if the table exists in the Salesforce schema
table_exists = spark.sql(f"SHOW TABLES IN Salesforce_Lakehouse.Salesforce").filter(f"tableName = '{table_name}'").count() &amp;gt; 0

if table_exists:
print(f"Table {table_name} exists in Salesforce schema. Overwriting...")
else:
print(f"Table {table_name} does not exist in Saleforce schema. Creating new table...")

# Write the non-null DataFrame to the Salesforce schema
df_non_null.write.mode("overwrite").saveAsTable(f"Salesforce_Lakehouse.Salesforce.{table_name}")

print(f"Table {table_name} processed and saved successfully.")

except AnalysisException as e:
print(f"Error processing table {table_name}: {str(e)}")
except Exception as e:
print(f"Unexpected error with table {table_name}: {str(e)}")
&lt;/LI-CODE&gt;&lt;P&gt;----------------------&lt;/P&gt;&lt;H4&gt;&lt;STRONG&gt;The Problem&lt;/STRONG&gt;&lt;/H4&gt;&lt;P&gt;The code above works seamlessly when using the dbo schema as the source (e.g., Salesforce_Lakehouse.dbo). However, when I attempt to retrieve tables from a different schema, such as Salesforce_Lakehouse.SOQL, it throws an error indicating that the schema cannot be found: &lt;STRONG&gt;( I have changed to other schemas with the same results)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[SCHEMA_NOT_FOUND] The schema `Salesforce_Lakehouse.SOQL` cannot be found. Verify the spelling and correctness of the schema and catalog.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have verified that the schema exists by running SHOW SCHEMAS;, and I can see the schema listed. However, the script does not seem to retrieve tables unless the schema is dbo.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’d appreciate guidance on:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Why this behavior occurs with non-dbo schemas in Microsoft Fabric.&lt;/LI&gt;&lt;LI&gt;Any potential workarounds or configuration changes to allow the script to work with any schema (not just dbo).&lt;/LI&gt;&lt;LI&gt;Best practices for handling schema-specific access in a Microsoft Fabric Lakehouse.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Thank you in advance for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 31 Dec 2024 12:19:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4347213#M5834</guid>
      <dc:creator>goldenarm253</dc:creator>
      <dc:date>2024-12-31T12:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Accessing Tables from Non-dbo Schema in Microsoft Fabric Using PySpark</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4349196#M5881</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="682804" data-lia-user-login="goldenarm253" class="lia-mention lia-mention-user"&gt;goldenarm253&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;Thank you for being part of the Microsoft Fabric Community.&lt;/DIV&gt;
&lt;DIV&gt;Please find the below workarounds that might helpful to resolve the issue.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;1. Use Dynamic Schema Retrieval:&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;Instead of hardcoding a schema (like dbo), dynamically retrieve all schemas in the Lakehouse and iterate through them:&lt;/DIV&gt;
&lt;DIV&gt;-----------------------------------------------------------------------------------&lt;/DIV&gt;
&lt;DIV&gt;Code changes:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;# Set the catalog to ensure correct context&lt;/DIV&gt;
&lt;DIV&gt;spark.sql("USE CATALOG Salesforce_Lakehouse")&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;# Retrieve all schemas in the catalog&lt;/DIV&gt;
&lt;DIV&gt;schemas = spark.sql("SHOW SCHEMAS IN Salesforce_Lakehouse").select("namespace").rdd.flatMap(lambda x: x).collect()&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;# Iterate through schemas to retrieve tables dynamically&lt;/DIV&gt;
&lt;DIV&gt;for schema in schemas:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; try:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(f"Processing schema: {schema}")&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; table_list = spark.sql(f"SHOW TABLES IN `Salesforce_Lakehouse`.`{schema}`").select("tableName").rdd.flatMap(lambda x: x).collect()&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for table_name in table_list:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(f"Processing table: {schema}.{table_name}")&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; df = spark.sql(f"SELECT * FROM `Salesforce_Lakehouse`.`{schema}`.`{table_name}`")&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # Further processing here&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; except Exception as e:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(f"Error processing schema {schema}: {str(e)}")&lt;/DIV&gt;
&lt;DIV&gt;-----------------------------------------------------------------------------------&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;2. Use a Parameterized Schema:&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;If the schema varies but you know it beforehand, pass the schema as a parameter or an environment variable.&lt;/DIV&gt;
&lt;DIV&gt;-----------------------------------------------------------------------------------&lt;/DIV&gt;
&lt;DIV&gt;import os&lt;BR /&gt;# Example: Pass schema as an environment variable or a parameter&lt;/DIV&gt;
&lt;DIV&gt;schema = os.getenv("TARGET_SCHEMA", "dbo")&amp;nbsp; # Default to 'dbo' if not set&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;# Retrieve tables from the specified schema&lt;/DIV&gt;
&lt;DIV&gt;table_list = spark.sql(f"SHOW TABLES IN `Salesforce_Lakehouse`.`{schema}`").select("tableName").rdd.flatMap(lambda x: x).collect()&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;for table_name in table_list:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; print(f"Processing table: {schema}.{table_name}")&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; df = spark.sql(f"SELECT * FROM `Salesforce_Lakehouse`.`{schema}`.`{table_name}`")&lt;/DIV&gt;
&lt;DIV&gt;-----------------------------------------------------------------------------------&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;3. Set the Default Schema:&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;To set the default schema for the session to simplify queries, especially if working with one schema at a time.&lt;/DIV&gt;
&lt;DIV&gt;-----------------------------------------------------------------------------------&lt;/DIV&gt;
&lt;DIV&gt;# Use the specific schema&lt;/DIV&gt;
&lt;DIV&gt;spark.sql("USE `Salesforce_Lakehouse.SOQL`")&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;# Query tables directly without prefixing schema&lt;/DIV&gt;
&lt;DIV&gt;table_list = spark.sql("SHOW TABLES").select("tableName").rdd.flatMap(lambda x: x).collect()&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;for table_name in table_list:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; print(f"Processing table: {table_name}")&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; df = spark.sql(f"SELECT * FROM `{table_name}`")&lt;/DIV&gt;
&lt;DIV&gt;-----------------------------------------------------------------------------------&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;4. Grant Permissions to Non-dbo Schemas:&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;Ensure the user running the script has the necessary permissions for all schemas.&lt;/DIV&gt;
&lt;DIV&gt;-----------------------------------------------------------------------------------&lt;/DIV&gt;
&lt;DIV&gt;SQL Commands to Grant Permissions:&lt;/DIV&gt;
&lt;DIV&gt;GRANT USAGE ON SCHEMA `Salesforce_Lakehouse`.`SOQL` TO &amp;lt;user&amp;gt;;&lt;/DIV&gt;
&lt;DIV&gt;GRANT SELECT ON ALL TABLES IN SCHEMA `Salesforce_Lakehouse`.`SOQL` TO &amp;lt;user&amp;gt;;&lt;/DIV&gt;
&lt;DIV&gt;-----------------------------------------------------------------------------------&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;&lt;STRONG&gt;If the above information helps you, please give us a Kudos and marked the reply as a solution.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;Cheri Srikanth&lt;/P&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 03 Jan 2025 04:17:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4349196#M5881</guid>
      <dc:creator>v-csrikanth</dc:creator>
      <dc:date>2025-01-03T04:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Accessing Tables from Non-dbo Schema in Microsoft Fabric Using PySpark</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4737864#M10296</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="682804" data-lia-user-login="goldenarm253" class="lia-mention lia-mention-user"&gt;goldenarm253&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Sorry for the late response.&lt;BR /&gt;I wanted to follow up since I haven't heard from you in a while. Have you had a chance to try the suggested solutions?&lt;BR /&gt;If your issue is resolved, please consider marking the post as solved. However, if you're still facing challenges, feel free to share the details, and we'll be happy to assist you further.&lt;BR /&gt;Looking forward to your response!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As per Microsoft community guidelines, we will now proceed to close this thread to keep discussions focused and manageable. If you still need assistance, you're &lt;STRONG&gt;welcome to start a new thread in the community at any time.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;We appreciate your understanding and participation.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Cheri Srikanth&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jun 2025 16:00:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4737864#M10296</guid>
      <dc:creator>v-csrikanth</dc:creator>
      <dc:date>2025-06-19T16:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Accessing Tables from Non-dbo Schema in Microsoft Fabric Using PySpark</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4741196#M10378</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="682804" data-lia-user-login="goldenarm253" class="lia-mention lia-mention-user"&gt;goldenarm253&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's been a while since I heard back from you and I wanted to follow up. Have you had a chance to try the solutions that have been offered? &lt;BR /&gt;If the issue has been resolved, can you mark the post as resolved? If you're still experiencing challenges, please feel free to let us know and we'll be happy to continue to help!&lt;BR /&gt;Looking forward to your reply!&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Community Support Team _ C Srikanth.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jun 2025 16:36:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4741196#M10378</guid>
      <dc:creator>v-csrikanth</dc:creator>
      <dc:date>2025-06-23T16:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Accessing Tables from Non-dbo Schema in Microsoft Fabric Using PySpark</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4746100#M10455</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="682804" data-lia-user-login="goldenarm253" class="lia-mention lia-mention-user"&gt;goldenarm253&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We haven't heard from you since last response and just wanted to check whether the solution provided has worked for you. If yes, please Accept as Solution to help others benefit in the community.&lt;BR /&gt;Thank you.&lt;/P&gt;
&lt;P&gt;If the above information is helpful, please give us Kudos and mark the response as Accepted as solution.&lt;BR /&gt;Best Regards,&lt;BR /&gt;Community Support Team _ C Srikanth.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jun 2025 07:00:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Accessing-Tables-from-Non-dbo-Schema-in-Microsoft/m-p/4746100#M10455</guid>
      <dc:creator>v-csrikanth</dc:creator>
      <dc:date>2025-06-27T07:00:42Z</dc:date>
    </item>
  </channel>
</rss>

