QuestionQ9

VerifiedTroubleshooting and Tuning Apache Spark DataFrame API Applications.

The code block below contains an error. It is intended to return the exact number of distinct values in the division column in DataFrame storesDF. Identify the error.

Code block:

storesDF.agg(approx_count_distinct(col(“division”)).alias(“divisionDistinct”))  
Explanation

Spark SQL's approx_count_distinct returns an estimated distinct count (using HyperLogLog++), not an exact one. Its optional relative-standard-deviation parameter controls the approximation tolerance; supplying it does not make the result exact. Use an exact distinct-count aggregate, such as count_distinct, when an exact value is required.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!