Skip to content

Error decoding bytes type with logicalType decimal - Avro #60

@arhantpanda

Description

@arhantpanda

I have the following Avro schema for a field that is a decimal logicalType.

{
  "name": "amount",
  "type": [
    "null",
    {
      "type": "bytes",
      "scale": 2,
      "precision": 10,
      "connect.version": 1,
      "connect.parameters": {
        "scale": "2",
        "connect.decimal.precision": "10"
      },
      "connect.name": "org.apache.kafka.connect.data.Decimal",
      "logicalType": "decimal"
    }
  ],
  "default": null
}

The value from processor is a dict with string and bytes values
The field value in bytes: b'\x00\x97\xf4'

I am unable to get the decimal value to proceed further. I've tried the following which did not work.

  1. data.decode() & data.decode('latin-1')
Fails with error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 1: invalid start byte
  1. BinaryDecoder
decoder = BinaryDecoder(io.BytesIO(data))
decoder.read_double()

Fails with error
  File "/IdeaProjects/virtualenv/event-venv/lib/python3.6/site-packages/avro/io.py", line 240, in read_double
    ((ord(self.read(1)) & 0xff) << 48) |
  File "/IdeaProjects/virtualenv/event-venv/lib/python3.6/site-packages/avro/io.py", line 180, in read
    assert (len(input_bytes) == n), input_bytes
AssertionError: b''

How can I extract data from byte fields in Avro?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions