Complete the code to read a Delta table with time travel to a specific version.
df = spark.read.format("delta").option("versionAsOf", [1]).load("/data/delta/events")
The versionAsOf option lets you read the table as it was at a specific version number. Here, 5 is the version number.
Complete the code to read a Delta table as it was at a specific timestamp.
df = spark.read.format("delta").option("timestampAsOf", [1]).load("/data/delta/events")
The timestampAsOf option lets you read the table as it was at a specific timestamp. The timestamp must be a string in ISO format.
Fix the error in the code to write data to a Delta table with versioning enabled.
df.write.format("delta").mode([1]).save("/data/delta/events")
append mode which adds data but may not replace existing data.create or update.To update a Delta table and create a new version, use mode("overwrite"). This replaces the data and creates a new version.
Fill both blanks to create a Delta table and enable versioning.
spark.sql("CREATE TABLE events USING delta LOCATION '[1]' [2]")
OPTIONS instead of TBLPROPERTIES.The LOCATION specifies the path to the Delta table. The TBLPROPERTIES option enables features like Change Data Feed for versioning.
Fill all three blanks to create a dictionary comprehension that maps version numbers to their timestamps for versions greater than 3.
version_times = {v: m['timestamp'] for v, m [1] history.items() if v [2] 3 and m.[3]('timestamp')}for instead of in in the comprehension.['timestamp'] directly which may cause errors if key missing.This dictionary comprehension loops over history.items() (using in), filters versions greater than 3 (using >), and safely accesses the 'timestamp' key using get.
