0
私はただハープを始めています。私はAvro(fastavro)を使っています。avroスキーマ(.avsc)をテストし、.avroに変換します。 AttributeError、array and encoding
1-私はスキーマを検証し、.avroファイルに変換したいと考えています。
{
"type": "record",
"name": "Node",
"fields": [
{
"name": "nom",
"type": "string"
},
{
"name": "zone",
"type": {
"type": "map",
"values": "string"
}
},
{
"name": "price",
"type": "float"
},
{
"name": "type",
"type": "string"
}
]
}
私のテストファイル(スキーマを検証):
{
"name": "ingredients",
"type": ["string"]
},
:私は、アレイを追加する場合、
Traceback (most recent call last):
File "test-schema.py", line 17, in <module>
fastavro.writer(open("myschema.avro", "wb"), schema, records)
File "/var/www/data-machine/HDFS/env/lib/python3.5/site-packages/fastavro/writer.py", line 614, in writer
output.write(record)
File "/var/www/data-machine/HDFS/env/lib/python3.5/site-packages/fastavro/writer.py", line 537, in write
write_data(self.io, record, self.schema)
File "/var/www/data-machine/HDFS/env/lib/python3.5/site-packages/fastavro/writer.py", line 432, in write_data
return fn(fo, datum, schema)
File "/var/www/data-machine/HDFS/env/lib/python3.5/site-packages/fastavro/writer.py", line 363, in write_record
name, field.get('default')), field['type'])
File "/var/www/data-machine/HDFS/env/lib/python3.5/site-packages/fastavro/writer.py", line 432, in write_data
return fn(fo, datum, schema)
File "/var/www/data-machine/HDFS/env/lib/python3.5/site-packages/fastavro/writer.py", line 232, in write_map
for key, val in iteritems(datum):
File "/var/www/data-machine/HDFS/env/lib/python3.5/site-packages/fastavro/six.py", line 27, in py3_iteritems
return obj.items()
AttributeError: 'list' object has no attribute 'items'
2-および:
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import json
import fastavro
schema = json.load(open("myschema.avsc"))
records = [
{
"nom": "blabla",
"zone": ["north", "south", "east"],
"prix": 4.0,
"type": "geoloc"
}
]
fastavro.writer(open("myschema.avro", "wb"), schema, records)
を私はこのエラーをしました
エラー:
File "/var/www/data-machine/HDFS/env/lib/python3.5/site-packages/fastavro/writer.py", line 345, in write_union
raise ValueError(msg)
ValueError: ["north", "south", "east"] (type <class 'list'>) do not match ['string']
そして、仕上げ、私はマップのためのあなたの記録情報が間違っている
感謝:) ファブリス
ok。どうもありがとう :)。それは働いている。 – fabrice