How to enable change data feed in path based delta table

Saurav Kumar Barnwal 1 Reputation point
2023-11-09T11:31:37.8+00:00

Dear Tech Members,

There is an existing path based delta table ('abfss://******@xyz.dfs.core.windows.net/main/testcdc') and i want to enable the change data feed to it , i have gone through the blogs, articles and different forum and all are suggesting to run the alter command like below :

ALTER TABLE myDeltaTable SET TBLPROPERTIES (delta.enableChangeDataFeed = true)

but here myDeltaTable is not path based delta table this I think is lakehouse database table (i may be incorrect not 100% sure) also when i am trying to run the below command in python or using only sql then also i am not able to run like mentioned below

spark.sql("ALTER TABLE 'abfss://******@xyz.dfs.core.windows.net/main/testcdc' SET TBLPROPERTIES (delta.enableChangeDataFeed = true)")

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,373 questions
Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,514 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2023-11-09T15:02:33.0633333+00:00

    Try to initialize a Delta table object in your Spark environment usinyou already have :

    from delta.tables import DeltaTable
    deltaTable = DeltaTable.forPath(spark, "abfss://******@xyz.dfs.core.windows.net/main/testcdc")
    

    Once you have the Delta table object, use the setTableProperties method to enable the Change Data Feed :

    deltaTable.setTableProperties({"delta.enableChangeDataFeed": "true"})
    

    If you prefer Spark SQL, you might need to create a temporary view pointing to your Delta table and then use the ALTER TABLE command on that view. This approach may not be supported for path-based Delta tables in all environments.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.