Time for action – examining the output data with Ruby
Now that we have the output data from the job, let's examine it again using Ruby.
Create the following as
read.rb
:require 'rubygems' require 'avro' file = File.open('res.avro', 'rb') reader = Avro::IO::DatumReader.new() dr = Avro::DataFile::Reader.new(file, reader) dr.each {|record| print record["shape"]," ",record["count"],"\n" } dr.close
Examine the created result file.
$ ruby read.rb blur 1 cylinder 1 diamond 2 formation 1 light 3 saucer 1
What just happened?
As before, we'll not analyze the Ruby Avro API. The example created a Ruby script that opens an Avro datafile, iterates through each datum, and displays it based on explicitly named fields. Note that the script does not have access to the schema for the datafile; the information in the header provides enough data to allow each field to be retrieved.