The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello Microsoft Fabric Community,
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: (Notebook works correctly for dbo)
------------------------------------------------------------------------------Remove Columns with complete NULLs in schema-------
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] > 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() > 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)}")
----------------------
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: ( I have changed to other schemas with the same results)
[SCHEMA_NOT_FOUND] The schema `Salesforce_Lakehouse.SOQL` cannot be found. Verify the spelling and correctness of the schema and catalog.
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.
I’d appreciate guidance on:
Thank you in advance for your help!
Solved! Go to Solution.
If the above information helps you, please give us a Kudos and marked the reply as a solution.
Thanks,
Cheri Srikanth
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.
Thank you.
If the above information is helpful, please give us Kudos and mark the response as Accepted as solution.
Best Regards,
Community Support Team _ C Srikanth.
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?
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!
Looking forward to your reply!
Best Regards,
Community Support Team _ C Srikanth.
Hi @goldenarm253
Sorry for the late response.
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?
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.
Looking forward to your response!
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 welcome to start a new thread in the community at any time.
We appreciate your understanding and participation.
Best Regards,
Cheri Srikanth
If the above information helps you, please give us a Kudos and marked the reply as a solution.
Thanks,
Cheri Srikanth