Complete the code to read a Delta table from a data lake.
df = spark.read.format([1]).load("/data/delta/events")
The Delta format is used to enable ACID transactions on data lakes. Using format('delta') tells Spark to read the Delta table.
Complete the code to write a DataFrame as a Delta table with overwrite mode.
df.write.format("delta").mode([1]).save("/data/delta/events")
Using mode('overwrite') replaces the existing data in the Delta table, which is useful for updating data fully.
Fix the error in the code to update a Delta table using Spark SQL.
spark.sql("UPDATE delta.`/data/delta/events` SET status = 'processed' WHERE [1] = 100")
The WHERE clause should filter by a column that identifies rows, such as id. Filtering by status or other columns may not target the intended rows.
Fill both blanks to create a Delta table with partitioning and enable schema evolution.
df.write.format("delta").partitionBy([1]).option("mergeSchema", [2]).mode("append").save("/data/delta/events")
Partitioning by "date" helps organize data by date. Setting mergeSchema to true allows schema changes to be merged automatically.
Fill all three blanks to create a Delta table, update it, and read the latest version.
df.write.format([1]).mode("overwrite").save("/data/delta/events") spark.sql("UPDATE [2] SET status = 'done' WHERE id = 5") df_latest = spark.read.format([3]).load("/data/delta/events")
The Delta format is used for writing and reading to support ACID transactions. The table name events is used in the SQL update. Reading with format delta ensures the latest version is read.
