Databricks Data Engineer Associate exam dumps

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

Single answer

You are working with a Delta table in Databricks that contains customer data. One of the columns, email_address, contains email addresses in the format username@domain.com. You need to extract only the domain name (e.g., 'domain.com') from the email_address column and store it in a new column called email_domain. Which of the following approaches would correctly achieve this in PySpark?

  1. A

    Use the regexp_extract function with the pattern @(.+)$ to extract the domain name.

  2. B

    Use the split function to split the string by the '@' character and select the second element.

  3. C

    Use the substring function to extract the portion of the string after the '@' character.

  4. D

    Use the format_string function to reformat the email_address column and extract the domain name.

Show answer and explanation

Correct answer: A

Explanation

The regexp_extract function is designed specifically for extracting substrings based on a regular expression pattern. In this case, the regex @(.+)$ captures everything after the '@' character in the email_address column, which is the domain name. This approach is efficient and concise compared to alternatives like split or substring. The format_string function is not relevant for this task.

  • A. Correct.

    Correct. The regexp_extract function with the regex pattern @(.+)$ is the appropriate method to extract the domain name. The pattern captures the portion of the string after the '@' character, which is the domain name.

  • B. Incorrect.

    Incorrect. While the split function can be used to split the string, it is less efficient and more complex to work with compared to regexp_extract for this specific task.

  • C. Incorrect.

    Incorrect. The substring function requires you to know the position of the '@' character, which is not guaranteed to be at the same index in every email address.

  • D. Incorrect.

    Incorrect. The format_string function is used for formatting strings rather than extracting patterns, making it unsuitable for this use case.

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