Databricks Data Engineer Associate Question 116
Single answerYou are working on a Databricks notebook to analyze customer data stored in a Delta table. The table contains a column named email that may contain NULL values. You need to calculate the total number of rows in the table, ignoring NULL values in the email column. Which of the following options correctly explains the behavior of using count(email)?
- A
count(email)will count all rows, including those with NULL values in theemailcolumn. - B
count(email)will count only rows where theemailcolumn is NOT NULL. - C
count(email)will count all rows in the table, regardless of theemailcolumn's value. - D
count(email)throws an error if NULL values are present in theemailcolumn.
Show answer and explanation
Correct answer: B
Explanation
The function count(column_name) in Spark SQL (and Databricks) counts only the rows where the specified column is NOT NULL. If the column contains NULL values, those rows are excluded from the count. This behavior ensures that only meaningful, non-NULL values are considered in the aggregation.
- A. Incorrect.
count(email)does not include NULL values in the column being counted, so this option is incorrect. - B. Correct.
count(email)specifically excludes rows with NULL values in theemailcolumn, making this the correct answer. - C. Incorrect.
count(email)does not count all rows in the table; it only counts rows where theemailcolumn is NOT NULL, so this option is incorrect. - D. Incorrect.
count(email)does not throw an error when NULL values are present. It simply skips them, so this option is incorrect.