Challenge - 5 Problems
Avro Schema Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Avro schema validation?
Given this Avro schema and a JSON record, what will be the result of validating the record against the schema?
Kafka
{
"type": "record",
"name": "User",
"fields": [
{"name": "name", "type": "string"},
{"name": "age", "type": "int"}
]
}
Record:
{"name": "Alice", "age": "25"}Attempts:
2 left
💡 Hint
Check the data types of each field in the record compared to the schema.
✗ Incorrect
The schema expects 'age' to be an integer, but the record provides it as a string. Avro does not automatically convert types, so validation fails.
🧠 Conceptual
intermediate1:30remaining
Which Avro schema type is best for optional fields?
You want to define a field in an Avro schema that may or may not be present in the data. Which schema type should you use?
Attempts:
2 left
💡 Hint
Avro uses unions to represent optional fields.
✗ Incorrect
In Avro, optional fields are represented by a union of null and the actual type, with null usually first to indicate the field can be missing.
🔧 Debug
advanced2:30remaining
Why does this Avro schema cause a parsing error?
Identify the error in this Avro schema snippet:
{
"type": "record",
"name": "Product",
"fields": [
{"name": "id", "type": "int"},
{"name": "price", "type": ["float", "null"]},
{"name": "tags", "type": "array", "items": "string"}
]
}
Attempts:
2 left
💡 Hint
Check the structure of the 'array' type in Avro schemas.
✗ Incorrect
In Avro, when defining an array type, the 'type' must be an object with 'type': 'array' and an 'items' key. Here, 'type' is a string and 'items' is a sibling key, which is invalid.
📝 Syntax
advanced2:30remaining
Which Avro schema snippet is syntactically correct for a nested record?
Choose the correct Avro schema snippet defining a record with a nested record field.
Attempts:
2 left
💡 Hint
Nested records must be defined as an object with type 'record' and a name.
✗ Incorrect
Option D correctly defines the nested record as an object with 'type': 'record', a 'name', and 'fields'. Option D and D miss the nested record object structure. Option D is valid but includes a union with null, which is optional but not required here.
🚀 Application
expert2:00remaining
How many fields will the following Avro schema record have after default values are applied?
Consider this Avro schema:
{
"type": "record",
"name": "Event",
"fields": [
{"name": "id", "type": "string"},
{"name": "timestamp", "type": "long"},
{"name": "metadata", "type": ["null", "string"], "default": null},
{"name": "priority", "type": "int", "default": 5}
]
}
If a record is created with only 'id' and 'timestamp' provided, how many fields will the record have after applying defaults?
Attempts:
2 left
💡 Hint
Fields with defaults are added automatically if missing.
✗ Incorrect
The record has 4 fields total. If only 'id' and 'timestamp' are provided, the fields 'metadata' and 'priority' will be added with their default values, making 4 fields in total.