Skip to content

Instantly share code, notes, and snippets.

@grantr grantr/gist:416080
Created May 27, 2010

Embed
What would you like to do?
require 'rubygems'
require 'avro'
count = ARGV[0] ? ARGV[0].to_i : 10000
puts "writing #{count} records"
SCHEMA = <<-JSON
{ "type": "record",
"name": "User",
"fields" : [
{"name": "username", "type": "string"},
{"name": "age", "type": "int"},
{"name": "verified", "type": "boolean", "default": "false"}
]}
JSON
file = File.open('data.avr', 'wb')
schema = Avro::Schema.parse(SCHEMA)
writer = Avro::IO::DatumWriter.new(schema)
dw = Avro::DataFile::Writer.new(file, writer, schema)
count.times do
dw << {"username" => "john", "age" => 25, "verified" => true}
end
dw.close
puts "data.avr: #{File.new("data.avr").stat.size}"
file = File.open('data.json', 'w')
count.times do
file << Yajl::Encoder.encode({"username" => "john", "age" => 25, "verified" => true})
end
file.close
puts "data.json: #{File.new("data.json").stat.size}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.