cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

MS Fabric Direct Lake, works with delta tables only?

dbernstein_tp
Contributor III

Lately we started using Direct Lake to use the results of our ingestion pipelines (gold tables) in PBI dashboards. This is working ok but has one annoying and troublesome issue. Which is: the gold tables are the end result of declarative pipelines so they are materialized views. However DL does not currently work with MVs so we added an extra step that copies the views to delta tables That works but the extra table copying a) is expensive, b) adds additional minutes to the ingestion->cleaning->aggregation job, and c) appears to create issues with Fabric and DL with the larger tables (50 M rows) in terms of them being overwritten so frequently (in one critical case every 15 minutes).

Is this pattern the only way to get this to work? How are other people handling this situation? I feel like I'm missing something here...

23 REPLIES 23

SumeshKashyap
Valued Contributor III

Hi @dbernstein_tp 

You're not missing anything on the first part: Direct Lake needs a plain Delta table, and Fabric's Azure Databricks mirroring explicitly doesn't support materialized views or streaming tables. So some copy step is unavoidable for now. What you can fix is how the copy is done. A full overwrite of 50M rows every 15 minutes rewrites every file, which is what makes it slow and expensive and makes Direct Lake throw away its cache each time. Switch to an incremental MERGE so only changed files get rewritten.

1. Replace the overwrite with a MERGE that only touches rows that actually changed:

MERGE INTO gold_dl.sales t

USING gold.sales_mv s

ON t.id = s.id

WHEN MATCHED AND t.row_hash <> s.row_hash THEN UPDATE SET *

WHEN NOT MATCHED THEN INSERT *

WHEN NOT MATCHED BY SOURCE THEN DELETE;

(row_hash = xxhash64 or sha2 over the non-key columns, computed in the MV.) Reading the MV is cheap. The win is that unchanged files are left alone, so Direct Lake reframes as a metadata-only operation and keeps the column segments for unchanged data in memory, instead of re-transcoding the whole table. If the table is date-partitioned and only recent data changes, INSERT INTO ... REPLACE WHERE date >= current_date() - 2 is even cheaper.

2. Run it as a task right after the pipeline update in the same job, so it only runs when the MV actually refreshed.

3. Keep VACUUM retention on the copy table well above your refresh interval (the 7-day default is fine; don't lower it). Direct Lake reads the exact parquet files from its last framing, so vacuuming them too early is a common cause of the errors you're seeing on the big table after frequent overwrites.

Two alternatives, depending on the use case:

- If a gold table is append-only, write it from the pipeline straight into a regular Delta table with a sink (dp.create_sink plus an append flow) and skip the copy entirely.

- For dashboards that don't need Direct Lake speed, Power BI DirectQuery through the Databricks connector against a SQL warehouse reads MVs directly, with no copy. YOu can even build metric views which  are similar to semantic models

This is the only alternate approach I could apply 

Thanks. I looked at MERGE INTO but it seemed extremely compute intensive and slow but I didn't do the hashing thing above so it was comparing every column in every row over the whole table.

We did try Direct Query but the PBI developers complained that it was too slow.

The gold tables are the results of complex queries on the cleaned data. A few of them just append rows but most are essentially snapshots of complex aggregations of the cleaned data.

@SumeshKashyap Should I be worried about hash collisions using this approach? Some of the tables needed for this have 50+ columns.

Hi @dbernstein_tp, no real worry. The hash is only compared for the same key (old vs new version of one row), not across the table, so with xxhash64 the odds of a missed update are about 1 in 10^19 per row, and 50+ columns doesn't change that. One gotcha: xxhash64 skips nulls, so (null, 1) and (1, null) hash the same. If you want zero doubt, use sha2(to_json(struct(<non-key cols>)), 256), which is null- and position-safe.

On MERGE cost: with the hash it compares one column instead of 50+, and since most rows in a snapshot aggregate don't change between runs, only files holding changed rows get rewritten. Also cluster the target on the merge key (CLUSTER BY id) so MERGE prunes files instead of scanning the whole table.

albert64chase
New Contributor II

No, you don't need a manual copy pipeline. Microsoft Fabric features Materialized Lake Views (MLVs), which natively persist transformation outputs directly as Delta tables in OneLake. Transitioning away from full-table overwrites every 15 minutes which cause severe Delta log bloat and performance degradation on large datasets to MLVs allows the platform to manage the Delta storage natively and handle updates more efficiently, eliminating the extra copy step and reducing resource strain.

Thanks for your response. I had not heard of MLVs. Do you have real world experience with getting this to work? I would like to hear more details about it.

Apparently these mirrored catalogs are part of the Direct Lake set up so in effect they are already in use here.

Aravind_Reddy
Databricks Partner

One approach worth exploring is whether you can eliminate the extra copy by exposing the Databricks gold tables to Fabric through the Mirrored Azure Databricks Catalog feature, then using Direct Lake against the supported mirrored tables.
If the current limitation is specifically around Lakeflow Materialized Views, I would first verify whether the MV results can be consumed through this integration in your environment. Fabric's Direct Lake support depends on the source type and integration path, so I wouldn't assume that every Databricks MV is directly supported.

If the MV itself cannot be consumed, another option is to maintain a physical Delta gold table as the pipeline output rather than materializing the MV and copying its results afterward. use physical Gold Delta tables in Databricks instead of Materialized Views.
For example, maintain curated tables such as gold.fact_sales and gold.dim_customer in Unity Catalog, then use Fabric's Mirrored Azure Databricks Catalog integration to expose supported tables to Power BI through Direct Lake.
This could eliminate the additional data-copying step and reduce refresh overhead. For tables updated every 15 minutes, incremental MERGE or append-based processing may also be more efficient than repeatedly overwriting 50M rows.
The Gold tables are supported by the chosen Fabric integration and Direct Lake mode. Gold-layer Delta tables stored in OneLake (inside a Fabric Lakehouse) are the primary and recommended source for Direct Lake semantic models. Direct Lake reads the underlying Delta/Parquet files directly from OneLake into the VertiPaq memory of Power BI without requiring an import copy or full data refresh cycles.

Louis_Frolio
Databricks Employee
Databricks Employee

Hello dbernstein_tp, I took a look at both internal and external documentation and here is what I found.

You're not missing anything. The Fabric Mirrored Azure Databricks Catalog item (including the newer Publish to OneLake button in Catalog Explorer) only mirrors regular Unity Catalog managed and external Delta tables. Views, materialized views, and streaming tables are all on the unsupported list. Aravind_Reddy's advice to serve Fabric from physical gold tables is the right call; mirroring the catalog alone won't surface a Databricks MV, and the Fabric Materialized Lake View suggestion is a Fabric-side pattern, not a way to expose the Databricks object.

The why matters here. A Lakeflow Spark Declarative Pipelines MV is Delta-backed, but its underlying files can carry extra data from upstream tables to support incremental refresh, so only Databricks compute reads them correctly. A plain Delta serving table is still required today. Three things make that less painful than what you have now.

Compatibility Mode (Public Preview). This is Databricks doing the copy for you. Two table properties on the MV definition and Databricks maintains a read-only, plain Delta version at an external location you choose.

CREATE OR REFRESH MATERIALIZED VIEW gold.my_mv
TBLPROPERTIES (
  'delta.universalFormat.enabledFormats' = 'compatibility',
  'delta.universalFormat.compatibility.location' = 'abfss://<container>@<account>.dfs.core.windows.net/<empty-path>'
) AS SELECT ...

For MVs the copy refreshes after each update with new commits and runs on Predictive Optimization compute, so it comes off your pipeline's critical path. Point an ADLS Gen2 shortcut at that location and build Direct Lake on OneLake on it. Caveats: you still pay storage plus the Predictive Optimization DBUs, and the compatibility version has no time travel or change data feed. I haven't confirmed the mirrored catalog item picks these up, so use a plain ADLS shortcut, and test refresh behavior on the 50M-row table before committing. You may also see "external data access for pipeline datasets," the no-copy option; skip it, since the docs state reading from Microsoft Fabric is not supported.

Fix the copy you already have. A CREATE OR REPLACE every 15 minutes rewrites every Parquet file. Direct Lake only drops column segments during framing that belong to removed row groups, so when every row group is removed, every query after that framing starts cold and transcodes 50M rows again. That's very likely the trouble you're seeing. Replace the overwrite with a MERGE or a partition-scoped replacement on the affected keys or dates. SumeshKashyap's row fingerprint idea cuts the cost of all-column comparisons, though it's change detection, not a correctness guarantee. Use WHEN NOT MATCHED BY SOURCE THEN DELETE only when the source is a complete, authoritative snapshot and deletes are intended. If most of the 50M rows change every 15 minutes, MERGE may still be heavy; make the aggregation incremental, publish only affected groups, or relax the cadence. Cluster the target on the merge keys, benchmark with Photon rather than assuming, and keep the file count low with OPTIMIZE.

Take Direct Lake out of the picture for these tables. The Fabric limitations don't apply when you use Power BI DirectQuery against Unity Catalog data, and MVs are first-class on a Databricks SQL warehouse. Publish to Power BI from Catalog Explorer builds the semantic model for you. The trade is warehouse query cost versus Fabric capacity.

If I were in your shoes I'd try Compatibility Mode on one gold MV and, in parallel, swap the 15-minute overwrite for a MERGE. The second fix helps no matter which route you pick.

References:

Regards,
Louis

Thanks! I don't see the compatibility mode in either the workspace or account previews. How do I turn it on?

Is it related to this: https://learn.microsoft.com/en-us/azure/databricks/partners/bi/fabric-publish

 

@Louis_Frolio see above please.

@Louis_Frolio So I checked out compatibility mode. It does seem to work using the right set up and table properties in the pipeline code. However here's the problem: the tables in question are gold tables produced by complex sql queries on silver data. The declarative pipeline cannot figure out how to do incremental refreshes of these tables so most of them are fully refreshed every time. But when this happens the compatibility mode table is also fully overwritten. Hence we are back to tables being fully replaced at every refresh.

Jen_Evangelista
New Contributor III

There's no preview toggle for this, which is why you don't see it in the workspace or account previews. For an MV, Compatibility Mode is set with the two table properties Louis showed, when the MV is created. The docs only document ALTER TABLE for managed tables, not for an existing MV, so I'd try it on a new test MV before counting on switching the current one in place.

The prerequisites are easy to miss. The target path must exist, be empty and sit under a UC external location. You need CREATE EXTERNAL TABLE on that location. And the path can't have been used as a Compatibility Mode location for another table in the last 7 days. The first version can take up to an hour to show up.

Once it's there, compare a known source version with the compatibility output and time how long Fabric takes to see a refresh. It's still a read-only copy, so the storage cost stays.

The page in your link is about publishing a UC catalog to Fabric as mirrored tables. That's a separate setup from Compatibility Mode.

Docs: https://learn.microsoft.com/en-us/azure/databricks/external-access/compatibility-mode

suranga
Databricks Partner

On the open question about an existing MV: the docs only describe setting those two properties when the MV is created. So I'd treat it as a create-time setting and not count on ALTER working on an existing MV. What I'd do:

1. Add the properties to the MV definition in the pipeline code (TBLPROPERTIES), deploy it to a dev pipeline and let it run a full refresh.

2. In Fabric, check whether the table shows up in the mirrored catalog and whether Direct Lake loads it without falling back to DirectQuery.

3. Only then roll it out to prod, and plan for the full refresh that a definition change can trigger.

If it doesn't show up, your current plain Delta copy with a hash-based MERGE is still the reliable route.