Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
import avro.schema
from avro.datafile import DataFileReader, DataFileWriter
from avro.io import DatumReader, DatumWriter
import simplejson as json
a = avro.schema.parse(json.dumps({"name": "hey", "type": "record", "fields": [{"name":"n", "type":"double"}]}))
b = avro.schema.parse(json.dumps({"name": "hey", "type": "record", "fields": [{"name":"n", "type":"int"}]}))
c = avro.schema.parse(json.dumps({"name": "hey", "type": "record", "fields": [{"name":"n", "type":["int","double"]}]}))
writer = DataFileWriter(open("a.avro", "w"), DatumWriter(), a)
writer.append({"n": 1.0})
writer.append({"n": 1})
writer.close()
reader = DataFileReader(open("a.avro", "r"), DatumReader())
print reader.next() # {u'n': 1.0}
print reader.next() # {u'n': 1.0}
reader = DataFileReader(open("a.avro", "r"), DatumReader(readers_schema=c))
print reader.next() # {u'n': 1.0}
print reader.next() # {u'n': 1.0}
d = avro.schema.parse(json.dumps({"name": "hey", "type": "record", "fields": [{"name":"n", "type":["int", "double"]}]}))
writer = DataFileWriter(open("d.avro", "w"), DatumWriter(), d)
writer.append({"n": 1.0})
writer.append({"n": 1})
writer.close()
reader = DataFileReader(open("d.avro", "r"), DatumReader())
print reader.next() # {u'n': 1.0}
print reader.next() # {u'n': 1.0}
reader = DataFileReader(open("d.avro", "r"), DatumReader(readers_schema=b))
print reader.next() # error, schema doesn't matdh
print reader.next() # {u'n': 0} ???
print reader.next() # {u'n': 0} ???
reader = DataFileReader(open("d.avro", "r"), DatumReader(readers_schema=c))
print reader.next() # {u'n': 1.0}
print reader.next() # {u'n': 1.0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.