Getting Illegal initial character: in schema parsing
Asked Answered
S

1

5

I am using Avro 1.8.1 and trying to parse the following schema_2. Can you please help?

    val schema: Schema = new Schema.Parser().parse(StrSchema) 

I am getting following exception.
Exception in thread "main" org.apache.avro.SchemaParseException: Illegal initial character: {"type":"record","name":"WS_MESSAGES","fields":[{"name":"message_id","type":"string"},{"name":"action","type":"string"},{"name":"status","type":"string"},{"name":"request","type":"string"},{"name":"response","type":"string"}]} 

at org.apache.avro.Schema.validateName(Schema.java:1079) 
        at org.apache.avro.Schema.access$200(Schema.java:79) 
        at org.apache.avro.Schema$Name.<init>(Schema.java:436) 
        at org.apache.avro.Schema$Names.get(Schema.java:1043) 
        at org.apache.avro.Schema.parse(Schema.java:1160) 
        at org.apache.avro.Schema$Parser.parse(Schema.java:965) 
        at org.apache.avro.Schema$Parser.parse(Schema.java:953) 
        at main.scala.SampleStreaming$.main(SampleStreaming.scala:42) 
        at main.scala.SampleStreaming.main(SampleStreaming.scala) 

Schema_2 :

    "{\"type\":\"record\",\"name\":\"WS_MESSAGES\",\"fields\":[{\"name\":\"message_id\",\"type\":\"string\"},{\"name\":\"action\",\"type\":\"string\"},{\"name\":\"status\",\"type\":\"string\"},{\"name\":\"request\",\"type\":\"string\"},{\"name\":\"response\",\"type\":\"string\"}]}" 

I initially was trying to parse the following schema_1 but got different error , then manipulated the string to make the schema_2 above.

Exception in thread "main" org.apache.avro.SchemaParseException: No type: {"schema":"{\"type\":\"record\",\"name\":\"WS_MESSAGES\",\"fields\":[{\"name\":\"message_id\",\"type\":\"string\"},{\"name\":\"action\",\"type\":\"string\"},{\"name\":\"status\",\"type\":\"string\"},{\"name\":\"request\",\"type\":\"string\"},{\"name\":\"response\",\"type\":\"string\"}],\"connect.name\":\"WS_MESSAGES\"}"} 
        at org.apache.avro.Schema.getRequiredText(Schema.java:1305) 
        at org.apache.avro.Schema.parse(Schema.java:1166) 

Schema_1: 

    {"schema":"{\"type\":\"record\",\"name\":\"WS_MESSAGES\",\"fields\":[{\"name\":\"message_id\",\"type\":\"string\"},{\"name\":\"action\",\"type\":\"string\"},{\"name\":\"status\",\"type\":\"string\"},{\"name\":\"request\",\"type\":\"string\"},{\"name\":\"response\",\"type\":\"string\"}],\"connect.name\":\"WS_MESSAGES\"}"} 

Thanks, 
Amritendu
Shayneshays answered 13/2, 2017 at 0:53 Comment(0)
R
7

I guess, the problem is, you are using a dot (.) in name field(connect.name). Which is not allowed . Take a look at Names Avro

Renatarenate answered 26/6, 2017 at 18:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.