Quality gate for a batch
Python data engineering interview problem. Difficulty: beginner. Pattern: Dictionaries. About 10 minutes. Free to practice.
Decide whether a batch of rows is clean enough to publish, based on missing required fields. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Before publishing a batch, a pipeline checks its quality. A row is bad if any required column is missing, None or an empty string. Implement quality_gate(rows, required, max_bad_pct). rows is a list of dicts and required is a list of column names. Return 'pass' if the share of bad rows is at most max_bad_pct percent, otherwise 'fail'. An empty batch returns 'fail', because there is nothing to publish.
Requirements
- A missing column, None and an empty string all make a row bad.
- Exactly at the limit is a pass.
Constraints
- max_bad_pct is between 0 and 100.
- The input rows are not changed.
Examples
Input: quality_gate([{'id': 1}, {'id': ''}, {'id': None}], ['id'], 25) Output: 'fail' Two of three rows are bad, far above 25 percent.
Topics: lakebench, python, quality gate, validation, pipeline.
More Python interview questions · All interview problems · Learn data engineering
Quality gate for a batch
Interview-style drill: Decide whether a batch of rows is clean enough to publish, based on missing required fields.
Before publishing a batch, a pipeline checks its quality. A row is **bad** if any required column is missing, `None` or an empty string. Implement `quality_gate(rows, required, max_bad_pct)`. - `rows` is a list of dicts and `required` is a list of column names. - Return `'pass'` if the share of bad rows is at most `max_bad_pct` percent, otherwise `'fail'`. - An empty batch returns `'fail'`, because there is nothing to publish.