AVRO Schemas & APIs
AVRO By Generating a Class
AVRO Using Parsers Library
AVRO Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
AVRO - Reference API
In the previous chapter, we described the input type of Avro, i.e., Avro schemas. In this chapter, we will explain the classes and methods used in the seriapzation and deseriapzation of Avro schemas.
SpecificDatumWriter Class
This class belongs to the package org.apache.avro.specific. It implements the DatumWriter interface which converts Java objects into an in-memory seriapzed format.
Constructor
S.No. | Description |
---|---|
1 | SpecificDatumWriter(Schema schema) |
Method
S.No. | Description |
---|---|
1 | SpecificData getSpecificData() Returns the SpecificData implementation used by this writer. |
SpecificDatumReader Class
This class belongs to the package org.apache.avro.specific. It implements the DatumReader interface which reads the data of a schema and determines in-memory data representation. SpecificDatumReader is the class which supports generated java classes.
Constructor
S.No. | Description |
---|---|
1 | SpecificDatumReader(Schema schema) Construct where the writer s and reader s schemas are the same. |
Methods
S.No. | Description |
---|---|
1 | SpecificData getSpecificData() Returns the contained SpecificData. |
2 | void setSchema(Schema actual) This method is used to set the writer s schema. |
DataFileWriter
Instantiates DataFileWrite for emp class. This class writes a sequence seriapzed records of data conforming to a schema, along with the schema in a file.
Constructor
S.No. | Description |
---|---|
1 | DataFileWriter(DatumWriter<D> dout) |
Methods
S.No | Description |
---|---|
1 | void append(D datum) Appends a datum to a file. |
2 | DataFileWriter<D> appendTo(File file) This method is used to open a writer appending to an existing file. |
Data FileReader
This class provides random access to files written with DataFileWriter. It inherits the class DataFileStream.
Constructor
S.No. | Description |
---|---|
1 | DataFileReader(File file, DatumReader<D> reader)) |
Methods
S.No. | Description |
---|---|
1 | next() Reads the next datum in the file. |
2 | Boolean hasNext() Returns true if more entries remain in this file. |
Class Schema.parser
This class is a parser for JSON-format schemas. It contains methods to parse the schema. It belongs to org.apache.avro package.
Constructor
S.No. | Description |
---|---|
1 | Schema.Parser() |
Methods
S.No. | Description |
---|---|
1 | parse (File file) Parses the schema provided in the given file. |
2 | parse (InputStream in) Parses the schema provided in the given InputStream. |
3 | parse (String s) Parses the schema provided in the given String. |
Interface GenricRecord
This interface provides methods to access the fields by name as well as index.
Methods
S.No. | Description |
---|---|
1 | Object get(String key) Returns the value of a field given. |
2 | void put(String key, Object v) Sets the value of a field given its name. |
Class GenericData.Record
Constructor
S.No. | Description |
---|---|
1 | GenericData.Record(Schema schema) |
Methods
S.No. | Description |
---|---|
1 | Object get(String key) Returns the value of a field of the given name. |
2 | Schema getSchema() Returns the schema of this instance. |
3 | void put(int i, Object v) Sets the value of a field given its position in the schema. |
4 | void put(String key, Object value) Sets the value of a field given its name. |