简体   繁体   中英

Fastavro fails to parse Avro schema with enum

I have the following code block:

import fastavro

schema = {
    "name": "event",
    "type": "record",
    "fields": [{"name": "event_type", "type": "enum", "symbols": ["START", "STOP"]}],
}

checker = fastavro.parse_schema(schema=schema)

Upon running it, it generates the following error:

Traceback (most recent call last):
  File ".\test_schema.py", line 7, in <module>
    checker = fastavro.parse_schema(schema=schema)
  File "fastavro\_schema.pyx", line 121, in fastavro._schema.parse_schema
  File "fastavro\_schema.pyx", line 322, in fastavro._schema._parse_schema
  File "fastavro\_schema.pyx", line 381, in fastavro._schema.parse_field
  File "fastavro\_schema.pyx", line 191, in fastavro._schema._parse_schema
fastavro._schema_common.UnknownType: enum

I'm running fastavro 1.7.0, on Windows 10, and python 3.8.8. I have had similar problems on Linux (RHEL 8) using python 3.10.

Based on the Avro documentation for enumerated types , the schema seems correct, but fastavro fails to recognize the enum type. Am I doing something wrong here, or does fastavro 1.7.0 not support Avro 1.9 enumerations?

Looks like the schema is not correctly formed. After some additional checking, the following works:

import fastavro

schema = {
    "name": "event",
    "type": "record",
    "fields": [
        {
            "name": "event_type",
            "type": {
                "type": "enum",
                "name": "event_type_enums",
                "symbols": ["START", "STOP"],
            },
        }
    ],
}

checker = fastavro.parse_schema(schema=schema)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM