Databricks Data Engineer Associate Question 292
Single answerYou are tasked with querying historical data from a Delta Lake table named 'sales_data'. The table undergoes frequent updates, and you need to retrieve the version of the table as it existed two versions prior. Which of the following commands will achieve this?
- A
SELECT * FROM sales_data VERSION AS OF 2;
- B
SELECT * FROM sales_data TIMESTAMP AS OF '2';
- C
SELECT * FROM sales_data VERSION AS OF 2 VERSION;
- D
SELECT * FROM sales_data VERSION AS OF 2;
Show answer and explanation
Correct answer: A
Explanation
In Delta Lake, the 'VERSION AS OF' clause is used to query historical data by specifying a particular version of the table. The correct syntax is 'SELECT * FROM table_name VERSION AS OF <version_number>;', where <version_number> represents the specific version of interest. Other options either use incorrect syntax or misuse the clause.
- A. Correct.
This is the correct syntax for querying a specific version of a Delta Lake table in Databricks. The 'VERSION AS OF' clause retrieves data from a specific table version.
- B. Incorrect.
This syntax is incorrect because 'TIMESTAMP AS OF' is used to query data from a table as it existed at a specific point in time, not by version.
- C. Incorrect.
This syntax is invalid as it redundantly includes 'VERSION' twice, which is not part of the correct Delta Lake query syntax.
- D. Incorrect.
This syntax is invalid because it repeats the 'VERSION AS OF' clause unnecessarily.