Interview practice question
countDistinct is slow
Data Engineering · Spark · Beginner
A daily job computes countDistinct of user_id per country over billions of events and is very slow. What can you do?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Exact distinct counts need big shuffles.
- approx_count_distinct is much faster with small error.
- Pre-aggregate daily distinct users if possible.
- Filter and select only needed columns early.
- Use exact counts only where required.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.