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: 

Change data feed from a materialized view

cdn_yyz_yul
Valued Contributor

Hi everyone,

Trying the CDF on materialized view (declarative pipeline) feature that is currently in Beta.

- Configuration:
** Verified the MVs (materialized veiws) have: 'delta.enableRowTracking'
SHOW TBLPROPERTIES my_mv ('delta.enableRowTracking');  returns true

** Enabled external metadata flag,

 In the declarative pipeline setting has included :
"configuration": {
"spark.databricks.acl.needAdminPermissionToViewLogs": "false",
"pipelines.externalMetadata.enabled": "true"
},

For the MV that used for testing, also added 

@dp.materialized_view(...) has:
    table_properties={
        "quality": "gold",
        "pipelines.reset.allowed": "true",
        "pipelines.externalMetadata.enabled": "true",
        "delta.enableRowTracking": "true",
    },

** DLT settings has channel: PREVIEW

- Read from CDF:
Dropped the MV used for the test: my_mv, and run full refresh of the pipeline. 

Open a notebook and connected to serverless, environment 5. 
Trying to read CDF from the MV:

spark.sql("SELECT * FROM table_changes('my_mv', 0)"😞

got error:
Spark version: 4.2.0 Error: (com.databricks.sql.transaction.tahoe.DeltaFileNotFoundException) [DELTA_LOG_FILE_NOT_FOUND] Unable to retrieve the delta log files to construct table version 0 starting from checkpoint version -1 at abfss://gold@myhostname123.dfs.core.windows.net/__unitystorage/schemas/7e714b9b-79cd-4afe-a95d-28f0026f6ef4/tables/c0072537-f031-4f89-9ab8-7bd4d2af0a70/_external_metadata/_delta_log.

---------

Can you help to point out what is missing?
Thanks,


 

18 REPLIES 18

Totally understandable, @cdn_yyz_yul! Holding off on workarounds for a roadmap feature is usually the right call — the extra complexity rarely pays off. If you haven’t already, consider upvoting the request in the Databricks Ideas Portal to help prioritize it. Good luck with your project! 🙂

data_pulse
Contributor

I tried reproducing a similar scenario using serverless compute in Databricks Free Edition.

I tested enabling pipelines.externalMetadata.enabled=true at the pipeline level, explicitly setting it in the materialized view's TBLPROPERTIES, and also creating a standalone materialized view through a Serverless SQL Warehouse with the same property.

 
In all cases, the property (pipelines.externalMetadata.enabled) does not appear in SHOW TBLPROPERTIES, and querying the MV's change feed using table_changes() fails with: DELTA_LOG_FILE_NOT_FOUND.
 
The error points to the _external_metadata/_delta_log location.
 
I also verified that the pipeline uses the PREVIEW channel, row tracking and CDF are enabled, and the materialized views refresh successfully, including incremental refreshes. I tried REPAIR TABLE,
SYNC METADATA, but the error persisted.
 
The table_changes() works as expected on the underlying Delta source table but not on the Mview.
 
It seems there may still be an additional prerequisite or feature enablement step needed for automatic CDF to work with materialized views, particularly given its Beta status.

Thank you very much @data_pulse for your test. It is really helpful.

A summary of my tests:

- CDF with MV: always fails (as discussed previously) after finished all configurations per documentation.

- CDF with Streaming tables: must set enableChangeDataFeed=true for each table (i.e., the legacy change data feed). When I follow the doc to migrate to automatic CDF, got DELTA_MISSING_CHANGE_DATA.

 https://learn.microsoft.com/en-us/azure/databricks/tables/features/change-data-feed#migrateUse chang...

Louis_Frolio
Databricks Employee
Databricks Employee

Hello @cdn_yyz_yul, Thanksto @Jen_Evangelista for the pipeline-config versus table-property framing and to @data_pulse for the Free Edition repro.

On the property question: I can't point to a doc line, but the evidence says it's expected that pipelines.externalMetadata.enabled doesn't show in SHOW TBLPROPERTIES. data_pulse never saw it in any of the three configuration paths, and in your case the metadata log did get written (REPAIR couldn't have produced versions 3 through 35 otherwise). The flag is consumed by the pipeline, not stored on the table. Note that data_pulse's failure is at an earlier step than yours: their log never got created at all.

There is a clue: Your dump has these two lines:

delta.enableChangeDataFeed,true
delta.feature.changeDataFeed,supported

That's legacy change data feed, turned on. The MV docs say materialized views use automatic CDF and you don't turn on the change feed itself. The automatic CDF docs say the two can't be used together, and the migration step is to unset delta.enableChangeDataFeed. With legacy on, the reader goes looking for materialized change records at each version, the pipeline never wrote any, and you get "change data was not recorded" at every version, before and after REPAIR. It fits all the facts. I don't think you set it; my understanding is pipelines turn legacy CDF on by default for the tables they manage. The experiment:

  1. Add "delta.enableChangeDataFeed": "false" to the MV's table_properties and run an update.
  2. Check SHOW TBLPROPERTIES my_catalog.my_schema.my_mv ('delta.enableChangeDataFeed'). If the pipeline put it back, that goes straight in the ticket.
  3. If it stuck, run REPAIR TABLE ... SYNC METADATA once more and read from the newest version with an explicit version number.

Caveat: if a downstream MV refreshes incrementally off this one, turning CDF off may push it to full recompute. Fine for a terminal gold MV in a test pipeline.

On the plain-table test, two things. First, automatic CDF needs row tracking on the table, and nothing in your history output shows whether that test table had it. The clean test is a fresh table with delta.enableRowTracking = true and no delta.enableChangeDataFeed, two writes, then table_changes from version 1 on DBR 19. If that works, automatic CDF is fine in your workspace and the MV problem is isolated to the legacy property. If it fails, automatic CDF itself isn't live for you, and that's the headline of the ticket instead. Second, a period with no changes should return zero rows, not DELTA_MISSING_CHANGE_DATA, so the error was never "nothing changed."

On streaming from the MV: fair hit. The docs do list a streaming read with readChangeFeed=true as supported for this beta, from a different PREVIEW pipeline or Databricks SQL, but it rides the same path as the batch read. Until table_changes() works, the stream won't either. Keep that exact error for the report.

If the experiment doesn't get you there, I'd treat this as a Beta product issue rather than a configuration problem, and you've got a crisp case: MV name, pipeline ID, runtime and compute type, the full property dump, confirmation REPAIR succeeded, the version range (3 through 35), a failing explicit-version read, the row-tracked plain-table result, and this thread.

References:

 

Regards, Louis.