Database Reference
In-Depth Information
dfw . append ({ 'left' : left , 'right' : right });
dfw . close ()
Before we can run the program, we need to install Avro for Python:
% easy_install avro
To run the program, we specify the name of the file to write output to ( pairs.avro ) and
send input pairs over standard in, marking the end of file by typing Ctrl-D:
% python ch12-avro/src/main/py/write_pairs.py pairs.avro
a,1
c,2
b,3
b,2
^D
Avro Tools
Next, we'll use the Avro tools (written in Java) to display the contents of pairs.avro . The
tools JAR is available from the Avro website; here we assume it's been placed in a local
directory called $AVRO_HOME . The tojson command converts an Avro datafile to
JSON and prints it to the console:
% java -jar $AVRO_HOME/avro-tools-*.jar tojson pairs.avro
{"left":"a","right":"1"}
{"left":"c","right":"2"}
{"left":"b","right":"3"}
{"left":"b","right":"2"}
We have successfully exchanged complex data between two Avro implementations
(Python and Java).
Search WWH ::




Custom Search