Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid default for field warning message coming from Avro?

Tags:

java

boolean

avro

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?

like image 528
john Avatar asked Jan 06 '15 00:01

john


People also ask

What is default in Avro schema?

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 }

How do you write Avro schema?

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.

What is Union in Avro schema?

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.

What is Apache Avro format?

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.


1 Answers

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
  }
like image 186
Todd Avatar answered Nov 15 '22 04:11

Todd