Eine weitere WordPress-Website

Sending data via AVRO

I got a better understanding when I used AVRO to write data via PHP and to read them via Java. It demonstrated to me how data can be written in one language and subsequently be read in another language.
I use a file to have the data be written by PHP. Subsequently the data can be read by Java.
The question then is: what is the advantage of using AVRO to have data been written in file. This can be compared to ordinary CSV files or a more advanced XML format.
Let us first write the data via PHP:using this script
We have now written in PHP some data to a file. The nice thing about it that the data are written with their description, as provided by the schema. Apparently, the schema shows that we write records with two elements: a number and a name. This schema is only written once and the data are written after the schema.
When one compares this to a normal CSV file, one may notice that the schema is added to the file. Hence a programme that reads the data may verify that the data are in the correct format.
One may argue that this is similar to XML but with XML, the schema is repeated with every data element. Hence XML files tend to very large as compared to CSV. An avro file avoids this by providing the sceme just once.

This demonstrates that the data can be read in another language. In this case, Java is used to read the file. The Java programme just needs to know where the data is stored (in data.avr) and how the schema looks like (provided in user.avsc). After that the file can be read and its records can be accessed.