I have a avro schema like this in which I have is_userid_present
decalred as boolean and I wanted to give default value as false to it so I came up with below avro schema.
{
"type":"record",
"name":"hello",
"fields":[
{
"name":"u",
"type":[
"string",
"null"
]
},
{
"name":"p",
"type":"string"
},
{
"name":"bu",
"type":"boolean"
},
{
"name":"is_userid_present",
"type":"boolean",
"default":"false"
}
]
}
But from Avro code, I am seeing this warning message -
[WARNING] Avro: Invalid default for field is_userid_present: "false" not a "boolean"
I am not sure what wrong I am doing here? If I have avro schema like this, then will it be of any problem for writing and reading the data?
Default Values and Logical Types Default Values is one of the use case of Union where we can have multiple field value to take different types. And in default every field in avro schema are not nullable. Example : Making middle_name as nullable { "name": "middle_name", "type": ["null", "string"], "default": null }
Creating Avro Schemas type − This field comes under the document as well as the under the field named fields. In case of document, it shows the type of the document, generally a record because there are multiple fields. When it is field, the type describes data type.
A union indicates that a field might have more than one data type. For example, a union might indicate that a field can be a string or a null. A union is represented as a JSON array containing the data types.
Apache Avro™ is the leading serialization format for record data, and first choice for streaming data pipelines. It offers excellent schema evolution, and has implementations for the JVM (Java, Kotlin, Scala, …), Python, C/C++/C#, PHP, Ruby, Rust, JavaScript, and even Perl.
According to the Avro Docs, if you specify a default boolean, you can't do it as a String
like you have it.
Try this...
{
"name": "is_userid_present",
"type": "boolean",
"default": false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With