빅데이터
[avro] python avro api 에서 The datum XX is not an example of the schema 오류
hs_seo
2021. 7. 13. 23:11
python을 이용한 avro 기본 api 에서 The datum XX is not an example of the schema 오류가 발생하는 경우가 있습니다.
Traceback (most recent call last):
File "test.py", line 77, in <module>
bytes_data = quickstart_schema.encode(sample_data)
File "test.py", line 41, in encode
self._writer.write(data, encoder)
File "/home/deploy/.local/lib/python2.7/site-packages/avro/io.py", line 979, in write
raise AvroTypeException(self.writers_schema, datum)
avro.io.AvroTypeException: The datum {'empdetails': {'age': 100, 'experience': 'AA'}} is not an example of the schema {
"namespace": "tutorialspoint",
"type": "record",
"name": "empdetails",
"fields": [
{
"type": "string",
"name": "experience"
},
{
"type": "int",
"name": "age"
}
]
}
https://avro.apache.org/docs/current/gettingstartedpython.html
Apache Avro™ 1.10.2 Getting Started (Python)
Apache Avro™ 1.10.2 Getting Started (Python) This is a short guide for getting started with Apache Avro™ using Python. This guide only covers using Avro for data serialization; see Patrick Hunt's Avro RPC Quick Start for a good introduction to using Av
avro.apache.org
원인
첫 번째 원인은 스키마와 값이 다를 때 발생합니다. 이 경우는 스키마를 잘 확인하고, 데이터의 타입을 잘 맞추어 주면 됩니다.
두번째는 python2에서 실행할 때 발생할 수 있습니다. 공식 문서에는 python2도 지원하고, pip를 이용해서 설치할 수 있지만 python2에서는 오류가 발생했습니다. python3로 실행하면 문제가 해결 됩니다.
반응형