Time for action – creating the source Avro data with Ruby

Let's create the sample data using Ruby to demonstrate the cross-language capabilities of Avro.

  1. Add the rubygems package:
    $ sudo apt-get install rubygems
    
  2. Install the Avro gem:
    $ gem install avro
    
  3. Create the following as generate.rb:
    require 'rubygems' require 'avro' file = File.open('sightings.avro', 'wb') schema = Avro::Schema.parse( File.open("ufo.avsc", "rb").read) writer = Avro::IO::DatumWriter.new(schema) dw = Avro::DataFile::Writer.new(file, writer, schema) dw<< {"sighting_date" => "2012-01-12", "city" => "Boston", "shape" => "diamond", "duration" => 3.5} dw<< {"sighting_date" => "2011-06-13", "city" => "London", "shape" => "light", "duration" => 13} dw<< {"sighting_date" => "1999-12-31", ...

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.