Complete the code to read a JSON file into a DataFrame.
df = spark.read.[1]("data/input.json")
The json method reads JSON files into a DataFrame.
Complete the code to write a DataFrame to a dead letter queue path in Parquet format.
df_dead_letter.write.mode("append").[1]("data/dead_letter")
Writing in Parquet format is efficient and common for dead letter queues.
Fix the error in the code to catch exceptions during data processing.
try: df = spark.read.json("data/input.json") df.show() except [1] as e: print(f"Error: {e}")
Using Exception catches all errors during processing.
Fill both blanks to filter out bad records and collect them into a dead letter DataFrame.
dead_letter_df = df.filter(df["status"] [1] "error").select([2])
Filter records where status equals 'error' and select all columns using '*'.
Fill all three blanks to create a dictionary of error counts by type from the dead letter DataFrame.
error_counts = dead_letter_df.groupBy([1]).count().rdd.map(lambda row: (row[[2]], row[[3]])).collectAsMap()
Group by 'error_type', then map row index 0 (error_type) and 1 (count) to a dictionary.
