Challenge - 5 Problems
Delta Lake Time Travel Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of reading a Delta table at a previous version
Given a Delta table with 3 versions, what will be the output count of rows when reading version 1?
Apache Spark
from delta.tables import DeltaTable from pyspark.sql import SparkSession spark = SparkSession.builder.appName('TimeTravelTest').getOrCreate() delta_path = '/tmp/delta-table' # Read version 1 of the table version_1_df = spark.read.format('delta').option('versionAsOf', 1).load(delta_path) print(version_1_df.count())
Attempts:
2 left
💡 Hint
Think about what versionAsOf option does when reading a Delta table.
✗ Incorrect
Using option('versionAsOf', 1) reads the table exactly as it was at version 1, so the row count matches that version's data.
❓ data_output
intermediateResult of a Delta table history query
What does the following code output?
Apache Spark
from delta.tables import DeltaTable from pyspark.sql import SparkSession spark = SparkSession.builder.appName('HistoryTest').getOrCreate() delta_path = '/tmp/delta-table' delta_table = DeltaTable.forPath(spark, delta_path) history_df = delta_table.history(2) history_df.show()
Attempts:
2 left
💡 Hint
The history() method shows commit history of the Delta table.
✗ Incorrect
Calling history(2) returns a DataFrame with details of the last 2 commits, including version numbers and operation types.
🔧 Debug
advancedIdentify the error in time travel query
What error will this code raise?
Apache Spark
spark.read.format('delta').option('versionAsOf', 'two').load('/tmp/delta-table')
Attempts:
2 left
💡 Hint
Check the type and value expected for versionAsOf option.
✗ Incorrect
The versionAsOf option expects an integer version number. Passing a string like 'two' causes an AnalysisException.
🚀 Application
advancedUsing timestamp for time travel in Delta Lake
Which code snippet correctly reads a Delta table as it was at '2024-01-01 12:00:00'?
Attempts:
2 left
💡 Hint
Look for the correct option name for timestamp-based time travel.
✗ Incorrect
The correct option to specify a timestamp for time travel is 'timestampAsOf'. Other options are invalid.
🧠 Conceptual
expertUnderstanding Delta Lake version retention and vacuum
What happens if you run vacuum on a Delta table and then try to time travel to a version older than the retention period?
Attempts:
2 left
💡 Hint
Consider what vacuum does to old data files and how time travel depends on them.
✗ Incorrect
Vacuum deletes data files older than the retention period. Time travel to versions relying on those files will fail.
