Databricks Data Engineer Associate exam dumps

Databricks Data Engineer Associate practice question 130 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 130

Single answer

You are working on a Databricks notebook, and you are tasked with deduplicating rows in a DataFrame named orders_df based on the order_id column. However, for rows with the same order_id, you want to keep the row with the most recent order_date. Which of the following code snippets achieves this?

  1. A

    orders_df.orderBy('order_id', 'order_date').dropDuplicates(['order_id'])

  2. B

    orders_df.orderBy('order_id', 'order_date').distinct()

  3. C

    orders_df.orderBy('order_id', F.desc('order_date')).dropDuplicates(['order_id'])

  4. D

    orders_df.dropDuplicates(['order_id']).orderBy(F.desc('order_date'))

Show answer and explanation

Correct answer: C

Explanation

To deduplicate a DataFrame based on a specific column (order_id) while keeping the most recent row (based on order_date), the DataFrame should first be ordered by the column to prioritize (descending order_date in this case). After ordering, dropDuplicates can be applied to remove duplicate rows based on the specified column while retaining the desired row.

  • A. Incorrect.

    This code does not ensure that the most recent order_date is kept. The orderBy is in ascending order (default), so the oldest date will be retained during deduplication.

  • B. Incorrect.

    This code does not address deduplication based on order_id. The distinct() function only removes exact duplicate rows and does not consider specific columns like order_id.

  • C. Correct.

    This code correctly orders the DataFrame by order_id and descending order_date, ensuring the most recent date is at the top for each order_id. The subsequent dropDuplicates(['order_id']) ensures deduplication while keeping the most recent row.

  • D. Incorrect.

    This code applies deduplication first using dropDuplicates(['order_id']) without guaranteeing the most recent order_date is kept, as orderBy is applied after deduplication, which won't change the already deduplicated result.

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