Created
July 13, 2021 14:11
-
-
Save developer-sdk/dc6fc9c968fb90e4d3c813afdda1562f to your computer and use it in GitHub Desktop.
python을 이용한 avro 예제
This file contains 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
import avro.schema | |
from avro.datafile import DataFileReader, DataFileWriter | |
from avro.io import DatumReader, DatumWriter | |
schema = avro.schema.parse("""{"namespace": "example.avro", | |
"type": "record", | |
"name": "User", | |
"fields": [ {"name": "name", "type": "string"} ] | |
}""") | |
writer = DataFileWriter(open("users.avro", "wb"), DatumWriter(), schema) | |
writer.append({"name": "Alyssa"}) | |
writer.close() | |
reader = DataFileReader(open("users.avro", "rb"), DatumReader()) | |
for user in reader: | |
print(user) | |
reader.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment