
Explanation:
The correct answer is A. The ALTER TABLE ADD COLUMNS command is the most efficient way to add a generated column to an existing Delta Lake table. By specifying the column with the GENERATED ALWAYS AS clause, you ensure that the column's values are computed based on other columns in the table, which optimizes storage and performance. This approach also allows you to set a default value for existing rows, fulfilling all the given requirements without the need for data migration or additional update operations.
Ultimate access to all questions.
In the context of managing a Delta Lake table within a Databricks environment, you are tasked with adding a new column that should automatically compute its values based on other columns in the table. This column must also have a default value for existing rows. Considering the need for efficiency in storage and performance, which of the following approaches correctly implements a generated column with these requirements? Choose the best option.
A
Execute the ALTER TABLE ADD COLUMNS command to add the new column, specifying a default value, and use the GENERATED ALWAYS AS clause to define it as a generated column.
B
Create a new table with the CREATE TABLE command, including the generated column definition in the WITH clause, and then migrate all data from the old table to the new one.
C
First, update all existing rows in the table to set the value of the new column using the UPDATE command, then add the column as a generated column with the ALTER TABLE ADD COLUMNS command.
D
Use the MERGE command to insert or update rows with the new column values, followed by the ALTER TABLE ADD COLUMNS command to add the column as a generated column.
No comments yet.