How to read changes in streaming queries using change data feed

User16826994223
Databricks Employee
Databricks Employee
 

User16826994223
Databricks Employee
Databricks Employee
# providing a starting version
spark.readStream.format("delta") \
  .option("readChangeFeed", "true") \
  .option("startingVersion", 0) \
  .table("myDeltaTable")
 
# providing a starting timestamp
spark.readStream.format("delta") \
  .option("readChangeFeed", "true") \
  .option("startingTimestamp", "2021-04-21 05:35:43") \
  .load("/pathToMyDeltaTable")
 
# not providing a starting version/timestamp will result in the latest snapshot being fetched first
spark.readStream.format("delta") \
  .option("readChangeFeed", "true") \
  .table("myDeltaTable")

To get the change data while reading the table, set the option  readChangeFeedto true.

The startingVersion or  startingTimestamp

 are optional and if not provided the stream returns the latest snapshot of the table at the time of streaming as an INSERT and future changes as change data. Options like rate limits (maxFilesPerTrigger

,maxBytesPerTrigger and excludeRegex are also supported by change data.

View solution in original post