Prepare and test your skills

Prepare and test your skills

Free sample question, answered and explained below. The Professional Data Engineer practice bank has 1,353 more like it. Try 10 free: instant score, no account.
A data engineer is designing an automated post-ingestion cleansing pipeline in BigQuery for a multi-terabyte event ingestion table named telemetry.raw_events.
Due to upstream at-least-once streaming semantics, duplicate event payloads are frequently ingested. The cleansing pipeline must meet the following operational requirements:
device_id and event_id.ingestion_timestamp.Which SQL pattern should the data engineer implement?
SELECT DISTINCT * query grouped by device_id and event_id, writing the output into a temporary table before dropping and recreating the original table.SELECT DISTINCT * filters out rows that are 100% identical across all columns in the table.
device_id, event_id) but differing system attributes (such as different ingestion_timestamp values). DISTINCT * treats them as separate rows and retains both.SELECT DISTINCT * directly with a GROUP BY on a subset of columns causes a syntax error in GoogleSQL because non-grouped columns must be explicitly aggregated.DISTINCT evaluates equality across every single column in the projection.Duplicates were exact bit-for-bit replicas across every single column and the table did not require time-based resolution.
CREATE OR REPLACE TABLE telemetry.raw_events AS statement querying SELECT * EXCEPT(row_num) FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY device_id, event_id ORDER BY ingestion_timestamp DESC) AS row_num FROM telemetry.raw_events) WHERE row_num = 1.This pattern uses a window function (ROW_NUMBER()) coupled with a CREATE OR REPLACE TABLE ... AS SELECT (DDL/DML) statement and the EXCEPT column modifier to perform an atomic, in-place deduplication of a BigQuery table.
device_id, event_id isolates duplicate groups into distinct evaluation windows.ingestion_timestamp DESC guarantees that the newest record is assigned row_num = 1.SELECT * EXCEPT(row_num) ensures that the transient ranking column is excluded from the final schema definition.CREATE OR REPLACE TABLE performs an atomic metadata swap that replaces the target table with the deduplicated dataset.ALTER TABLE DROP COLUMN operations by discarding helper attributes on write.Compared to row-by-row DELETE DML statements or expensive self-joins, evaluating window functions in a single-pass CREATE OR REPLACE TABLE AS SELECT query scans the data efficiently, minimizes slot execution time, and avoids concurrency limits associated with multiple mutation operations.
MERGE INTO telemetry.raw_events target USING (SELECT device_id, event_id, MAX(ingestion_timestamp) AS max_time FROM telemetry.raw_events GROUP BY device_id, event_id) source ON target.device_id = source.device_id AND target.event_id = source.event_id WHEN MATCHED AND target.ingestion_timestamp < source.max_time THEN DELETE.This query uses a MERGE DML statement that calculates the maximum timestamp per key using an aggregate subquery, and deletes any row in the target table where the timestamp is strictly older than the maximum.
ingestion_timestamp values for the same (device_id, event_id), the condition target.ingestion_timestamp < source.max_time evaluates to false for all of them, leaving both duplicate rows intact.MERGE statements on massive BigQuery tables require substantial slot processing for join resolution and generate extensive DML mutations compared to an atomic metadata table overwrite (CREATE OR REPLACE TABLE).The target table was receiving real-time concurrent updates where rewriting the entire table partition was prohibited.
DELETE FROM telemetry.raw_events WHERE (device_id, event_id) IN (SELECT (device_id, event_id) FROM telemetry.raw_events GROUP BY device_id, event_id HAVING COUNT(*) > 1).This statement identifies all (device_id, event_id) combinations that have more than one occurrence using a subquery with GROUP BY and HAVING COUNT(*) > 1, and passes those keys into a DELETE statement.
WHERE (device_id, event_id) IN (...) removes every row that has duplicates, deleting both the original and the recent entries rather than preserving the latest record.GROUP BY followed by a large-scale DELETE operation forces extensive data shuffling and triggers high-cost DML mutation locks on the table.ingestion_timestamp.The business requirement dictated that any record subjected to duplicate generation was considered corrupt and must be completely purged from the system.
Answer them yourself and get your score the moment you finish. No account needed.
Full access includes
Keep the momentum going with these hand-picked practice scenarios
Last updated Validated