AVRO – Reference API

  • Post author:
  • Post category:AVRO
  • Post comments:1 Comment
Classes

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 serialization and deserialization 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 serialized format.

Constructor

S.No.Description
1SpecificDatumWriter(Schema schema)

Method

S.No.Description
1SpecificData 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
1SpecificDatumReader(Schema schema)Construct where the writer’s and reader’s schemas are the same.

Methods

S.No.Description
1SpecificData getSpecificData()Returns the contained SpecificData.
2void setSchema(Schema actual)This method is used to set the writer’s schema.

DataFileWriter

Instantiates DataFileWrite for emp class. This class writes a sequence serialized records of data conforming to a schema, along with the schema in a file.

Constructor

S.No.Description
1DataFileWriter(DatumWriter<D> dout)

Methods

S.NoDescription
1void append(D datum)Appends a datum to a file.
2DataFileWriter<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
1DataFileReader(File file, DatumReader<D> reader))

Methods

S.No.Description
1next()Reads the next datum in the file.
2Boolean 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
1Schema.Parser()

Methods

S.No.Description
1parse (File file)Parses the schema provided in the given file.
2parse (InputStream in)Parses the schema provided in the given InputStream.
3parse (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
1Object get(String key)Returns the value of a field given.
2void put(String key, Object v)Sets the value of a field given its name.

Class GenericData.Record

Constructor

S.No.Description
1GenericData.Record(Schema schema)

Methods

S.No.Description
1Object get(String key)Returns the value of a field of the given name.
2Schema getSchema()Returns the schema of this instance.
3void put(int i, Object v)Sets the value of a field given its position in the schema.
4void put(String key, Object value)Sets the value of a field given its name.

Next Topic:-Click Here

This Post Has One Comment

Leave a Reply