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.

  1. 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
  2. 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 ...

Get Hadoop Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.