Skip to content

Instantly share code, notes, and snippets.

@gphilipp
Created February 8, 2024 10:23
Show Gist options
  • Save gphilipp/3874b7d3d5a3f46ae48a752ad8000312 to your computer and use it in GitHub Desktop.
Save gphilipp/3874b7d3d5a3f46ae48a752ad8000312 to your computer and use it in GitHub Desktop.
Negative number for Avro's date logicalType
avro~=1.11.3
fastavro~=1.11.3
from fastavro import json_reader, parse_schema
from io import StringIO
avro_schema = {
"type": "record",
"name": "Membership",
"fields": [
{"name": "start_date", "type": {"type": "int", "logicalType": "date"}},
{"name": "end_date", "type": {"type": "int", "logicalType": "date"}},
{"name": "email", "type": "string"},
{"name": "ssn", "type": "string"}
]
}
schema = parse_schema(avro_schema)
f = StringIO('{"start_date": -1, "end_date": 0, "email": "john.doe@acme.io", "ssn": "123-45-6789"}')
avro_reader = json_reader(f, schema)
for record in avro_reader:
print(record)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment