Bird
Raised Fist0

Which of the following is the correct way to declare a new optional field with a default value in an Avro schema for forward compatibility?

easy📝 Syntax Q12 of Q15
Kafka - Schema Registry
Which of the following is the correct way to declare a new optional field with a default value in an Avro schema for forward compatibility?
A{"name": "age", "type": "string", "default": "unknown"}
B{"name": "age", "type": "int", "default": null}
C{"name": "age", "type": "int", "default": 0}
D{"name": "age", "type": "int"}
Step-by-Step Solution
Solution:
  1. Step 1: Identify forward compatibility rule

    Forward compatibility requires new fields to have default values so new consumers can read data produced with the old schema.
  2. Step 2: Check options for default value and type

    {"name": "age", "type": "int", "default": 0} declares an int field with default 0, which is correct for forward compatibility.
  3. Final Answer:

    {"name": "age", "type": "int", "default": 0} -> Option C
  4. Quick Check:

    New optional field with default = {"name": "age", "type": "int", "default": 0} [OK]
Quick Trick: New fields need defaults for forward compatibility [OK]
Common Mistakes:
MISTAKES
  • Missing default value for new fields
  • Using null default without union type
  • Setting wrong type for default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes