Databricks Data Engineer Associate exam dumps

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

Single answer

You are working with a JSON dataset in a Databricks notebook. The dataset contains the following nested structure for each record: { "user": { "id": 123, "details": { "name": "John Doe", "age": 30 } } }. You want to extract the name field from the details object using PySpark. Which of the following code snippets correctly extracts this field?

  1. A

    df.select('user.details.name')

  2. B

    df.select('details.name')

  3. C

    df.select(col('user.details.name'))

  4. D

    df.select(col('user.details').name)

Show answer and explanation

Correct answer: C

Explanation

To access nested fields in a PySpark DataFrame, the dot syntax can be used in combination with the col function. In this case, the correct syntax to extract the name field is col('user.details.name') as it correctly navigates through the nested structure of the dataset.

  • A. Incorrect.

    This option is incorrect because PySpark requires the use of the col function to access nested fields with dot syntax.

  • B. Incorrect.

    This option is incorrect because the field details.name is not at the top level of the dataset. It is nested under the user field.

  • C. Correct.

    This is the correct option because the col function supports the dot syntax to access nested fields in the dataset.

  • D. Incorrect.

    This option is incorrect because the col('user.details') expression retrieves the entire details object, and .name cannot be directly appended to it.

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