Databricks Data Engineer Associate Question 288
Single answerYou are working with a Delta table named 'sales_data' in Databricks. A recent update caused issues, and you need to query the table as it existed before the update. The table has multiple versions stored in its transaction log. How can you query a specific version of the 'sales_data' table?
- A
SELECT * FROM sales_data VERSION AS OF 5;
- B
SELECT * FROM delta.
/path/to/sales_dataVERSION AS OF 5; - C
SELECT * FROM sales_data TIMESTAMP '2023-10-01T10:00:00';
- D
SELECT * FROM sales_data AS OF VERSION 5;
Show answer and explanation
Correct answer: B
Explanation
To query a specific version of a Delta table, you must use the 'VERSION AS OF' clause and specify the table's path. This allows you to retrieve the state of the table at a particular version number recorded in the Delta Lake transaction log. The other options use either incorrect syntax or a clause intended for querying by timestamp rather than version.
- A. Incorrect.
This syntax is incorrect because the correct clause is 'VERSION AS OF' and it can only be used in conjunction with the Delta table's path.
- B. Correct.
This is the correct syntax for querying a specific version of a Delta table by referencing its path and using 'VERSION AS OF'.
- C. Incorrect.
This syntax uses the 'TIMESTAMP AS OF' clause, which is used for querying the table at a specific point in time, not a specific version.
- D. Incorrect.
This syntax is invalid because 'AS OF VERSION' is not a supported clause in Delta Lake.