8000 Schemaless reader does not return enum names in unions of string and enums · Issue #788 · fastavro/fastavro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Schemaless reader does not return enum names in unions of string and enums #788
Open
@sral85

Description

@sral85

I have the following avro schema. This bascially consists of a record with 1 field. This field consists of a union of a string and two enums.

{"namespace": "example.avro", "type": "record", "name": "Example", "fields": [ {"name": "option_enums", "type": ["string", {"type": "enum", "name": "Enum1", "symbols": ["a", "b", "Unknown"]}, {"type": "enum", "name": "Enum2", "symbols": ["a", "b", "Unknown"]} ]} ] }
I have the issue that the schemaless reader does not output the enum names, although I used the "return_named_type" parameter. Consider the following script:

`
import pathlib
import fastavro
import io
import fastavro.utils

path = pathlib.Path(file).parent.resolve() / "localtests" / "schemas" / "schema_enums.avsc"
SCHEMA = fastavro.schema.load_schema(path.as_posix())

def roundtrip(avro_message):
buffer = io.BytesIO()
fastavro.schemaless_writer(buffer, SCHEMA, avro_message)
buffer.seek(0)
return fastavro.schemaless_reader(
buffer, SCHEMA, return_named_type=True
)

for msg in fastavro.utils.generate_many(SCHEMA, 10):
result = roundtrip(msg)
print(result)
`

which gives the output

{'option_enums': 'rkdHDVsNQJ'} {'option_enums': 'b'} {'option_enums': 'Unknown'} {'option_enums': 'MVwYwmsljt'} {'option_enums': 'b'} {'option_enums': 'Unknown'} {'option_enums': 'MXjAihssRO'} {'option_enums': 'b'} {'option_enums': 'Unknown'} {'option_enums': 'TWovuTXqeG'}

I would expect that in some cases the enum names should present (like {'option_enums': ('example.avro.Enum1', 'a')}). If I remove the "string" component from the union, then the enum names are returned. Could you please check this issue?

Possibly this issue may be related to #729

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

      0