Databricks Data Engineer Associate exam dumps

Databricks Data Engineer Associate practice question 314 of 532

Databricks Certified Data Engineer Associate. Associate level, Databricks. Free question with the correct answer and a full explanation.

Databricks Data Engineer Associate Question 314

Single answer

A data engineer is working on a Delta table in Databricks containing transaction data. The table includes the columns transaction_id, amount, and timestamp. The engineer wants to create a new column, year_month, that extracts the year and month from the timestamp column in the format 'YYYY-MM'. This column should be automatically updated whenever new data is added to the table. Which of the following SQL commands should the engineer use to achieve this?

  1. A

    ALTER TABLE transactions ADD COLUMN year_month STRING GENERATED ALWAYS AS (date_format(timestamp, 'yyyy-MM'))

  2. B

    ALTER TABLE transactions ADD COLUMN year_month STRING GENERATED BY (date_format(timestamp, 'yyyy-MM'))

  3. C

    ALTER TABLE transactions ADD COLUMN year_month STRING GENERATED ALWAYS AS (concat(year(timestamp), '-', month(timestamp)))

  4. D

    ALTER TABLE transactions ADD COLUMN year_month STRING AS (date_format(timestamp, 'yyyy-MM'))

Show answer and explanation

Correct answer: A

Explanation

The correct syntax for creating a generated column in Databricks is to use the GENERATED ALWAYS AS clause followed by a valid expression. This ensures the column is derived from the specified expression and automatically updated whenever new data is added to the table. In this scenario, the correct expression to extract the year and month in 'YYYY-MM' format is date_format(timestamp, 'yyyy-MM').

  • A. Correct.

    This is the correct syntax for adding a generated column in Databricks. The GENERATED ALWAYS AS clause ensures the column is derived from the specified expression and automatically updated.

  • B. Incorrect.

    This is incorrect because GENERATED BY is not valid syntax for creating generated columns in Databricks.

  • C. Incorrect.

    This is incorrect because while GENERATED ALWAYS AS is valid syntax, the expression concat(year(timestamp), '-', month(timestamp)) does not produce the desired 'YYYY-MM' format.

  • D. Incorrect.

    This is incorrect because the AS keyword alone does not define a generated column. It would not ensure the column is automatically updated.

Timed practice exam

Take a Databricks Data Engineer Associate practice test under exam conditions

45 questions in 90 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam