Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of DatumWriter in Avro

Tags:

java

avro

Avro website has an example:

DatumWriter<User> userDatumWriter = new SpecificDatumWriter<User>(User.class);
DataFileWriter<User> dataFileWriter = new DataFileWriter<User>(userDatumWriter);
dataFileWriter.create(user1.getSchema(), new File("users.avro"));
dataFileWriter.append(user1);
dataFileWriter.append(user2);
dataFileWriter.append(user3);
dataFileWriter.close();

What is the purpose of DatumWriter<User>? I mean what it does provide? It provides write method, but instead of using it we use DataFileWriter. Can someone explain the design purpose of it?

like image 695
Majid Azimi Avatar asked Mar 21 '23 19:03

Majid Azimi


1 Answers

The DatumWriter class responsible for translating the given data object into an avro record with a given schema (which is extracted in your case from the User class).

Given this record the DataFileWriter is responsible to write it to a file.

like image 60
bennyl Avatar answered Apr 08 '23 23:04

bennyl