Google Cloud Professional Data Engineer · Free practice question 10 of 12
Approximate distinct counts for dashboards
A dashboard at Wetherby Streaming shows daily unique viewers from a 40 TB BigQuery table, and the exact COUNT(DISTINCT viewer_id) query is slow and expensive. The product team accepts a small statistical error. What should the query use?
- A.COUNT(viewer_id)
- B.APPROX_COUNT_DISTINCT(viewer_id)
- C.COUNT(DISTINCT viewer_id) with a LIMIT clause
- D.SUM(1) grouped by viewer_id
Show answer and explanation
Correct answer: B. APPROX_COUNT_DISTINCT(viewer_id)
Why: APPROX_COUNT_DISTINCT uses a HyperLogLog-based estimate that needs far less memory and computation than an exact distinct count, at the cost of a small error. COUNT counts repeated viewers more than once. LIMIT does not reduce the work of the aggregation, and grouping by viewer_id still processes every distinct value.
More free Google Cloud Professional Data Engineer questions
- Sliding windows for moving averages
- Turbo replication on dual-region buckets
- Assured Workloads for sovereign controls
- Data Validation Tool after migration
- Pub/Sub Cloud Storage subscription archive
- Bigtable garbage collection by age
- Search indexes for log lookups
- Data Studio viewer's credentials
- Integer-range partitioning on an ID
- Scheduled queries for a single SQL job
- Pub/Sub message storage policy regions