
Answer-first summary for fast verification
Answer: GENERATED ALWAYS AS (CAST(orderTime as DATE))
The correct answer is `GENERATED ALWAYS AS (CAST(orderTime as DATE))`. Delta Lake supports generated columns, which are automatically populated based on a user-specified function over other columns in the table. This feature allows Delta Lake to compute the values for these columns automatically when data is written to the table without explicit values provided for the generated columns. For more details, refer to the [Delta Lake documentation](https://docs.microsoft.com/en-us/azure/databricks/delta/delta-batch#–use-generated-columns). Note: Databricks also supports partitioning using generated columns.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
You are tasked with creating a table to store order data, including a timestamp for when the order was placed. However, the finance team prefers to query this data in date format. To accommodate this, you decide to add a calculated column that converts the orderTime timestamp to a date. Complete the DDL statement to achieve this.
CREATE TABLE orders ( orderId int, orderTime timestamp, orderdate date _____________________________________________ , units int)
A
AS DEFAULT (CAST(orderTime as DATE))
B
GENERATED DEFAULT AS (CAST(orderTime as DATE))
C
AS (CAST(orderTime as DATE))
D
Delta lake does not support calculated columns, value should be inserted into the table as part of the ingestion process
E
GENERATED ALWAYS AS (CAST(orderTime as DATE))
No comments yet.