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.
Add the
rubygems
package:$ sudo apt-get install rubygems
Install the Avro gem:
$ gem install avro
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", "city" => "New York", "shape" => "light", "duration" => 0.25} dw<< {"sighting_date" => "2001-08-23", "city" => "Las Vegas", "shape" => "cylinder", "duration" => 1.2} dw...