Forum Discussion
How to properly refresh Lakehouse SQL endpoint?
- 11 months ago
Instead of hardcoding table names, query the catalog for all tables in a given schema and loop through them.
from pyspark.sql import SparkSession # create Spark session spark = SparkSession.builder \ .appName("Refresh Lakehouse SQL Endpoint") \ .getOrCreate() # define schema name schema_name = "dbo" # get all tables in schema tables_df = spark.sql(f"SHOW TABLES IN {schema_name}") tables = [row.tableName for row in tables_df.collect()] # refresh each table for table in tables: print(f"Refreshing table {schema_name}.{table} ...") spark.sql(f"REFRESH TABLE {schema_name}.{table}") print(f"Metadata refresh completed for schema: {schema_name}")If you are running this right after data ingestion, you need to wait until write jobs finish.
If ingestion is done within the same notebook, make sure to call spark.catalog.clearCache() to avoid stale metadata. But if its asynchronous consider implementing a checkpoint/audit table to track job completion and trigger refresh only after proper validation thtat the data has been landed.Pls note that the REFRESH TABLE refreshes only the metadata, it does not reload the data unless there are structural changes. You can also force query compilation reset if you want (spark.catalog.refreshTable) but for heavy pipelines, limit the refresh to only the tables that has been changed.
- Ingest data into Lakehouse.
- Validate ingestion completion (checkpoint or audit).
- Run REFRESH TABLE dynamically for all tables in schema
- Validate row counts.
- Trigger stored procedure executions.
Please 'Kudos' and 'Accept as Solution' if this answered your query.
so when w perform incrmental loads, our pipeline timings are scheduled to run in such a way it overlaps with each others timings we cannot seggregate it, we can consider that all lakehouse tables keeps on reloading data that means we cannot call that API ones for all the lakehouse table in that way we need to call it again and again whenever a pipeline is at lakehouse data load step and I dont think an API can run multiple instances, that is why we want to run lakehouse table refresh at a time for particular pipeline that are related to lakehouse tables and refresh those only, if we cannot specifiy table level details in an API, then it will be no go for us at this point of time.
"and I dont think an API can run multiple instances"
Have you tried it?
(I haven't, but I would try it before writing it off).
Or you can decide to refresh the SQL Analytics Endpoint only on the last pipeline, if you are concerned about refreshing the SQL Analytics Endpoint too often.
You can also create an Idea for this feature. Also, you can ask on Microsoft Fabric on Reddit.
- AnmolGan8111 months agoAdvocate II
I have seen that behaviour with various MS refresh API's, anyways we dont know if it will work, but if it did the we dont want to keep on calling refresh api again and again in all the pipelines, we are looking for a seggregated approach here as per our architecture.
- v-aatheeque11 months agoCommunity Support
Hi AnmolGan81
Thanks for sharing your inputs. As the frithjof_v mentioned, running multiple instances of the refresh API isn’t currently supported, and the recommended path is to post this as an idea in the New Idea - Microsoft Fabric Community so the product team can review it.