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: 

How to find which delta commit removed a specific file?

brickster_2018
Esteemed Contributor
Esteemed Contributor
1 ACCEPTED SOLUTION

Accepted Solutions

brickster_2018
Esteemed Contributor
Esteemed Contributor
val oldestVersionAvailable = 
val newestVersionAvailable = 
val pathToDeltaTable = ""
val pathToFileName = ""
(oldestVersionAvailable to newestVersionAvailable).map { version => 
    var df1 = spark.read.json(f"$pathToDeltaTable/_delta_log/$version%020d.json")
    if (df1.columns.toSeq.contains("remove")) {
      var df2 = df1.where("remove is not null").select("remove.path")
      var df3 = df2.filter('path.contains(pathToFileName))
      if (df3.count > 0)
         print(s"Commit Version $version removed the file $pathToFileName \n")
  }
}

View solution in original post

1 REPLY 1

brickster_2018
Esteemed Contributor
Esteemed Contributor
val oldestVersionAvailable = 
val newestVersionAvailable = 
val pathToDeltaTable = ""
val pathToFileName = ""
(oldestVersionAvailable to newestVersionAvailable).map { version => 
    var df1 = spark.read.json(f"$pathToDeltaTable/_delta_log/$version%020d.json")
    if (df1.columns.toSeq.contains("remove")) {
      var df2 = df1.where("remove is not null").select("remove.path")
      var df3 = df2.filter('path.contains(pathToFileName))
      if (df3.count > 0)
         print(s"Commit Version $version removed the file $pathToFileName \n")
  }
}

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!