You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Jason Kososki (Jira)" <ji...@apache.org> on 2020/01/01 03:07:00 UTC

[jira] [Commented] (AVRO-2126) avro.io.SchemaResolutionException: Can't access branch index 36 for union with 2 branches

    [ https://issues.apache.org/jira/browse/AVRO-2126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17006288#comment-17006288 ] 

Jason Kososki commented on AVRO-2126:
-------------------------------------

[~nbhav] 

 

I was running into the same problem and was able to resolve by dropping the first five bytes of msg.value()

I was following the solution from this post:
https://stackoverflow.com/questions/44407780/how-to-decode-deserialize-kafka-avro-strings-with-python

I modified the line 
{code:python}
msg_value = msg.value()
{code}
to 
{code:python}
msg_value = msg.value()[5:]
{code}

Also -- a good post that helped me understand the format of the avro message:
https://stackoverflow.com/questions/31204201/apache-kafka-with-avro-and-schema-repo-where-in-the-message-does-the-schema-id

 

> avro.io.SchemaResolutionException: Can't access branch index 36 for union with 2 branches
> -----------------------------------------------------------------------------------------
>
>                 Key: AVRO-2126
>                 URL: https://issues.apache.org/jira/browse/AVRO-2126
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: python
>    Affects Versions: 1.8.2
>         Environment: Python 3.5.2, avro-python3 1.8.2
>            Reporter: Jurgis Pods
>            Priority: Major
>
> I get the following error when decoding messages from Kafka via avro-python3:
> {code}
> avro.io.SchemaResolutionException: Can't access branch index 36 for union with 2 branches
> Writer's Schema: [
>   "null",
>   "string"
> ]
> Reader's Schema: [
>   "null",
>   "string"
> ]
> {code}
> Relevant code producing this error:
> {code}
> import avro.schema
> import avro.io
> import io
> def parse_avro(value, schema):
>     bytes_reader = io.BytesIO(value)
>     decoder = avro.io.BinaryDecoder(bytes_reader)
>     reader = avro.io.DatumReader(schema)
>     return reader.read(decoder)
> # msg: Message from Kafka, schema: avro.schema.Schema from Confluent Schema Registry
> parse_avro(msg.value, avro_schema)
> {code}
> I have no idea where the number 36 might come from.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)