Created
February 8, 2024 10:23
-
-
Save gphilipp/3874b7d3d5a3f46ae48a752ad8000312 to your computer and use it in GitHub Desktop.
Negative number for Avro's date logicalType
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
avro~=1.11.3 | |
fastavro~=1.11.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "[email protected]", "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