Validate a nested order schema
Python data engineering interview problem. Difficulty: intermediate. Pattern: Dictionaries. About 15 minutes. Part of the Pro drill bank.
Orders arrive as nested dicts. A validator should catch a missing required field before the order is written to the warehouse.
Orders arrive as nested dictionaries from different systems. Before saving, the service must name the first required field that is missing or wrong. Check an order in this order: id must be a non-empty string; customer must be a dictionary with a non-empty email; items must be a non-empty list; each item needs a non-empty sku and a qty that is a number of at least 1. Return the name of the first problem as text ('id', 'customer', 'customer.email', 'items', 'items.0.sku', 'items.0.qty'), or None if the order is valid. Write missing_order_field(order). A full order with id '1', an email and one item with sku and qty 1 returns None. An empty dictionary {} returns 'id'. The starter file already has the function name and its print lines. Keep them and fill in the body.
Requirements
- Check the fields in the order given.
- Return the dotted name of the first problem.
- Report the index for items, like items.1.qty.
- Return None when everything is valid.
Constraints
- order can be any value, even {} or a non-dictionary.
- qty must be a number of at least 1.
Examples
Input: missing_order_field({'id': '1', 'customer': {'email': '[email protected]'}, 'items': [{'sku': 'X', 'qty': 1}]}) Output: None This input follows the stated rules and produces this output.
Topics: lakebench, python, nested-structures.
More Python interview questions · All interview problems · Learn data engineering
Validate a nested order schema
Interview-style drill: Check that a nested order dict has all required fields at every level, reporting the first missing one.
Validate a nested order object and report the missing field the tests expect.