Validate warehouse records against an ordered schema. Each schema entry contains column, type ("int", "float", or "str"), and nullable, with optional inclusive min and max bounds. The float schema type accepts Python integers and floats, but Boolean values do not count as integers.
For each column in schema order, check missing values, nullability, type, then range. After a missing value, valid nullable null, or failed type check, skip later checks for that column. Use exact errors "{column}: missing", "{column}: null", "{column}: expected {expected_type}, got {actual_type}", and "{column}: out of range". Return a list of result dictionaries in input order. Each dictionary contains record_index, is_valid, and errors.
Input: records = [{"name": "Alice", "age": 30, "score": 95.5}, {"name": "Bob", "age": 25, "score": 88}], schema = [{"column": "name", "type": "str", "nullable": false}, {"column": "age", "type": "int", "nullable": false, "min": 0, "max": 150}, {"column": "score", "type": "float", "nullable": false, "min": 0, "max": 100}]
Output: [{"record_index": 0, "is_valid": true, "errors": []}, {"record_index": 1, "is_valid": true, "errors": []}]
Explanation: Both records contain every field with accepted types and ranges.
Input: records = [{"name": "Alice", "age": "thirty", "score": 95.5}], schema = [{"column": "name", "type": "str", "nullable": false}, {"column": "age", "type": "int", "nullable": false, "min": 0, "max": 150}, {"column": "score", "type": "float", "nullable": false, "min": 0, "max": 100}]
Output: [{"record_index": 0, "is_valid": false, "errors": ["age: expected int, got str"]}]
Map each schema type name to a predicate using type(value).
Use continue after missing, nullable-null, and wrong-type cases to avoid extra errors.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Validate warehouse records against an ordered schema. Each schema entry contains column, type ("int", "float", or "str"), and nullable, with optional inclusive min and max bounds. The float schema type accepts Python integers and floats, but Boolean values do not count as integers.
For each column in schema order, check missing values, nullability, type, then range. After a missing value, valid nullable null, or failed type check, skip later checks for that column. Use exact errors "{column}: missing", "{column}: null", "{column}: expected {expected_type}, got {actual_type}", and "{column}: out of range". Return a list of result dictionaries in input order. Each dictionary contains record_index, is_valid, and errors.
Input: records = [{"name": "Alice", "age": 30, "score": 95.5}, {"name": "Bob", "age": 25, "score": 88}], schema = [{"column": "name", "type": "str", "nullable": false}, {"column": "age", "type": "int", "nullable": false, "min": 0, "max": 150}, {"column": "score", "type": "float", "nullable": false, "min": 0, "max": 100}]
Output: [{"record_index": 0, "is_valid": true, "errors": []}, {"record_index": 1, "is_valid": true, "errors": []}]
Explanation: Both records contain every field with accepted types and ranges.
Input: records = [{"name": "Alice", "age": "thirty", "score": 95.5}], schema = [{"column": "name", "type": "str", "nullable": false}, {"column": "age", "type": "int", "nullable": false, "min": 0, "max": 150}, {"column": "score", "type": "float", "nullable": false, "min": 0, "max": 100}]
Output: [{"record_index": 0, "is_valid": false, "errors": ["age: expected int, got str"]}]
Map each schema type name to a predicate using type(value).
Use continue after missing, nullable-null, and wrong-type cases to avoid extra errors.
Sign in to take notes on this problem
Accepts: array
Accepts: array