Pick One Value per Hour When Two Metric Pipelines Overlap

Last updated: November 29, 2026

Quick Overview

During a migration, hourly metrics land from both a legacy and a new pipeline, and reruns add duplicate rows. Write SQL that keeps exactly one value per metric and hour, preferring the new pipeline and its latest run, then rolls the result up to daily totals.

Meta
Data Manipulation (SQL/Python)
Data Engineer
Meta
November 29, 2026
Data Engineer
Phone Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


During a migration, hourly metrics land from both a legacy and a new pipeline, and reruns add duplicate rows. Write SQL that keeps exactly one value per metric and hour, preferring the new pipeline and its latest run, then rolls the result up to daily totals.

A practical data engineering screen at Meta, where pipeline migrations and backfills regularly leave overlapping hourly partitions. The interviewer checks ROW_NUMBER deduplication with a multi-key priority and that the daily rollup happens after the dedup, not before.

What the Interviewer Expects
  • Define the priority order explicitly (pipeline, then recency)
  • Deduplicate with ROW_NUMBER over metric and hour
  • Roll up to daily only after deduplicating
  • Report which pipeline supplied each day
  • Spot hours missing from both pipelines
Key Topics to Cover
deduplication
ROW_NUMBER
priority rules
rollups
pipeline migration
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you detect days where the two pipelines disagree by more than 1%?
  • What if the new pipeline is missing a few hours?
  • Why not simply use MAX(value)?
  • How would you make this a view that survives the old pipeline's removal?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

hourly_metrics(metric_name, hour_ts, value, pipeline, computed_at), where pipeline is legacy or v2. A rerun writes a new row with a later computed_at. Rule: for each metric and hour, take `v...

Approach

ROW_NUMBER over (metric_name, hour_ts) ordered by a pipeline rank and then computed_at DESC, keep row 1. Then group by metric and date, summing values, and count how many hours came from each pipe...


Submit Your Answer
Markdown supported