1

I want to use the Avro schema and read it in python. Cannot read the schema. It is throwing an error

import avro.schema
from avro.datafile import DataFileReader, DataFileWriter
from avro.io import DatumReader, DatumWriter

schema = avro.schema.Parse(open("user.avsc","rb").read())
schema_1=schema.meta
print(schema_1)
Community
  • 1
  • 1
  • 2
    What error? Please add more details – Umang Gupta Jun 21 '18 at 18:30
  • This is the error AttributeError: 'RecordSchema' object has no attribute 'meta' –  Jun 21 '18 at 21:12
  • 1
    import avro.schema from avro.datafile import DataFileReader, DataFileWriter from avro.io import DatumReader, DatumWriter schema = avro.schema.Parse(open("fraud_alert.avsc","rb").read()) print(schema) print(type(schema)) The type of the object returned is Avro.schema. Recordschema. I want to use this object but I don't know how to. –  Jun 21 '18 at 21:15

1 Answers1

0

Are you trying to read the fields in the schema (user.avsc) ? If so: schema would be a list of all the fields in the avsc file [each.name for each in schema] would give the list of fields.

Hope that helps...

aady
  • 35
  • 2
  • This would be better suited as a comment, which you will be able to make when you reach 50 reputation. Your contribution in attempting to answer the question is appreciated but please reserve the answer section for concrete solutions. – tshimkus Apr 08 '19 at 05:23